mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 20:07:45 +08:00
p2p/net/swarm: dial timeout to 10s + dialer
This commit is contained in:
parent
5b4a3c09bd
commit
8de8ed0842
@ -3,6 +3,7 @@ package swarm
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -13,6 +14,7 @@ import (
|
||||
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||
manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
|
||||
)
|
||||
|
||||
// dialAttempts governs how many times a goroutine will try to dial a given peer.
|
||||
@ -21,7 +23,7 @@ const dialAttempts = 3
|
||||
// DialTimeout is the amount of time each dial attempt has. We can think about making
|
||||
// this larger down the road, or putting more granular timeouts (i.e. within each
|
||||
// subcomponent of Dial)
|
||||
var DialTimeout time.Duration = time.Second * 30
|
||||
var DialTimeout time.Duration = time.Second * 10
|
||||
|
||||
// dialsync is a small object that helps manage ongoing dials.
|
||||
// this way, if we receive many simultaneous dial requests, one
|
||||
@ -185,6 +187,11 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
|
||||
|
||||
// open connection to peer
|
||||
d := &conn.Dialer{
|
||||
Dialer: manet.Dialer{
|
||||
Dialer: net.Dialer{
|
||||
Timeout: DialTimeout,
|
||||
},
|
||||
},
|
||||
LocalPeer: s.local,
|
||||
LocalAddrs: localAddrs,
|
||||
PrivateKey: sk,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user