diff --git a/limiter.go b/limiter.go index 391b828f014a0ca9a6d4360aac25e04a259c583f..02aed50a2eb5d43cb60d6e2490f8c4b4de55e584 100644 --- a/limiter.go +++ b/limiter.go @@ -34,7 +34,7 @@ func (dj *dialJob) cancelled() bool { } func (dj *dialJob) dialTimeout() time.Duration { - timeout := DialTimeout + timeout := transport.DialTimeout if lowTimeoutFilters.AddrBlocked(dj.addr) { timeout = DialTimeoutLocal } diff --git a/swarm.go b/swarm.go index 0a50bed9e6054772d51621905da084a9bb06b841..7d795abd861762d327791396c7ca40c8bb862cca 100644 --- a/swarm.go +++ b/swarm.go @@ -37,11 +37,6 @@ var ErrSwarmClosed = errors.New("swarm closed") // transport is misbehaving. var ErrAddrFiltered = errors.New("address filtered") -// DialTimeout is the maximum duration a Dial is allowed to take. -// This includes the time between dialing the raw network connection, -// protocol selection as well the handshake, if applicable. -var DialTimeout = 60 * time.Second - // Swarm is a connection muxer, allowing connections to other peers to // be opened and closed, while still using the same Chan for all // communication. The Chan sends/receives Messages, which note the diff --git a/swarm_dial.go b/swarm_dial.go index fe7a4cbfd54266cf6f2857d4d1b513e5ebb748de..3e0cfafac2de5f403976ca4746df78b0a16988c5 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -202,10 +202,15 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) { return nil, ErrDialBackoff } + // apply the DialPeer timeout + ctx, cancel := context.WithTimeout(ctx, inet.GetDialPeerTimeout(ctx)) + defer cancel() + conn, err := s.dsync.DialLock(ctx, p) if err != nil { return nil, err } + log.Debugf("network for %s finished dialing %s", s.local, p) return conn, err } @@ -256,9 +261,6 @@ func (s *Swarm) canDial(addr ma.Multiaddr) bool { // dial is the actual swarm's dial logic, gated by Dial. func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { - ctx, cancel := context.WithTimeout(ctx, DialTimeout) - defer cancel() - var logdial = lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil) if p == s.local { log.Event(ctx, "swarmDialDoDialSelf", logdial)