repeated calls to join a server now trigger a fetch

This commit is contained in:
Dan Ballard 2019-02-05 13:12:11 -08:00
parent 58535b0eb6
commit 8109158f40
2 changed files with 15 additions and 5 deletions

View File

@ -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.

View File

@ -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