repeated calls to join a server now trigger a fetch
This commit is contained in:
parent
58535b0eb6
commit
8109158f40
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue