Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit 19f9651

Browse files
committed
Changes to createLibp2pHost function
1 parent 4fbc28f commit 19f9651

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

forwarder.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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

159160
func 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

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/atotto/clipboard v0.1.2 // indirect
88
github.com/huandu/xstrings v1.3.2 // indirect
99
github.com/libp2p/go-libp2p v0.10.3
10+
github.com/libp2p/go-libp2p-circuit v0.3.1
1011
github.com/libp2p/go-libp2p-connmgr v0.2.4
1112
github.com/libp2p/go-libp2p-core v0.6.1
1213
github.com/libp2p/go-libp2p-kad-dht v0.8.3

0 commit comments

Comments
 (0)