Last active
December 16, 2020 08:54
-
-
Save upperwal/b80bd1516fbad79d0d2c7c4f5b99421b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
mrand "math/rand" | |
logging "github.com/ipfs/go-log" | |
libp2p "github.com/libp2p/go-libp2p" | |
"github.com/libp2p/go-libp2p-crypto" | |
dht "github.com/libp2p/go-libp2p-kad-dht" | |
inet "github.com/libp2p/go-libp2p-net" | |
ma "github.com/multiformats/go-multiaddr" | |
) | |
func main() { | |
ctx := context.Background() | |
// libp2p.New constructs a new libp2p Host. | |
// Other options can be added here. | |
sourceMultiAddr, _ := ma.NewMultiaddr("/ip4/0.0.0.0/tcp/4000") | |
r := mrand.New(mrand.NewSource(int64(10))) | |
prvKey, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, r) | |
if err != nil { | |
panic(err) | |
} | |
host, err := libp2p.New( | |
ctx, | |
libp2p.ListenAddrs(sourceMultiAddr), | |
libp2p.Identity(prvKey), | |
) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("This node: ", host.ID().Pretty(), " ", host.Addrs()) | |
_, err = dht.New(ctx, host) | |
if err != nil { | |
panic(err) | |
} | |
select {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment