Commit f3880753 authored by acud's avatar acud Committed by GitHub

kademlia: add timeout to connect (#332)

* add timeout to connect
parent c3efa490
......@@ -251,6 +251,8 @@ func (k *Kad) recalcDepth() uint8 {
// connect connects to a peer and gossips its address to our connected peers,
// as well as sends the peers we are connected to to the newly connected peer
func (k *Kad) connect(ctx context.Context, peer swarm.Address, ma ma.Multiaddr, po uint8) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, err := k.p2p.Connect(ctx, ma)
if err != nil {
if errors.Is(err, p2p.ErrAlreadyConnected) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment