Skip to content

Commit

Permalink
fix source address not being set in non REUSEPORT dialer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kubuxu committed Jul 26, 2017
1 parent 53da0c0 commit af1302a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions p2p/transport/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand Down

0 comments on commit af1302a

Please sign in to comment.