move ConnectionTo from Peer to LocalPeer
further shrinking the former's API
This commit is contained in:
1 parent
505ced5cc8
commit
0229185ffe
5 files changed
+14
-10
No files matched your search
+1
-1
@@ -75,7 +75,7 @@ func (conn *LocalConnection) handshake(enc *gob.Encoder, dec *gob.Decoder, accep
|
|||||||
return fmt.Errorf("Found unknown remote name: %s at %s", name, conn.remoteTCPAddr)
|
return fmt.Errorf("Found unknown remote name: %s at %s", name, conn.remoteTCPAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if existingConn, found := conn.local.ConnectionTo(name); found && existingConn.Established() {
|
if existingConn, found := conn.Router.Ourself.ConnectionTo(name); found && existingConn.Established() {
|
||||||
return fmt.Errorf("Already have connection to %s at %s", existingConn.Remote(), existingConn.RemoteTCPAddr())
|
return fmt.Errorf("Already have connection to %s at %s", existingConn.Remote(), existingConn.RemoteTCPAddr())
|
||||||
}
|
}
|
||||||
uid, err := strconv.ParseUint(uidStr, 10, 64)
|
uid, err := strconv.ParseUint(uidStr, 10, 64)
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ func (peer *LocalPeer) RelayBroadcast(srcPeer *Peer, df bool, frame []byte, dec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (peer *LocalPeer) ConnectionTo(name PeerName) (Connection, bool) {
|
||||||
|
peer.RLock()
|
||||||
|
defer peer.RUnlock()
|
||||||
|
conn, found := peer.connections[name]
|
||||||
|
return conn, found // yes, you really can't inline that. FFS.
|
||||||
|
}
|
||||||
|
|
||||||
func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection {
|
func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection {
|
||||||
conns := make([]Connection, 0, len(names))
|
conns := make([]Connection, 0, len(names))
|
||||||
peer.RLock()
|
peer.RLock()
|
||||||
|
|||||||
@@ -48,13 +48,6 @@ func (peer *Peer) Version() uint64 {
|
|||||||
return peer.version
|
return peer.version
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *Peer) ConnectionTo(name PeerName) (Connection, bool) {
|
|
||||||
peer.RLock()
|
|
||||||
defer peer.RUnlock()
|
|
||||||
conn, found := peer.connections[name]
|
|
||||||
return conn, found // yes, you really can't inline that. FFS.
|
|
||||||
}
|
|
||||||
|
|
||||||
func (peer *Peer) Connections() ConnectionSet {
|
func (peer *Peer) Connections() ConnectionSet {
|
||||||
connections := make(ConnectionSet)
|
connections := make(ConnectionSet)
|
||||||
peer.RLock()
|
peer.RLock()
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func TestPeersEncoding(t *testing.T) {
|
|||||||
case 0:
|
case 0:
|
||||||
from, to := rand.Intn(numNodes), rand.Intn(numNodes)
|
from, to := rand.Intn(numNodes), rand.Intn(numNodes)
|
||||||
if from != to {
|
if from != to {
|
||||||
if _, found := peer[from].ConnectionTo(peer[to].Name); !found {
|
if _, found := peer[from].connections[peer[to].Name]; !found {
|
||||||
ps[from].AddTestConnection(peer[to])
|
ps[from].AddTestConnection(peer[to])
|
||||||
conns = append(conns, struct{ from, to int }{from, to})
|
conns = append(conns, struct{ from, to int }{from, to})
|
||||||
checkApplyUpdate(t, ps[from])
|
checkApplyUpdate(t, ps[from])
|
||||||
|
|||||||
+5
-1
@@ -231,7 +231,11 @@ func (routes *Routes) calculateBroadcast(establishedAndSymmetric bool) map[PeerN
|
|||||||
if _, found := reached[remoteName]; found {
|
if _, found := reached[remoteName]; found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if remoteConn, found := conn.Remote().ConnectionTo(ourself.Name); !establishedAndSymmetric || (found && remoteConn.Established()) {
|
// conn.Remote() cannot by ourself. Modifying
|
||||||
|
// peer.connections requires a write lock on Peers,
|
||||||
|
// and since we are holding a read lock (due to the
|
||||||
|
// ForEach), access without locking the peer is safe.
|
||||||
|
if remoteConn, found := conn.Remote().connections[ourself.Name]; !establishedAndSymmetric || (found && remoteConn.Established()) {
|
||||||
hops = append(hops, remoteName)
|
hops = append(hops, remoteName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user