go-waku/waku/v2/utils/multiaddr.go

27 lines
712 B
Go
Raw Normal View History

2023-07-07 15:51:15 +00:00
package utils
import (
"fmt"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
)
// EncapsulatePeerID takes a peer.ID and adds a p2p component to all multiaddresses it receives
func EncapsulatePeerID(peerID peer.ID, addrs ...multiaddr.Multiaddr) []multiaddr.Multiaddr {
hostInfo, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/p2p/%s", peerID.String()))
2023-07-07 15:51:15 +00:00
var result []multiaddr.Multiaddr
for _, addr := range addrs {
result = append(result, addr.Encapsulate(hostInfo))
}
return result
}
2023-10-16 16:28:54 +00:00
func MultiAddrSet(addr ...multiaddr.Multiaddr) map[multiaddr.Multiaddr]struct{} {
r := make(map[multiaddr.Multiaddr]struct{})
for _, a := range addr {
r[a] = struct{}{}
}
return r
}