Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a basichost, not a blankhost when constructing autonat #1257

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/libp2p/go-libp2p/p2p/protocol/holepunch"

autonat "github.com/libp2p/go-libp2p-autonat"
blankhost "github.com/libp2p/go-libp2p-blankhost"
discovery "github.com/libp2p/go-libp2p-discovery"
swarm "github.com/libp2p/go-libp2p-swarm"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
Expand Down Expand Up @@ -307,12 +306,16 @@ func (cfg *Config) NewNode() (host.Host, error) {
Peerstore: ps,
}

dialer, err := autoNatCfg.makeSwarm()
dialerSwarm, err := autoNatCfg.makeSwarm()
if err != nil {
h.Close()
return nil, err
}
dialerHost, err := bhost.NewHost(dialerSwarm, &bhost.HostOpts{DisableIdentify: true})
if err != nil {
h.Close()
return nil, err
}
dialerHost := blankhost.NewBlankHost(dialer)
if err := autoNatCfg.addTransports(dialerHost); err != nil {
dialerHost.Close()
h.Close()
Expand Down
22 changes: 14 additions & 8 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ type HostOpts struct {
// ConnManager is a libp2p connection manager
ConnManager connmgr.ConnManager

// DisableIdentify indicates whether to instantiate the identify service
DisableIdentify bool

// EnablePing indicates whether to instantiate the ping service
EnablePing bool

Expand Down Expand Up @@ -219,14 +222,17 @@ func NewHost(n network.Network, opts *HostOpts) (*BasicHost, error) {
h.mux = opts.MultistreamMuxer
}

// we can't set this as a default above because it depends on the *BasicHost.
if h.disableSignedPeerRecord {
h.ids, err = identify.NewIDService(h, identify.UserAgent(opts.UserAgent), identify.DisableSignedPeerRecord())
} else {
h.ids, err = identify.NewIDService(h, identify.UserAgent(opts.UserAgent))
}
if err != nil {
return nil, fmt.Errorf("failed to create Identify service: %s", err)
if !opts.DisableIdentify {
var err error
// we can't set this as a default above because it depends on the *BasicHost.
if h.disableSignedPeerRecord {
h.ids, err = identify.NewIDService(h, identify.UserAgent(opts.UserAgent), identify.DisableSignedPeerRecord())
} else {
h.ids, err = identify.NewIDService(h, identify.UserAgent(opts.UserAgent))
}
if err != nil {
return nil, fmt.Errorf("failed to create Identify service: %s", err)
}
}

if opts.EnableHolePunching {
Expand Down