fix source address not being set in non REUSEPORT dialer

parent 9e0ef121
...@@ -51,6 +51,12 @@ func (t *TcpTransport) Dialer(laddr ma.Multiaddr, opts ...tpt.DialOpt) (tpt.Dial ...@@ -51,6 +51,12 @@ func (t *TcpTransport) Dialer(laddr ma.Multiaddr, opts ...tpt.DialOpt) (tpt.Dial
} }
var base manet.Dialer 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 var doReuse bool
for _, o := range opts { for _, o := range opts {
switch o := o.(type) { switch o := o.(type) {
...@@ -136,12 +142,6 @@ type tcpDialer struct { ...@@ -136,12 +142,6 @@ type tcpDialer struct {
} }
func (t *TcpTransport) newTcpDialer(base manet.Dialer, laddr ma.Multiaddr, doReuse bool) (*tcpDialer, error) { 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 var pattern mafmt.Pattern
if TCP4.Matches(laddr) { if TCP4.Matches(laddr) {
pattern = TCP4 pattern = TCP4
...@@ -153,10 +153,7 @@ func (t *TcpTransport) newTcpDialer(base manet.Dialer, laddr ma.Multiaddr, doReu ...@@ -153,10 +153,7 @@ func (t *TcpTransport) newTcpDialer(base manet.Dialer, laddr ma.Multiaddr, doReu
if doReuse && ReuseportIsAvailable() { if doReuse && ReuseportIsAvailable() {
rd := reuseport.Dialer{ rd := reuseport.Dialer{
D: net.Dialer{ D: base.Dialer,
LocalAddr: la,
Timeout: base.Timeout,
},
} }
return &tcpDialer{ return &tcpDialer{
......
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