diff --git a/protocol/connections/engine.go b/protocol/connections/engine.go index 30529d5..50036de 100644 --- a/protocol/connections/engine.go +++ b/protocol/connections/engine.go @@ -101,7 +101,7 @@ func (e *engine) eventHandler() { case event.StatusRequest: e.eventManager.Publish(event.Event{EventType: event.ProtocolEngineStatus, EventID: ev.EventID}) case event.PeerRequest: - e.peerWithOnion(ev.Data[event.RemotePeer]) + go e.peerWithOnion(ev.Data[event.RemotePeer]) case event.InvitePeerToGroup: e.sendMessageToPeer(ev.EventID, ev.Data[event.RemotePeer], event.ContextInvite, []byte(ev.Data[event.GroupInvite])) case event.JoinServer: @@ -160,8 +160,13 @@ func (e *engine) Shutdown() { } // peerWithOnion is the entry point for cwtchPeer relationships +// needs to be run in a goroutine as will block on Open. func (e *engine) peerWithOnion(onion string) { - e.service.Connect(onion, e.createPeerTemplate()) + e.ignoreOnShutdown(e.peerConnecting)(onion) + _,err := e.service.Connect(onion, e.createPeerTemplate()) + if err != nil { + e.ignoreOnShutdown(e.peerDisconnected)(onion) + } } func (e * engine) ignoreOnShutdown(f func(string)) func(string){ diff --git a/protocol/connections/peerapp.go b/protocol/connections/peerapp.go index 323bcf9..6c6e063 100644 --- a/protocol/connections/peerapp.go +++ b/protocol/connections/peerapp.go @@ -40,11 +40,6 @@ func (pa PeerApp) NewInstance() tapir.Application { // Init is run when the connection is first started. func (pa *PeerApp) Init(connection *tapir.Connection) { - // We don't want to issue an event for unknown peers (we only know inbound peer hostnames once we have authenticated) - if connection.Outbound { - pa.OnConnecting(connection.Hostname) - } - // First run the Authentication App pa.AuthApp.Init(connection)