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-reuseport-transport
Commits
36e5e632
Commit
36e5e632
authored
Jan 19, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some documentation
parent
3cc21601
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
dial.go
dial.go
+8
-0
listen.go
listen.go
+7
-0
No files found.
dial.go
View file @
36e5e632
...
...
@@ -14,10 +14,18 @@ type dialer interface {
DialContext
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
}
// Dial dials the given multiaddr, reusing ports we're currently listening on if
// possible.
//
// Dial attempts to be smart about choosing the source port. For example, If
// we're dialing a loopback address and we're listening on one or more loopback
// ports, Dial will randomly choose one of the loopback ports and addresses and
// reuse it.
func
(
t
*
Transport
)
Dial
(
raddr
ma
.
Multiaddr
)
(
manet
.
Conn
,
error
)
{
return
t
.
DialContext
(
context
.
Background
(),
raddr
)
}
// DialContext is like Dial but takes a context.
func
(
t
*
Transport
)
DialContext
(
ctx
context
.
Context
,
raddr
ma
.
Multiaddr
)
(
manet
.
Conn
,
error
)
{
network
,
addr
,
err
:=
manet
.
DialArgs
(
raddr
)
if
err
!=
nil
{
...
...
listen.go
View file @
36e5e632
...
...
@@ -20,6 +20,13 @@ func (l *listener) Close() error {
return
l
.
Listener
.
Close
()
}
// Listen listens on the given multiaddr.
//
// If reuseport is supported, it will be enabled for this listener and future
// dials from this transport may reuse the port.
//
// Note: You can listen on the same multiaddr as many times as you want
// (although only *one* listener will end up handling the inbound connection).
func
(
t
*
Transport
)
Listen
(
laddr
ma
.
Multiaddr
)
(
manet
.
Listener
,
error
)
{
nw
,
naddr
,
err
:=
manet
.
DialArgs
(
laddr
)
if
err
!=
nil
{
...
...
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