Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (

// This file implements the Routing interface for the IpfsDHT struct.

// putOperationTimeout is the per-peer timeout for PUT_VALUE and ADD_PROVIDER operations.
const putOperationTimeout = 30 * time.Second

// Basic Put/Get

// PutValue adds value corresponding to given Key.
Expand Down Expand Up @@ -78,7 +81,7 @@ func (dht *IpfsDHT) PutValue(ctx context.Context, key string, value []byte, opts
for _, p := range peers {
wg.Add(1)
go func(p peer.ID) {
ctx, cancel := context.WithCancel(ctx)
ctx, cancel := context.WithTimeout(ctx, putOperationTimeout)
defer cancel()
defer wg.Done()
routing.PublishQueryEvent(ctx, &routing.QueryEvent{
Expand Down Expand Up @@ -271,7 +274,7 @@ func (dht *IpfsDHT) updatePeerValues(ctx context.Context, key string, val []byte
}
return
}
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
ctx, cancel := context.WithTimeout(ctx, putOperationTimeout)
defer cancel()
err := dht.protoMessenger.PutValue(ctx, p, fixupRec)
if err != nil {
Expand Down Expand Up @@ -454,6 +457,8 @@ func (dht *IpfsDHT) classicProvide(ctx context.Context, keyMH multihash.Multihas
wg.Add(1)
go func(p peer.ID) {
defer wg.Done()
ctx, cancel := context.WithTimeout(ctx, putOperationTimeout)
defer cancel()
logger.Debugf("putProvider(%s, %s)", internal.LoggableProviderRecordBytes(keyMH), p)
err := dht.protoMessenger.PutProviderAddrs(ctx, p, keyMH, peer.AddrInfo{
ID: dht.self,
Expand Down