99 "time"
1010
1111 "github.com/libp2p/go-libp2p"
12+ relay "github.com/libp2p/go-libp2p-circuit"
1213 connmgr "github.com/libp2p/go-libp2p-connmgr"
1314 "github.com/libp2p/go-libp2p-core/crypto"
1415 "github.com/libp2p/go-libp2p-core/host"
@@ -157,7 +158,9 @@ func loadUserPrivKey() (priv crypto.PrivKey, err error) {
157158}
158159
159160func createLibp2pHost (ctx context.Context , priv crypto.PrivKey ) (host.Host , error ) {
160- return libp2p .New (ctx ,
161+ var d * dht.IpfsDHT
162+
163+ h , err := libp2p .New (ctx ,
161164 // Use the keypair
162165 libp2p .Identity (priv ),
163166 // Multiple listen addresses
@@ -174,6 +177,9 @@ func createLibp2pHost(ctx context.Context, priv crypto.PrivKey) (host.Host, erro
174177 libp2p .Transport (libp2pquic .NewTransport ),
175178 // support any other default transports (TCP)
176179 libp2p .DefaultTransports ,
180+
181+ libp2p .DefaultMuxers ,
182+
177183 // Let's prevent our peer from having too many
178184 // connections by attaching a connection manager.
179185 libp2p .ConnectionManager (connmgr .NewConnManager (
@@ -186,15 +192,28 @@ func createLibp2pHost(ctx context.Context, priv crypto.PrivKey) (host.Host, erro
186192 libp2p .NATPortMap (),
187193 // Let this host use the DHT to find other hosts
188194 libp2p .Routing (func (h host.Host ) (routing.PeerRouting , error ) {
189- return dht .New (ctx , h )
195+ var err error
196+ d , err = dht .New (ctx , h , dht .BootstrapPeers (dht .GetDefaultBootstrapPeerAddrInfos ()... ))
197+ return d , err
190198 }),
191199 // Let this host use relays and advertise itself on relays if
192200 // it finds it is behind NAT.
193201 libp2p .EnableAutoRelay (),
202+ libp2p .EnableRelay (relay .OptActive ),
194203 libp2p .DefaultStaticRelays (),
195204
196205 libp2p .DefaultPeerstore ,
197206 )
207+ if err != nil {
208+ return nil , err
209+ }
210+
211+ err = d .Bootstrap (ctx )
212+ if err != nil {
213+ return nil , err
214+ }
215+
216+ return h , err
198217}
199218
200219// ID returns id of Forwarder
0 commit comments