diff --git a/src/main.go b/src/main.go index 6778982..0297473 100644 --- a/src/main.go +++ b/src/main.go @@ -5,8 +5,11 @@ import ( "context" "fmt" "log" + mrand "math/rand" + "time" "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/network" relayv1 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv1/relay" @@ -27,11 +30,22 @@ func run() { // Create a libp2p host, able to be a relay // Should connect other clients together + r := mrand.New(mrand.NewSource(time.Now().UnixMicro())) + + // Generate a key pair for this host. We will use it at least + // to obtain a valid host ID. + priv, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, r) + if err != nil { + log.Printf("Error creating key pair: %v\n", err) + return + } + // Create a host h1 that is a relay h1, err := libp2p.New(libp2p.DisableRelay(), // Set transports libp2p.Transport(tcp.NewTCPTransport), libp2p.Transport(libp2pquic.NewTransport), + libp2p.Identity(priv), // Set listenaddrs libp2p.ListenAddrStrings( "/ip4/0.0.0.0/tcp/6666",