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
mf
go-multiaddr
Commits
69423986
Unverified
Commit
69423986
authored
Aug 09, 2019
by
Steven Allen
Committed by
GitHub
Aug 09, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #36 from multiformats/feat/udp
Make PacketConn more idiomatic and direct
parents
bd61b049
9feee519
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
18 deletions
+15
-18
net.go
net.go
+13
-16
net_test.go
net_test.go
+2
-2
No files found.
net.go
View file @
69423986
...
...
@@ -109,6 +109,8 @@ type maEndpoints struct {
raddr
ma
.
Multiaddr
}
var
_
Conn
=
(
*
maConn
)(
nil
)
// LocalMultiaddr returns the local address associated with
// this connection
func
(
c
*
maEndpoints
)
LocalMultiaddr
()
ma
.
Multiaddr
{
...
...
@@ -310,14 +312,12 @@ func WrapNetListener(nl net.Listener) (Listener, error) {
// A PacketConn is a generic packet oriented network connection which uses an
// underlying net.PacketConn, wrapped with the locally bound Multiaddr.
type
PacketConn
interface
{
Connection
()
net
.
PacketConn
Multiaddr
()
ma
.
Multiaddr
net
.
PacketConn
ReadFrom
(
b
[]
byte
)
(
int
,
ma
.
Multiaddr
,
error
)
WriteTo
(
b
[]
byte
,
maddr
ma
.
Multiaddr
)
(
int
,
error
)
LocalMultiaddr
()
ma
.
Multiaddr
Close
()
error
ReadFromMultiaddr
(
b
[]
byte
)
(
int
,
ma
.
Multiaddr
,
error
)
WriteToMultiaddr
(
b
[]
byte
,
maddr
ma
.
Multiaddr
)
(
int
,
error
)
}
// maPacketConn implements PacketConn
...
...
@@ -326,28 +326,25 @@ type maPacketConn struct {
laddr
ma
.
Multiaddr
}
// Connection returns the embedded net.PacketConn.
func
(
l
*
maPacketConn
)
Connection
()
net
.
PacketConn
{
return
l
.
PacketConn
}
var
_
PacketConn
=
(
*
maPacketConn
)(
nil
)
// Multiaddr returns the bound local Multiaddr.
func
(
l
*
maPacketConn
)
Multiaddr
()
ma
.
Multiaddr
{
//
Local
Multiaddr returns the bound local Multiaddr.
func
(
l
*
maPacketConn
)
Local
Multiaddr
()
ma
.
Multiaddr
{
return
l
.
laddr
}
func
(
l
*
maPacketConn
)
ReadFrom
(
b
[]
byte
)
(
int
,
ma
.
Multiaddr
,
error
)
{
n
,
addr
,
err
:=
l
.
PacketConn
.
ReadFrom
(
b
)
func
(
l
*
maPacketConn
)
ReadFrom
Multiaddr
(
b
[]
byte
)
(
int
,
ma
.
Multiaddr
,
error
)
{
n
,
addr
,
err
:=
l
.
ReadFrom
(
b
)
maddr
,
_
:=
FromNetAddr
(
addr
)
return
n
,
maddr
,
err
}
func
(
l
*
maPacketConn
)
WriteTo
(
b
[]
byte
,
maddr
ma
.
Multiaddr
)
(
int
,
error
)
{
func
(
l
*
maPacketConn
)
WriteTo
Multiaddr
(
b
[]
byte
,
maddr
ma
.
Multiaddr
)
(
int
,
error
)
{
addr
,
err
:=
ToNetAddr
(
maddr
)
if
err
!=
nil
{
return
0
,
err
}
return
l
.
PacketConn
.
WriteTo
(
b
,
addr
)
return
l
.
WriteTo
(
b
,
addr
)
}
// ListenPacket announces on the local network address laddr.
...
...
net_test.go
View file @
69423986
...
...
@@ -323,8 +323,8 @@ func TestListenPacketAndDial(t *testing.T) {
wg
.
Add
(
1
)
go
func
()
{
if
!
pc
.
Multiaddr
()
.
Equal
(
maddr
)
{
t
.
Fatal
(
"connection multiaddr not equal:"
,
maddr
,
pc
.
Multiaddr
())
if
!
pc
.
Local
Multiaddr
()
.
Equal
(
maddr
)
{
t
.
Fatal
(
"connection multiaddr not equal:"
,
maddr
,
pc
.
Local
Multiaddr
())
}
buffer
:=
make
([]
byte
,
1024
)
...
...
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