|
|
|
@ -17,10 +17,8 @@ import (
|
|
|
|
|
"github.com/libp2p/go-libp2p-crypto"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var ho h.Host
|
|
|
|
|
var dhtPtr *dht.IpfsDHT
|
|
|
|
|
|
|
|
|
|
func handleConn(conn net.Conn) {
|
|
|
|
|
func createConnHandler(dhtPtr *dht.IpfsDHT, ho h.Host) func(conn net.Conn) {
|
|
|
|
|
return func(conn net.Conn) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
d := *dhtPtr
|
|
|
|
@ -61,6 +59,7 @@ func handleConn(conn net.Conn) {
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Printf("no remote providers!\n")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
@ -84,7 +83,7 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Set up a libp2p host.
|
|
|
|
|
// Set up a libp2p host listening on every interface
|
|
|
|
|
//
|
|
|
|
|
host, err := libp2p.New(ctx,
|
|
|
|
|
libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/9876"),
|
|
|
|
@ -95,22 +94,21 @@ func main() {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
host.Network().SetConnHandler(handleConn)
|
|
|
|
|
|
|
|
|
|
ho = host
|
|
|
|
|
|
|
|
|
|
fmt.Printf("To connect, run:\n")
|
|
|
|
|
fmt.Printf("node js-dht-test/index.js %s/ipfs/%s\n", host.Addrs()[0], host.ID().Pretty())
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Construct a DHT for discovery.
|
|
|
|
|
// Construct a DHT for discovery
|
|
|
|
|
//
|
|
|
|
|
d, err := dht.New(ctx, host, dhtopts.Client(false))
|
|
|
|
|
dhtPtr, err := dht.New(ctx, host, dhtopts.Client(false))
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dhtPtr = d
|
|
|
|
|
//
|
|
|
|
|
// Accept connections from peers
|
|
|
|
|
//
|
|
|
|
|
f := createConnHandler(dhtPtr, host)
|
|
|
|
|
host.Network().SetConnHandler(f)
|
|
|
|
|
fmt.Printf("To connect, run:\n")
|
|
|
|
|
fmt.Printf("node js-dht-test/index.js %s/ipfs/%s\n", host.Addrs()[0], host.ID().Pretty())
|
|
|
|
|
|
|
|
|
|
select {}
|
|
|
|
|
}
|
|
|
|
|