Esempio n. 1
0
func makePeer(addr ma.Multiaddr) peer.Peer {
	sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
	if err != nil {
		panic(err)
	}
	p, err := peer.WithKeyPair(sk, pk)
	if err != nil {
		panic(err)
	}
	p.AddAddress(addr)
	return p
}
Esempio n. 2
0
func getPeer(tb testing.TB) peer.Peer {
	privk, pubk, err := ci.GenerateKeyPair(ci.RSA, 1024)
	if err != nil {
		tb.Fatal(err)
	}

	p, err := peer.WithKeyPair(privk, pubk)
	if err != nil {
		tb.Fatal(err)
	}

	return p
}
Esempio n. 3
0
// NewMockNode constructs an IpfsNode for use in tests.
func NewMockNode() (*IpfsNode, error) {
	nd := new(IpfsNode)

	// Generate Identity
	sk, pk, err := ci.GenerateKeyPair(ci.RSA, 1024)
	if err != nil {
		return nil, err
	}

	p, err := peer.WithKeyPair(sk, pk)
	if err != nil {
		return nil, err
	}

	nd.Peerstore = peer.NewPeerstore()
	nd.Identity, err = nd.Peerstore.Add(p)
	if err != nil {
		return nil, err
	}

	// Temp Datastore
	dstore := ds.NewMapDatastore()
	nd.Datastore = util.CloserWrap(syncds.MutexWrap(dstore))

	// Routing
	dht := mdht.NewMockRouter(nd.Identity, nd.Datastore)
	nd.Routing = dht

	// Bitswap
	//??

	bserv, err := bs.NewBlockService(nd.Datastore, nil)
	if err != nil {
		return nil, err
	}

	nd.DAG = mdag.NewDAGService(bserv)

	// Namespace resolver
	nd.Namesys = nsys.NewNameSystem(dht)

	// Path resolver
	nd.Resolver = &path.Resolver{DAG: nd.DAG}

	return nd, nil
}
Esempio n. 4
0
func setupPeer(t *testing.T, addr string) peer.Peer {
	tcp, err := ma.NewMultiaddr(addr)
	if err != nil {
		t.Fatal(err)
	}

	sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
	if err != nil {
		t.Fatal(err)
	}

	p, err := peer.WithKeyPair(sk, pk)
	if err != nil {
		t.Fatal(err)
	}
	p.AddAddress(tcp)
	return p
}
Esempio n. 5
0
func setupPeer(addr string) (peer.Peer, error) {
	tcp, err := ma.NewMultiaddr(addr)
	if err != nil {
		return nil, err
	}

	sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
	if err != nil {
		return nil, err
	}

	p, err := peer.WithKeyPair(sk, pk)
	if err != nil {
		return nil, err
	}
	p.AddAddress(tcp)
	return p, nil
}
Esempio n. 6
0
func TestRoutingResolve(t *testing.T) {
	local := peer.WithIDString("testID")
	lds := ds.NewMapDatastore()
	d := mock.NewMockRouter(local, lds)

	resolver := NewRoutingResolver(d)
	publisher := NewRoutingPublisher(d)

	privk, pubk, err := ci.GenerateKeyPair(ci.RSA, 512)
	if err != nil {
		t.Fatal(err)
	}

	err = publisher.Publish(privk, "Hello")
	if err == nil {
		t.Fatal("should have errored out when publishing a non-multihash val")
	}

	h := u.Key(u.Hash([]byte("Hello"))).Pretty()
	err = publisher.Publish(privk, h)
	if err != nil {
		t.Fatal(err)
	}

	pubkb, err := pubk.Bytes()
	if err != nil {
		t.Fatal(err)
	}

	pkhash := u.Hash(pubkb)
	res, err := resolver.Resolve(u.Key(pkhash).Pretty())
	if err != nil {
		t.Fatal(err)
	}

	if res != h {
		t.Fatal("Got back incorrect value.")
	}
}