diff --git a/router/connection.go b/router/connection.go index d096922f..ac8f2ca9 100644 --- a/router/connection.go +++ b/router/connection.go @@ -495,7 +495,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool // receiver's version are updated conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers())) } else if msg[0] == ProtocolUpdate { - newUpdate, err := conn.Router.Peers.ApplyUpdate(msg[1:], conn.Router) + newUpdate, err := conn.Router.Peers.ApplyUpdate(msg[1:], conn.Router.Ourself.Peer, conn.Router.Macs) if _, ok := err.(UnknownPeersError); err != nil && ok { // That update contained a peer we didn't know about; // request full update @@ -506,6 +506,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool return } if len(newUpdate) != 0 { + conn.Router.ConnectionMaker.Refresh() conn.Router.Routes.Recalculate() conn.Router.Ourself.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate)) } diff --git a/router/peers.go b/router/peers.go index 464565af..35296c37 100644 --- a/router/peers.go +++ b/router/peers.go @@ -51,7 +51,7 @@ func (peers *Peers) ForEach(fun func(PeerName, *Peer)) { } } -func (peers *Peers) ApplyUpdate(update []byte, router *Router) ([]byte, error) { +func (peers *Peers) ApplyUpdate(update []byte, ourself *Peer, macs *MacCache) ([]byte, error) { peers.Lock() newPeers, decodedUpdate, decodedConns, err := peers.decodeUpdate(update) @@ -68,19 +68,15 @@ func (peers *Peers) ApplyUpdate(update []byte, router *Router) ([]byte, error) { } // Now apply the updates - newUpdate := peers.applyUpdate(decodedUpdate, decodedConns, router.Ourself.Peer) + newUpdate := peers.applyUpdate(decodedUpdate, decodedConns, ourself) - for _, peerRemoved := range peers.garbageCollect(router.Ourself.Peer, router.Macs) { + for _, peerRemoved := range peers.garbageCollect(ourself, macs) { delete(newUpdate, peerRemoved.Name) } // Don't need to hold peers lock any longer peers.Unlock() - if len(newUpdate) > 0 { - router.ConnectionMaker.Refresh() - } - return encodePeersMap(newUpdate), nil }