From af1302af3ea4c560159cf4f4ff3379ea6595d7f4 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 26 Jul 2017 16:40:00 +0200 Subject: [PATCH] fix source address not being set in non REUSEPORT dialer --- p2p/transport/tcp/tcp.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/p2p/transport/tcp/tcp.go b/p2p/transport/tcp/tcp.go index a30dcbb7b0..e851a2084d 100644 --- a/p2p/transport/tcp/tcp.go +++ b/p2p/transport/tcp/tcp.go @@ -51,6 +51,12 @@ func (t *TcpTransport) Dialer(laddr ma.Multiaddr, opts ...tpt.DialOpt) (tpt.Dial } var base manet.Dialer + la, err := manet.ToNetAddr(laddr) + if err != nil { + return nil, err // something wrong with laddr. + } + base.Dialer.LocalAddr = la + var doReuse bool for _, o := range opts { switch o := o.(type) { @@ -136,12 +142,6 @@ type tcpDialer struct { } func (t *TcpTransport) newTcpDialer(base manet.Dialer, laddr ma.Multiaddr, doReuse bool) (*tcpDialer, error) { - // get the local net.Addr manually - la, err := manet.ToNetAddr(laddr) - if err != nil { - return nil, err // something wrong with laddr. - } - var pattern mafmt.Pattern if TCP4.Matches(laddr) { pattern = TCP4 @@ -153,10 +153,7 @@ func (t *TcpTransport) newTcpDialer(base manet.Dialer, laddr ma.Multiaddr, doReu if doReuse && ReuseportIsAvailable() { rd := reuseport.Dialer{ - D: net.Dialer{ - LocalAddr: la, - Timeout: base.Timeout, - }, + D: base.Dialer, } return &tcpDialer{