Commit 5dea71d2 authored by Jeromy's avatar Jeromy

swarm: add optimized method for checking connectedness to peer

parent 48ef0bb9
......@@ -286,6 +286,15 @@ func (s *Swarm) ConnectionsToPeer(p peer.ID) []*Conn {
return wrapConns(ps.ConnsWithGroup(p, s.swarm.Conns()))
}
func (s *Swarm) HaveConnsToPeer(p peer.ID) bool {
for _, c := range s.swarm.Conns() {
if c.InGroup(p) {
return true
}
}
return false
}
// Connections returns a slice of all connections.
func (s *Swarm) Connections() []*Conn {
return wrapConns(s.swarm.Conns())
......
......@@ -123,8 +123,7 @@ func (n *Network) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
// Connectedness returns a state signaling connection capabilities
// For now only returns Connected || NotConnected. Expand into more later.
func (n *Network) Connectedness(p peer.ID) inet.Connectedness {
c := n.Swarm().ConnectionsToPeer(p)
if len(c) > 0 {
if n.Swarm().HaveConnsToPeer(p) {
return inet.Connected
}
return inet.NotConnected
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment