Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-tcp-transport
Commits
116adaa6
Commit
116adaa6
authored
Dec 27, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set the source IP, but not port, when not using the reuseport dialer
parent
75e68219
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
25 deletions
+34
-25
tcp.go
tcp.go
+34
-25
No files found.
tcp.go
View file @
116adaa6
...
...
@@ -50,8 +50,6 @@ func (t *TcpTransport) Dialer(laddr ma.Multiaddr, opts ...tpt.DialOpt) (tpt.Dial
if
found
{
return
d
,
nil
}
var
base
manet
.
Dialer
var
doReuse
bool
for
_
,
o
:=
range
opts
{
switch
o
:=
o
.
(
type
)
{
...
...
@@ -62,7 +60,7 @@ func (t *TcpTransport) Dialer(laddr ma.Multiaddr, opts ...tpt.DialOpt) (tpt.Dial
}
}
tcpd
,
err
:=
t
.
newTcpDialer
(
base
,
laddr
,
doReuse
)
tcpd
,
err
:=
t
.
newTcpDialer
(
laddr
,
doReuse
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -136,11 +134,23 @@ type tcpDialer struct {
var
_
tpt
.
Dialer
=
&
tcpDialer
{}
func
(
t
*
TcpTransport
)
newTcpDialer
(
base
manet
.
Dialer
,
laddr
ma
.
Multiaddr
,
doReuse
bool
)
(
*
tcpDialer
,
error
)
{
func
maddrToTcp
(
addr
ma
.
Multiaddr
)
(
*
net
.
TCPAddr
,
error
)
{
la
,
err
:=
manet
.
ToNetAddr
(
addr
)
if
err
!=
nil
{
return
nil
,
err
// something wrong with addr.
}
latcp
,
ok
:=
la
.
(
*
net
.
TCPAddr
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"not a tcp multiaddr: %s"
,
addr
)
}
return
latcp
,
nil
}
func
(
t
*
TcpTransport
)
newTcpDialer
(
laddr
ma
.
Multiaddr
,
doReuse
bool
)
(
*
tcpDialer
,
error
)
{
// get the local net.Addr manually
la
,
err
:=
ma
net
.
ToNetAddr
(
laddr
)
la
,
err
:=
ma
ddrToTcp
(
laddr
)
if
err
!=
nil
{
return
nil
,
err
// something wrong with laddr.
return
nil
,
err
}
var
pattern
mafmt
.
Pattern
...
...
@@ -152,31 +162,30 @@ func (t *TcpTransport) newTcpDialer(base manet.Dialer, laddr ma.Multiaddr, doReu
return
nil
,
fmt
.
Errorf
(
"local addr did not match TCP4 or TCP6: %s"
,
laddr
)
}
// Ignore the port when constructing the default (non-reuseport) dialer.
labase
:=
*
la
labase
.
Port
=
0
dialer
:=
&
tcpDialer
{
laddr
:
laddr
,
pattern
:
pattern
,
madialer
:
manet
.
Dialer
{
Dialer
:
net
.
Dialer
{
LocalAddr
:
&
labase
,
},
},
transport
:
t
,
}
if
doReuse
&&
ReuseportIsAvailable
()
{
rd
:=
reuseport
.
Dialer
{
dialer
.
doReuse
=
true
dialer
.
rd
=
reuseport
.
Dialer
{
D
:
net
.
Dialer
{
LocalAddr
:
la
,
Timeout
:
base
.
Timeout
,
},
}
return
&
tcpDialer
{
doReuse
:
true
,
laddr
:
laddr
,
rd
:
rd
,
madialer
:
base
,
transport
:
t
,
pattern
:
pattern
,
},
nil
}
return
&
tcpDialer
{
doReuse
:
false
,
laddr
:
laddr
,
pattern
:
pattern
,
madialer
:
base
,
transport
:
t
,
},
nil
return
dialer
,
nil
}
func
(
d
*
tcpDialer
)
Dial
(
raddr
ma
.
Multiaddr
)
(
tpt
.
Conn
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment