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
|
// receiver's version are updated
|
||||||
conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers()))
|
conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers()))
|
||||||
} else if msg[0] == ProtocolUpdate {
|
} 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 {
|
if _, ok := err.(UnknownPeersError); err != nil && ok {
|
||||||
// That update contained a peer we didn't know about;
|
// That update contained a peer we didn't know about;
|
||||||
// request full update
|
// request full update
|
||||||
@@ -506,6 +506,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(newUpdate) != 0 {
|
if len(newUpdate) != 0 {
|
||||||
|
conn.Router.ConnectionMaker.Refresh()
|
||||||
conn.Router.Routes.Recalculate()
|
conn.Router.Routes.Recalculate()
|
||||||
conn.Router.Ourself.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate))
|
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()
|
peers.Lock()
|
||||||
|
|
||||||
newPeers, decodedUpdate, decodedConns, err := peers.decodeUpdate(update)
|
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
|
// 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)
|
delete(newUpdate, peerRemoved.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't need to hold peers lock any longer
|
// Don't need to hold peers lock any longer
|
||||||
peers.Unlock()
|
peers.Unlock()
|
||||||
|
|
||||||
if len(newUpdate) > 0 {
|
|
||||||
router.ConnectionMaker.Refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
return encodePeersMap(newUpdate), nil
|
return encodePeersMap(newUpdate), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user