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

Commit

Permalink
Changes to createLibp2pHost function
Browse files Browse the repository at this point in the history
  • Loading branch information
nickname76 committed Aug 10, 2020
1 parent 4fbc28f commit 19f9651
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/libp2p/go-libp2p"
relay "github.com/libp2p/go-libp2p-circuit"
connmgr "github.com/libp2p/go-libp2p-connmgr"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/host"
Expand Down Expand Up @@ -157,7 +158,9 @@ func loadUserPrivKey() (priv crypto.PrivKey, err error) {
}

func createLibp2pHost(ctx context.Context, priv crypto.PrivKey) (host.Host, error) {
return libp2p.New(ctx,
var d *dht.IpfsDHT

h, err := libp2p.New(ctx,
// Use the keypair
libp2p.Identity(priv),
// Multiple listen addresses
Expand All @@ -174,6 +177,9 @@ func createLibp2pHost(ctx context.Context, priv crypto.PrivKey) (host.Host, erro
libp2p.Transport(libp2pquic.NewTransport),
// support any other default transports (TCP)
libp2p.DefaultTransports,

libp2p.DefaultMuxers,

// Let's prevent our peer from having too many
// connections by attaching a connection manager.
libp2p.ConnectionManager(connmgr.NewConnManager(
Expand All @@ -186,15 +192,28 @@ func createLibp2pHost(ctx context.Context, priv crypto.PrivKey) (host.Host, erro
libp2p.NATPortMap(),
// Let this host use the DHT to find other hosts
libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
return dht.New(ctx, h)
var err error
d, err = dht.New(ctx, h, dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...))
return d, err
}),
// Let this host use relays and advertise itself on relays if
// it finds it is behind NAT.
libp2p.EnableAutoRelay(),
libp2p.EnableRelay(relay.OptActive),
libp2p.DefaultStaticRelays(),

libp2p.DefaultPeerstore,
)
if err != nil {
return nil, err
}

err = d.Bootstrap(ctx)
if err != nil {
return nil, err
}

return h, err
}

// ID returns id of Forwarder
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/atotto/clipboard v0.1.2 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/libp2p/go-libp2p v0.10.3
github.com/libp2p/go-libp2p-circuit v0.3.1
github.com/libp2p/go-libp2p-connmgr v0.2.4
github.com/libp2p/go-libp2p-core v0.6.1
github.com/libp2p/go-libp2p-kad-dht v0.8.3
Expand Down

0 comments on commit 19f9651

Please sign in to comment.