simplify dial timeout context
From the documentation:
WithDeadline returns a copy of the parent context with the deadline
adjusted to be no later than d. If the parent's deadline is already
earlier than d, WithDeadline(parent, d) is semantically equivalent to
parent.
@@ -121,13 +121,10 @@ func (t *TcpTransport) CanDial(addr ma.Multiaddr) bool {
func (t *TcpTransport) maDial(ctx context.Context, raddr ma.Multiaddr) (manet.Conn, error) {
// Apply the deadline iff applicable
if t.ConnectTimeout > 0 {
- deadline := time.Now().Add(t.ConnectTimeout)
- if d, ok := ctx.Deadline(); !ok || deadline.Before(d) {
- var cancel func()
- ctx, cancel = context.WithDeadline(ctx, deadline)
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, t.ConnectTimeout)
defer cancel()
}
- }
if t.UseReuseport() {
return t.reuse.DialContext(ctx, raddr)
