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

introspection: reformulate host options. #791

Closed
wants to merge 1 commit 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
26 changes: 21 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/introspect"
"github.com/libp2p/go-libp2p-core/introspection"
"github.com/libp2p/go-libp2p-core/metrics"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
Expand Down Expand Up @@ -40,6 +40,10 @@ type NATManagerC func(network.Network) bhost.NATManager

type RoutingC func(host.Host) (routing.PeerRouting, error)

// IntrospectionEndpointC is a type that represents an introspection.Endpoint
// constructor.
type IntrospectionEndpointC func(introspection.Introspector) (introspection.Endpoint, error)

// Config describes a set of settings for a libp2p node
//
// This is *not* a stable interface. Use the options defined in the root
Expand Down Expand Up @@ -79,7 +83,8 @@ type Config struct {
EnableAutoRelay bool
StaticRelays []peer.AddrInfo

Introspector introspect.Introspector
Introspector introspection.Introspector
IntrospectionEndpoint IntrospectionEndpointC
}

// NewNode constructs a new libp2p Host from the Config.
Expand Down Expand Up @@ -123,17 +128,28 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
swrm.Filters = cfg.Filters
}

h, err := bhost.NewHost(ctx, swrm, &bhost.HostOpts{
opts := &bhost.HostOpts{
ConnManager: cfg.ConnManager,
AddrsFactory: cfg.AddrsFactory,
NATManager: cfg.NATManager,
EnablePing: !cfg.DisablePing,
UserAgent: cfg.UserAgent,
Introspector: cfg.Introspector,
})
}

if cfg.Introspector != nil && cfg.IntrospectionEndpoint != nil {
opts.IntrospectionEndpoint, err = cfg.IntrospectionEndpoint(cfg.Introspector)
if err != nil {
swrm.Close()
return nil, fmt.Errorf("failed while starting introspection endpoint: %w", err)
}
}

h, err := bhost.NewHost(ctx, swrm, opts)

if err != nil {
swrm.Close()
_ = swrm.Close()
_ = opts.IntrospectionEndpoint.Close()
return nil, err
}

Expand Down
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ module github.com/libp2p/go-libp2p

require (
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.2
github.com/gorilla/websocket v1.4.1
github.com/ipfs/go-cid v0.0.4
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ipfs-util v0.0.1
github.com/ipfs/go-log v0.0.1
github.com/ipfs/go-log v1.0.1
github.com/jbenet/go-cienv v0.1.0
github.com/jbenet/goprocess v0.1.3
github.com/libp2p/go-conn-security-multistream v0.1.0
github.com/libp2p/go-eventbus v0.1.0
github.com/libp2p/go-libp2p-autonat v0.1.1
github.com/libp2p/go-libp2p-blankhost v0.1.4
github.com/libp2p/go-libp2p-circuit v0.1.4
github.com/libp2p/go-libp2p-core v0.3.0
github.com/libp2p/go-libp2p-core v0.3.1-0.20200207145311-a52ff097a8de
github.com/libp2p/go-libp2p-discovery v0.2.0
github.com/libp2p/go-libp2p-introspector v0.0.3
github.com/libp2p/go-libp2p-loggables v0.1.0
github.com/libp2p/go-libp2p-mplex v0.2.1
github.com/libp2p/go-libp2p-nat v0.0.5
Expand All @@ -34,7 +37,10 @@ require (
github.com/multiformats/go-multiaddr-dns v0.2.0
github.com/multiformats/go-multiaddr-net v0.1.1
github.com/multiformats/go-multistream v0.1.0
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 // indirect
)

Expand Down
Loading