Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
231b8f2b
Commit
231b8f2b
authored
Mar 24, 2018
by
Lars Gierth
Browse files
WIP
parent
aa7aa16b
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/datagram/README.md
View file @
231b8f2b
...
...
@@ -5,51 +5,27 @@ I'm using it to test out interfaces and conventions, and also to produce working
For now it's going to be the simplest possible echo server/client.
##
Addition
s
##
New package
s
package p2phost
type MsgHandler func(peer.ID, protocol.ID, []byte)
type Host interface {
MsgMux()
*
msmux.MultigramMuxer
SetMsgHandler(protocol.ID, inet.MsgHandler)
SetMsgHandlerMatch(protocol.ID, func(string) bool, MsgHandler)
RemoveMsgHandler(protocol.ID)
WriteMsg(context.Context, peer.ID, ...protocol.ID, []byte)
}
package p2pswarm
type MsgHandler func(peer.ID, []byte)
func (s
*
Swarm) AddPacketTransport(p2ptransport.PacketTransport) {}
func (s
*
Swarm) SetMsgHandler(MsgHandler) {}
func (s
*
Swarm) MsgHandler() MsgHandler {}
package p2piconn
type PacketConn interface {}
package p2pnet
package p2pstream
func NoOpMsgHandler(msg []byte, peeridOrConn) {}
package p2ptransport
package udptransport
-
[ ] go-multigram
-
[ ] go-multigram-select
-
[ ] go-libp2p-wireguard
-
[ ] go-udp-transport
package manet
##
TODO
##
Affected packages
-
[ ] go-multiaddr-net datagram support
-
[ ] go-libp2p-transport datagram support
-
[ ] go-udp-transport
-
[ ] go-peerstream datagram support
-
[ ] go-libp2p-swarm datagram support
-
[ ] go-multigram
-
[ ] go-shs vs. go-dtls vs. go-cryptoauth
-
[ ] label-based switch
-
[ ] overlay routing interfaces
-
[x] go-multiaddr-net (manet.PacketConn)
-
[ ] go-libp2p-transport (tptiface.PacketTransport/Dialer/Conn)
-
[ ] go-libp2p-swarm (sw.AddPacketTransport(), sw.SetPacketHandler(), sw.WritePacket())
-
[ ] go-libp2p-host (hostiface.SetPacketHandler(), hostiface.WritePacket())
-
[ ] go-libp2p-net (netiface.PacketHandler)
##
PR
##
About wireguard-go
This PR adds APIs for message-based communication
-
Looks good, but way too tightly coupled
-
main.go, device.go
-
send.go, receive.go
-
device routines/queues and peer routines/queues
-
split up: packetconn, cli+uapi+tun+routing
examples/datagram/main.go
View file @
231b8f2b
...
...
@@ -16,7 +16,6 @@ func fatal(i interface{}) {
os
.
Exit
(
1
)
}
// XXX unrewritten broken because jbenet/go-stream-muxer is out of date
// TODO move to libp2p org: go-stream-muxer go-smux-multistream go-smux-spdystream go-smux-yamux
// TODO multigram will live in BasicHost, for now it's only swarm
...
...
@@ -44,18 +43,17 @@ func main() {
fatal
(
err
)
}
// Conn as argument, for WriteMsg()?
s
.
SetMsgHandler
(
func
(
msg
[]
byte
,
p
peer
.
ID
)
{
fmt
.
Printf
(
"got message from %s: %s
\n
"
,
p
,
string
(
msg
))
s
.
SetPacketHandler
(
func
(
pkt
*
[]
byte
,
p
peer
.
ID
)
{
fmt
.
Printf
(
"got message from %s: %s
\n
"
,
p
,
pkt
)
_
,
err
=
s
.
Write
Msg
(
msg
,
p
)
_
,
err
=
s
.
Write
Packet
(
pkt
,
p
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
})
s
.
Write
Msg
(
"hey bob"
,
QmBob
)
//
s.Write
Packet
("hey bob", QmBob)
// Wait forever
<-
make
(
chan
bool
)
...
...
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