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
dms3
go-dms3
Commits
223a97f3
Commit
223a97f3
authored
Jan 20, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/net/conn: only reuseport if avail
parent
ee4c727c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
15 deletions
+22
-15
p2p/net/conn/dial.go
p2p/net/conn/dial.go
+1
-1
p2p/net/conn/listen.go
p2p/net/conn/listen.go
+21
-14
No files found.
p2p/net/conn/dial.go
View file @
223a97f3
...
...
@@ -89,7 +89,7 @@ func (d *Dialer) rawConnDial(ctx context.Context, raddr ma.Multiaddr, remote pee
laddr
:=
pickLocalAddr
(
d
.
LocalAddrs
,
raddr
)
log
.
Debugf
(
"%s dialing %s -- %s --> %s"
,
d
.
LocalPeer
,
remote
,
laddr
,
raddr
)
if
laddr
!=
nil
{
if
laddr
!=
nil
&&
reuseport
.
Available
()
{
// dial using reuseport.Dialer, because we're probably reusing addrs.
// this is optimistic, as the reuseDial may fail to bind the port.
if
nconn
,
retry
,
reuseErr
:=
d
.
reuseDial
(
laddr
,
raddr
);
reuseErr
==
nil
{
...
...
p2p/net/conn/listen.go
View file @
223a97f3
...
...
@@ -124,20 +124,7 @@ func (l *listener) Loggable() map[string]interface{} {
// Listen listens on the particular multiaddr, with given peer and peerstore.
func
Listen
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
,
local
peer
.
ID
,
sk
ic
.
PrivKey
)
(
Listener
,
error
)
{
network
,
naddr
,
err
:=
manet
.
DialArgs
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
// _ := reuseport.Listen
// ml, err := manet.Listen(addr)
nl
,
err
:=
reuseport
.
Listen
(
network
,
naddr
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Failed to listen on %s: %s"
,
addr
,
err
)
}
ml
,
err
:=
manet
.
WrapNetListener
(
nl
)
ml
,
err
:=
manetListen
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -154,3 +141,23 @@ func Listen(ctx context.Context, addr ma.Multiaddr, local peer.ID, sk ic.PrivKey
log
.
Event
(
ctx
,
"swarmListen"
,
l
)
return
l
,
nil
}
func
manetListen
(
addr
ma
.
Multiaddr
)
(
manet
.
Listener
,
error
)
{
network
,
naddr
,
err
:=
manet
.
DialArgs
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
if
reuseport
.
Available
()
{
nl
,
err
:=
reuseport
.
Listen
(
network
,
naddr
)
if
err
==
nil
{
// hey, it worked!
return
manet
.
WrapNetListener
(
nl
)
}
// reuseport is available, but we failed to listen. log debug, and retry normally.
log
.
Debugf
(
"reuseport available, but failed to listen: %s %s, %s"
,
network
,
naddr
,
err
)
}
// either reuseport not available, or it failed. try normally.
return
manet
.
Listen
(
addr
)
}
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