func NewHostNode(ctx context.Context, options HostNodeOptions) (*HostNode, error) {
	ps := pstoremem.NewPeerstore()

	h, err := libp2p.New(
		ctx,
		libp2p.ListenAddrs(options.ListenAddresses...),
		libp2p.Identity(options.PrivateKey),
		libp2p.EnableRelay(),
		libp2p.Peerstore(ps),
	)

	if err != nil {
		return nil, err
	}

	addrs, err := peer.AddrInfoToP2pAddrs(&peer.AddrInfo{
		ID:    h.ID(),
		Addrs: options.ListenAddresses,
	})
	if err != nil {
		return nil, err
	}

	for _, a := range addrs {
		logrus.WithField("addr", a).Info("binding to address")
	}

	// setup gossip sub protocol
	g, err := pubsub.NewGossipSub(ctx, h)
	if err != nil {
		return nil, err
	}

	hostNode := &HostNode{
		privateKey:        options.PrivateKey,
		host:              h,
		gossipSub:         g,
		ctx:               ctx,
		timeoutInterval:   timeoutInterval,
		heartbeatInterval: heartbeatInterval,
	}

	discovery, err := NewConnectionManager(ctx, hostNode, options.ConnManagerOptions)
	if err != nil {
		return nil, err
	}
	hostNode.discovery = discovery

	h.Network().Notify(discovery)

	return hostNode, nil
}
// NewHostNode creates a host node
NewHostNode creates a host node
// NewHostNode creates a host node
func NewHostNode(ctx context.Context, options HostNodeOptions) (*HostNode, error) {
	ps := pstoremem.NewPeerstore()
	h, err := libp2p.New(
		ctx,
		libp2p.ListenAddrs(options.ListenAddresses...),
		libp2p.Identity(options.PrivateKey),
		libp2p.EnableRelay(),
		libp2p.Peerstore(ps),
	)
	if err != nil {
		return nil, err
	}
	addrs, err := peer.AddrInfoToP2pAddrs(&peer.AddrInfo{
		ID:    h.ID(),
		Addrs: options.ListenAddresses,
	})
	if err != nil {
		return nil, err
	}
	for _, a := range addrs {
		logrus.WithField("addr", a).Info("binding to address")
	}
	g, err := pubsub.NewGossipSub(ctx, h)
	if err != nil {
		return nil, err
	}
	hostNode := &HostNode{
		privateKey:        options.PrivateKey,
		host:              h,
		gossipSub:         g,
		ctx:               ctx,
		timeoutInterval:   timeoutInterval,
		heartbeatInterval: heartbeatInterval,
	}
	discovery, err := NewConnectionManager(ctx, hostNode, options.ConnManagerOptions)
	if err != nil {
		return nil, err
	}
	hostNode.discovery = discovery
	h.Network().Notify(discovery)
	return hostNode, nil
}
func NewHostNode ( ctx context . Context , options HostNodeOptions ) ( * HostNode , error ) { ps := pstoremem . NewPeerstore ( ) h , err := libp2p . New ( ctx , libp2p . ListenAddrs ( options . ListenAddresses ... ) , libp2p . Identity ( options . PrivateKey ) , libp2p . EnableRelay ( ) , libp2p . Peerstore ( ps ) , ) if err != nil { return nil , err } addrs , err := peer . AddrInfoToP2pAddrs ( & peer . AddrInfo { ID : h . ID ( ) , Addrs : options . ListenAddresses , } ) if err != nil { return nil , err } for _ , a := range addrs { logrus . WithField ( " " , a ) . Info ( " " ) } g , err := pubsub . NewGossipSub ( ctx , h ) if err != nil { return nil , err } hostNode := & HostNode { privateKey : options . PrivateKey , host : h , gossipSub : g , ctx : ctx , timeoutInterval : timeoutInterval , heartbeatInterval : heartbeatInterval , } discovery , err := NewConnectionManager ( ctx , hostNode , options . ConnManagerOptions ) if err != nil { return nil , err } hostNode . discovery = discovery h . Network ( ) . Notify ( discovery ) return hostNode , nil }
NewHostNode creates a host node
NewHostNode creates a host node
// setup gossip sub protocol