2022-08-17 06:38:57 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-10-07 07:24:51 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p"
|
2022-08-17 06:38:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *client) connectToPeers(ctx context.Context, peerMultiaddrs ...string) error {
|
|
|
|
peers, err := p2p.PeersFromStringAddrs(peerMultiaddrs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
addrInfos, err := peer.AddrInfosFromP2pAddrs(peers...)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
for _, info := range addrInfos {
|
|
|
|
if info.ID == c.host.ID() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := c.host.Connect(ctx, info); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|