Merge pull request #352 from libp2p/nit/optimize

check for connectedness using Connectedness
This commit is contained in:
Steven Allen 2018-06-14 18:44:06 +00:00 committed by GitHub
commit 74486ec970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 3 deletions

View File

@ -384,8 +384,7 @@ func (h *BasicHost) Connect(ctx context.Context, pi pstore.PeerInfo) error {
// absorb addresses into peerstore
h.Peerstore().AddAddrs(pi.ID, pi.Addrs, pstore.TempAddrTTL)
cs := h.Network().ConnsToPeer(pi.ID)
if len(cs) > 0 {
if h.Network().Connectedness(pi.ID) == inet.Connected {
return nil
}

View File

@ -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.
func (rh *RoutedHost) Connect(ctx context.Context, pi pstore.PeerInfo) error {
// 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
}