refactor: promote connection lifecycle methods from LocalPeer to Peer
They are sufficiently generic, and having them on Peer is useful for testing.
This commit is contained in:
1 parent
1dde9bfe0b
commit
55f55a59bc
2 files changed
+22
-22
No files matched your search
@@ -261,28 +261,6 @@ func (peer *LocalPeer) handleSendProtocolMsg(m ProtocolMsg) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *LocalPeer) addConnection(conn Connection) {
|
|
||||||
peer.Lock()
|
|
||||||
peer.connections[conn.Remote().Name] = conn
|
|
||||||
peer.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (peer *LocalPeer) deleteConnection(conn Connection) {
|
|
||||||
established := conn.Established()
|
|
||||||
peer.Lock()
|
|
||||||
delete(peer.connections, conn.Remote().Name)
|
|
||||||
if established {
|
|
||||||
peer.version += 1
|
|
||||||
}
|
|
||||||
peer.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (peer *LocalPeer) connectionEstablished(conn Connection) {
|
|
||||||
peer.Lock()
|
|
||||||
peer.version += 1
|
|
||||||
peer.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (peer *LocalPeer) broadcastPeerUpdate(peers ...*Peer) {
|
func (peer *LocalPeer) broadcastPeerUpdate(peers ...*Peer) {
|
||||||
peer.Router.Routes.Recalculate()
|
peer.Router.Routes.Recalculate()
|
||||||
peer.handleSendProtocolMsg(ProtocolMsg{ProtocolUpdate, EncodePeers(append(peers, peer.Peer)...)})
|
peer.handleSendProtocolMsg(ProtocolMsg{ProtocolUpdate, EncodePeers(append(peers, peer.Peer)...)})
|
||||||
|
|||||||
@@ -86,6 +86,28 @@ func (peer *Peer) SetVersionAndConnections(version uint64, connections map[PeerN
|
|||||||
peer.connections = connections
|
peer.connections = connections
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (peer *LocalPeer) addConnection(conn Connection) {
|
||||||
|
peer.Lock()
|
||||||
|
defer peer.Unlock()
|
||||||
|
peer.connections[conn.Remote().Name] = conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (peer *LocalPeer) deleteConnection(conn Connection) {
|
||||||
|
established := conn.Established()
|
||||||
|
peer.Lock()
|
||||||
|
defer peer.Unlock()
|
||||||
|
delete(peer.connections, conn.Remote().Name)
|
||||||
|
if established {
|
||||||
|
peer.version += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (peer *LocalPeer) connectionEstablished(conn Connection) {
|
||||||
|
peer.Lock()
|
||||||
|
defer peer.Unlock()
|
||||||
|
peer.version += 1
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the routing table from this peer to all peers reachable
|
// Calculate the routing table from this peer to all peers reachable
|
||||||
// from it, returning a "next hop" map of PeerNameX -> PeerNameY,
|
// from it, returning a "next hop" map of PeerNameX -> PeerNameY,
|
||||||
// which says "in order to send a message to X, the peer should send
|
// which says "in order to send a message to X, the peer should send
|
||||||
|
|||||||
Reference in new issue
Block a user