refactor: Peers no longer has dependency on Router
or ConnectionMaker
This commit is contained in:
1 parent
6f990d217d
commit
af59b38134
2 files changed
+5
-8
No files matched your search
@@ -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))
|
||||
}
|
||||
|
||||
+3
-7
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user