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
aa7aa16b
Commit
aa7aa16b
authored
Sep 18, 2017
by
Lars Gierth
Browse files
WIP
parent
b8fcaf47
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/datagram/main.go
View file @
aa7aa16b
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
peer
"github.com/libp2p/go-libp2p-peer"
swarm
"github.com/libp2p/go-libp2p-swarm"
udpt
"github.com/libp2p/go-udp-transport"
ma
"github.com/multiformats/go-multiaddr"
...
...
@@ -25,7 +26,16 @@ func main() {
fatal
(
err
)
}
s
:=
swarm
.
NewBlankSwarm
(
context
.
Background
(),
"Qmbob"
,
nil
,
nil
)
QmAlice
,
err
:=
peer
.
IDFromString
(
"QmAlice"
)
if
err
!=
nil
{
fatal
(
err
)
}
QmBob
,
err
:=
peer
.
IDFromString
(
"QmBob"
)
if
err
!=
nil
{
fatal
(
err
)
}
s
:=
swarm
.
NewBlankSwarm
(
context
.
Background
(),
QmAlice
,
nil
,
nil
)
s
.
AddPacketTransport
(
udpt
.
NewUDPTransport
())
// Add an address to start listening on
...
...
@@ -35,17 +45,17 @@ func main() {
}
// Conn as argument, for WriteMsg()?
s
.
SetMsgHandler
(
func
(
msg
[]
byte
,
peer
id
string
)
{
fmt
.
Printf
(
"got message from %s: %s
\n
"
,
p
eerid
,
string
(
msg
))
s
.
SetMsgHandler
(
func
(
msg
[]
byte
,
p
peer
.
ID
)
{
fmt
.
Printf
(
"got message from %s: %s
\n
"
,
p
,
string
(
msg
))
_
,
err
=
s
.
WriteMsg
(
msg
,
p
eerid
)
_
,
err
=
s
.
WriteMsg
(
msg
,
p
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
})
s
.
WriteMsg
(
"hey bob"
,
"
Qm
b
ob
"
)
s
.
WriteMsg
(
"hey bob"
,
Qm
B
ob
)
// 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