Commit aa7aa16b authored by Lars Gierth's avatar Lars Gierth
Browse files

WIP

parent b8fcaf47
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
peer "github.com/libp2p/go-libp2p-peer"
swarm "github.com/libp2p/go-libp2p-swarm" swarm "github.com/libp2p/go-libp2p-swarm"
udpt "github.com/libp2p/go-udp-transport" udpt "github.com/libp2p/go-udp-transport"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
...@@ -25,7 +26,16 @@ func main() { ...@@ -25,7 +26,16 @@ func main() {
fatal(err) 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()) s.AddPacketTransport(udpt.NewUDPTransport())
// Add an address to start listening on // Add an address to start listening on
...@@ -35,17 +45,17 @@ func main() { ...@@ -35,17 +45,17 @@ func main() {
} }
// Conn as argument, for WriteMsg()? // Conn as argument, for WriteMsg()?
s.SetMsgHandler(func(msg []byte, peerid string) { s.SetMsgHandler(func(msg []byte, p peer.ID) {
fmt.Printf("got message from %s: %s\n", peerid, string(msg)) fmt.Printf("got message from %s: %s\n", p, string(msg))
_, err = s.WriteMsg(msg, peerid) _, err = s.WriteMsg(msg, p)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
}) })
s.WriteMsg("hey bob", "Qmbob") s.WriteMsg("hey bob", QmBob)
// Wait forever // Wait forever
<-make(chan bool) <-make(chan bool)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment