Skip to content

Commit

Permalink
fix: Add reconnection to known peers (#1482)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #1481 

## Description

Currently, we de not reconnect to known peers on restart unless the peer
is defined in the config file or on the CLI command. This PR makes sure
that we try to reconnect to known peers.
  • Loading branch information
fredcarle authored May 10, 2023
1 parent 9fa6e81 commit 36261e1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions net/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ func (p *Peer) Start() error {
p.mu.Lock()
defer p.mu.Unlock()

// reconnect to known peers
for _, id := range p.host.Peerstore().PeersWithAddrs() {
if id == p.host.ID() {
continue
}
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,
"Failure while reconnecting to a known peer",
logging.NewKV("peer", id),
logging.NewKV("error", err),
)
}
}(id)
}

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

0 comments on commit 36261e1

Please sign in to comment.