Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

remove dependency on the go-libp2p-peerstore/addr package #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions backoffcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/libp2p/go-libp2p-core/discovery"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-peerstore/addr"
)

// BackoffDiscovery is an implementation of discovery that caches peer data and attenuates repeated queries
Expand Down Expand Up @@ -276,13 +275,26 @@ func findPeerReceiver(ctx context.Context, pch, evtCh chan peer.AddrInfo, rcvPee
}
}

// mergeAddrInfos merges to AddrInfos.
// It returns nil if the merge doesn't add any new addresses.
func mergeAddrInfos(prevAi, newAi peer.AddrInfo) *peer.AddrInfo {
combinedAddrs := addr.UniqueSource(addr.Slice(prevAi.Addrs), addr.Slice(newAi.Addrs)).Addrs()
if len(combinedAddrs) > len(prevAi.Addrs) {
combinedAi := &peer.AddrInfo{ID: prevAi.ID, Addrs: combinedAddrs}
return combinedAi
addrs := prevAi.Addrs
addrLoop:
for _, addr := range newAi.Addrs {
for _, a := range prevAi.Addrs {
if a.Equal(addr) {
continue addrLoop
}
}
addrs = append(addrs, addr)
}
if len(addrs) <= len(prevAi.Addrs) {
return nil
}
return &peer.AddrInfo{
ID: prevAi.ID,
Addrs: addrs,
}
return nil
}

func checkUpdates(orig, update map[peer.ID]peer.AddrInfo) bool {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/ipfs/go-log/v2 v2.4.0
github.com/libp2p/go-libp2p-blankhost v0.2.0
github.com/libp2p/go-libp2p-core v0.11.0
github.com/libp2p/go-libp2p-peerstore v0.4.0
github.com/libp2p/go-libp2p-swarm v0.8.0
github.com/multiformats/go-multihash v0.0.15
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down