From 8109158f40e10d5886f6d8a844bc74c1b26d6714 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 5 Feb 2019 13:12:11 -0800 Subject: [PATCH] repeated calls to join a server now trigger a fetch --- protocol/connections/engine.go | 7 ++++++- protocol/connections/peerserverconnection.go | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/protocol/connections/engine.go b/protocol/connections/engine.go index d5a82d9..0768124 100644 --- a/protocol/connections/engine.go +++ b/protocol/connections/engine.go @@ -208,7 +208,12 @@ func (e *Engine) ReceiveGroupMessage(server string, gm *protocol.GroupMessage) { // JoinServer manages a new server connection with the given onion address func (e *Engine) JoinServer(onion string) { - e.connectionsManager.ManageServerConnection(onion, e.ReceiveGroupMessage) + psc := e.connectionsManager.GetPeerServerConnectionForOnion(onion) + if psc == nil { + e.connectionsManager.ManageServerConnection(onion, e.ReceiveGroupMessage) + } else { + psc.StartFetchMessages() + } } // SendMessageToGroup attempts to sent the given message to the given group id. diff --git a/protocol/connections/peerserverconnection.go b/protocol/connections/peerserverconnection.go index f22da2a..4333c92 100644 --- a/protocol/connections/peerserverconnection.go +++ b/protocol/connections/peerserverconnection.go @@ -66,10 +66,7 @@ func (psc *PeerServerConnection) Run() error { psc.state = AUTHENTICATED go func() { - psc.connection.Do(func() error { - psc.connection.RequestOpenChannel("im.cwtch.server.fetch", &fetch.CwtchPeerFetchChannel{Handler: psc}) - return nil - }) + psc.StartFetchMessages() psc.connection.Do(func() error { psc.connection.RequestOpenChannel("im.cwtch.server.listen", &listen.CwtchPeerListenChannel{Handler: psc}) @@ -125,6 +122,14 @@ func (psc *PeerServerConnection) SendGroupMessage(gm *protocol.GroupMessage) err return err } +//StartFetchMessages opens a fetch channel to the server. The server will respond by sending back all messages in buffer and closing the channel +func (psc *PeerServerConnection) StartFetchMessages() error { + return psc.connection.Do(func() error { + psc.connection.RequestOpenChannel("im.cwtch.server.fetch", &fetch.CwtchPeerFetchChannel{Handler: psc}) + return nil + }) +} + // Close shuts down the connection (freeing the handler goroutines) func (psc *PeerServerConnection) Close() { psc.state = KILLED