Commit 46f34ff8 authored by Jeromy's avatar Jeromy

swarm: add deadline for connection setup

parent 9da803ca
......@@ -372,10 +372,21 @@ func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (con
return connC, nil
}
var ConnSetupTimeout = time.Minute * 5
// dialConnSetup is the setup logic for a connection from the dial side. it
// needs to add the Conn to the StreamSwarm, then run newConnSetup
func dialConnSetup(ctx context.Context, s *Swarm, connC conn.Conn) (*Conn, error) {
deadline, ok := ctx.Deadline()
if !ok {
deadline = time.Now().Add(ConnSetupTimeout)
}
if err := connC.SetDeadline(deadline); err != nil {
return nil, err
}
psC, err := s.swarm.AddConn(connC)
if err != nil {
// connC is closed by caller if we fail.
......@@ -389,5 +400,10 @@ func dialConnSetup(ctx context.Context, s *Swarm, connC conn.Conn) (*Conn, error
return nil, err
}
if err := connC.SetDeadline(time.Time{}); err != nil {
log.Error("failed to reset connection deadline after setup: ", err)
return nil, err
}
return swarmC, err
}
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