@@ -18,12 +18,8 @@ import (
18
18
net "github.com/libp2p/go-libp2p-net"
19
19
peer "github.com/libp2p/go-libp2p-peer"
20
20
pstore "github.com/libp2p/go-libp2p-peerstore"
21
- swarm "github.com/libp2p/go-libp2p-swarm"
22
- bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
23
21
ma "github.com/multiformats/go-multiaddr"
24
22
gologging "github.com/whyrusleeping/go-logging"
25
- msmux "github.com/whyrusleeping/go-smux-multistream"
26
- yamux "github.com/whyrusleeping/go-smux-yamux"
27
23
)
28
24
29
25
// makeBasicHost creates a LibP2P host with a random peer ID listening on the
@@ -42,37 +38,21 @@ func makeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error
42
38
43
39
// Generate a key pair for this host. We will use it at least
44
40
// to obtain a valid host ID.
45
- priv , pub , err := crypto .GenerateKeyPairWithReader (crypto .RSA , 2048 , r )
41
+ priv , _ , err := crypto .GenerateKeyPairWithReader (crypto .RSA , 2048 , r )
46
42
if err != nil {
47
43
return nil , err
48
44
}
49
45
50
- // Obtain Peer ID from public key
51
- pid , err := peer .IDFromPublicKey (pub )
52
- if err != nil {
53
- return nil , err
54
- }
55
-
56
- // Create a multiaddress
57
- addr , err := ma .NewMultiaddr (fmt .Sprintf ("/ip4/127.0.0.1/tcp/%d" , listenPort ))
58
-
59
- if err != nil {
60
- return nil , err
46
+ opts := []libp2p.Option {
47
+ libp2p .ListenAddrStrings (fmt .Sprintf ("/ip4/127.0.0.1/tcp/%d" , listenPort )),
48
+ libp2p .WithPeerKey (priv ),
61
49
}
62
50
63
- // Create a peerstore
64
- ps := pstore .NewPeerstore ()
65
-
66
- // If using secio, we add the keys to the peerstore
67
- // for this peer ID.
68
- if secio {
69
- ps .AddPrivKey (pid , priv )
70
- ps .AddPubKey (pid , pub )
51
+ if ! secio {
52
+ opts = append (opts , libp2p .NoSecio )
71
53
}
72
54
73
- basicHost , err := libp2p .NewWithCfg (ctx , & libp2p.Config {
74
- ListenAddrs : []ma.Multiaddr {addr },
75
- })
55
+ basicHost , err := libp2p .New (context .Background (), opts ... )
76
56
if err != nil {
77
57
return nil , err
78
58
}
@@ -82,6 +62,7 @@ func makeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error
82
62
83
63
// Now we can build a full multiaddress to reach this host
84
64
// by encapsulating both addresses:
65
+ addr := basicHost .Addrs ()[0 ]
85
66
fullAddr := addr .Encapsulate (hostAddr )
86
67
log .Printf ("I am %s\n " , fullAddr )
87
68
if secio {
0 commit comments