Skip to content

Commit

Permalink
add reconnection to known peers
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed May 10, 2023
1 parent 053a08c commit 3cb29dc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions net/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ func (p *Peer) Start() error {
p.mu.Lock()
defer p.mu.Unlock()

// reconnect to known peers
for _, id := range p.host.Peerstore().PeersWithAddrs() {
go func(id peer.ID) {
addr := p.host.Peerstore().PeerInfo(id)
err := p.host.Connect(p.ctx, addr)
if err != nil {
log.Info(
p.ctx,
"Failed to reconnect to peer`",
logging.NewKV("peer", id),
)
}
}(id)
}

p2plistener, err := gostream.Listen(p.host, corenet.Protocol)
if err != nil {
return err
Expand Down

0 comments on commit 3cb29dc

Please sign in to comment.