Commit a361bf03 authored by Steven Allen's avatar Steven Allen
Browse files

check for connectedness using Connectedness

(counting open connections requires copying)
parent a08d9e63
...@@ -384,8 +384,7 @@ func (h *BasicHost) Connect(ctx context.Context, pi pstore.PeerInfo) error { ...@@ -384,8 +384,7 @@ func (h *BasicHost) Connect(ctx context.Context, pi pstore.PeerInfo) error {
// absorb addresses into peerstore // absorb addresses into peerstore
h.Peerstore().AddAddrs(pi.ID, pi.Addrs, pstore.TempAddrTTL) h.Peerstore().AddAddrs(pi.ID, pi.Addrs, pstore.TempAddrTTL)
cs := h.Network().ConnsToPeer(pi.ID) if h.Network().Connectedness(pi.ID) == inet.Connected {
if len(cs) > 0 {
return nil return nil
} }
......
...@@ -47,7 +47,7 @@ func Wrap(h host.Host, r Routing) *RoutedHost { ...@@ -47,7 +47,7 @@ func Wrap(h host.Host, r Routing) *RoutedHost {
// given peer, it will use its routing system to try to find some. // given peer, it will use its routing system to try to find some.
func (rh *RoutedHost) Connect(ctx context.Context, pi pstore.PeerInfo) error { func (rh *RoutedHost) Connect(ctx context.Context, pi pstore.PeerInfo) error {
// first, check if we're already connected. // first, check if we're already connected.
if len(rh.Network().ConnsToPeer(pi.ID)) > 0 { if rh.Network().Connectedness(pi.ID) == inet.Connected {
return nil return nil
} }
......
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