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
e80e6dde
Unverified
Commit
e80e6dde
authored
Dec 28, 2017
by
Steven Allen
Committed by
GitHub
Dec 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20 from libp2p/fix/19
Set source port iff using reuseport
parents
7596c750
e6940407
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
31 deletions
+43
-31
package.json
package.json
+2
-2
tcp.go
tcp.go
+41
-29
No files found.
package.json
View file @
e80e6dde
...
...
@@ -27,9 +27,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
QGRkVSA5vTXt9WpJ6nBGnrvq9zRNsfjoNPq8uQrhnBoq
"
,
"hash"
:
"Qm
ZE4uDRWo12UWKZa65CQLZR4t3jkmWc1ZdA1fBzT3XQEx
"
,
"name"
:
"go-libp2p-transport"
,
"version"
:
"2.2.1
0
"
"version"
:
"2.2.1
1
"
},
{
"hash"
:
"QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52"
,
...
...
tcp.go
View file @
e80e6dde
...
...
@@ -50,14 +50,6 @@ func (t *TcpTransport) Dialer(laddr ma.Multiaddr, opts ...tpt.DialOpt) (tpt.Dial
if
found
{
return
d
,
nil
}
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
)
{
...
...
@@ -68,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
}
...
...
@@ -142,7 +134,25 @@ 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
:=
maddrToTcp
(
laddr
)
if
err
!=
nil
{
return
nil
,
err
}
var
pattern
mafmt
.
Pattern
if
TCP4
.
Matches
(
laddr
)
{
pattern
=
TCP4
...
...
@@ -152,28 +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
{
D
:
base
.
Dialer
,
dialer
.
doReuse
=
true
dialer
.
rd
=
reuseport
.
Dialer
{
D
:
net
.
Dialer
{
LocalAddr
:
la
,
},
}
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