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

*basic.BasicHost does not implement host.Host #303

Closed
darmie opened this issue Mar 21, 2018 · 1 comment
Closed

*basic.BasicHost does not implement host.Host #303

darmie opened this issue Mar 21, 2018 · 1 comment

Comments

@darmie
Copy link

darmie commented Mar 21, 2018

I am having a type error while following the examples:

package main

// package host

import (
	"crypto/rand"

	crypto "github.com/libp2p/go-libp2p-crypto"
	peer "github.com/libp2p/go-libp2p-peer"
	pstore "github.com/libp2p/go-libp2p-peerstore"

	"context"

	host "github.com/libp2p/go-libp2p-host"
	ma "github.com/multiformats/go-multiaddr"

	swarm "github.com/libp2p/go-libp2p-swarm"
	bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
)

func genHost() host.Host {
	// Generate an identity keypair using go's cryptographic randomness source
	priv, pub, err := crypto.GenerateEd25519Key(rand.Reader)
	if err != nil {
		panic(err)
	}

	// A peers ID is the hash of its public key
	pid, err := peer.IDFromPublicKey(pub)
	if err != nil {
		panic(err)
	}

	// We've created the identity, now we need to store it.
	// A peerstore holds information about peers, including your own
	ps := pstore.NewPeerstore()
	ps.AddPrivKey(pid, priv)
	ps.AddPubKey(pid, pub)

	// Make address

	maddr, err := ma.NewMultiaddr("/ip4/0.0.0.0/tcp/9000")
	if err != nil {
		panic(err)
	}

	// Make a context to govern the lifespan of the swarm
	ctx := context.Background()

	// Put all this together
	netw, err := swarm.NewNetwork(ctx, []ma.Multiaddr{maddr}, pid, ps, nil)
	if err != nil {
		panic(err)
	}

	return bhost.New(netw)

	// //host := libp2p.

	// fmt.Printf("my address: %s\n", netw.ListenAddresses()[0].String())

	// hostID := netw.LocalPeer().Loggable()["peerID"]

	// fmt.Printf("my host ID: %s\n", hostID)
	// fmt.Println("is equal? ", pid.Loggable()["peerID"] == hostID)
}

screen shot 2018-03-21 at 11 51 25 am

How do I fix this?

@darmie darmie closed this as completed Mar 21, 2018
@darmie
Copy link
Author

darmie commented Mar 21, 2018

Here's how to fix it:

  1. cd $HOME/go/src/github.com/libp2p/go-libp2p
  2. copy the content of gxDependencies in package.json
  3. run gx init in directory where your project is
  4. open package.json and paste the dependencies from previous step in the gxDependencies

marten-seemann added a commit that referenced this issue Apr 21, 2022
stop using the deprecated libp2p/go-maddr-filter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant