Commit 0f3e3fe2 authored by Jeromy's avatar Jeromy
Browse files

replace nodebuilder with a nicer interface



License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>

use NewNode instead of NewIPFSNode in most of the codebase

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>

make mocknet work with node constructor better

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>

finish cleanup of old construction method

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>

blockservice.New doesnt return an error anymore

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>

break up node construction into separate function

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>

add error case to default filling on node constructor

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent fc3c6838
......@@ -25,6 +25,7 @@ type Mocknet interface {
// AddPeer adds an existing peer. we need both a privkey and addr.
// ID is derived from PrivKey
AddPeer(ic.PrivKey, ma.Multiaddr) (host.Host, error)
AddPeerWithPeerstore(peer.ID, peer.Peerstore) (host.Host, error)
// retrieve things (with randomized iteration order)
Peers() []peer.ID
......
......@@ -64,13 +64,26 @@ func (mn *mocknet) GenPeer() (host.Host, error) {
}
func (mn *mocknet) AddPeer(k ic.PrivKey, a ma.Multiaddr) (host.Host, error) {
n, err := newPeernet(mn.ctx, mn, k, a)
p, err := peer.IDFromPublicKey(k.GetPublic())
if err != nil {
return nil, err
}
ps := peer.NewPeerstore()
ps.AddAddr(p, a, peer.PermanentAddrTTL)
ps.AddPrivKey(p, k)
ps.AddPubKey(p, k.GetPublic())
return mn.AddPeerWithPeerstore(p, ps)
}
func (mn *mocknet) AddPeerWithPeerstore(p peer.ID, ps peer.Peerstore) (host.Host, error) {
n, err := newPeernet(mn.ctx, mn, p, ps)
if err != nil {
return nil, err
}
h := bhost.New(n)
log.Debugf("mocknet added listen addr for peer: %s -- %s", n.LocalPeer(), a)
mn.proc.AddChild(n.proc)
......
......@@ -5,7 +5,6 @@ import (
"math/rand"
"sync"
ic "github.com/ipfs/go-ipfs/p2p/crypto"
inet "github.com/ipfs/go-ipfs/p2p/net"
peer "github.com/ipfs/go-ipfs/p2p/peer"
......@@ -40,19 +39,7 @@ type peernet struct {
}
// newPeernet constructs a new peernet
func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey,
a ma.Multiaddr) (*peernet, error) {
p, err := peer.IDFromPublicKey(k.GetPublic())
if err != nil {
return nil, err
}
// create our own entirely, so that peers knowledge doesn't get shared
ps := peer.NewPeerstore()
ps.AddAddr(p, a, peer.PermanentAddrTTL)
ps.AddPrivKey(p, k)
ps.AddPubKey(p, k.GetPublic())
func newPeernet(ctx context.Context, m *mocknet, p peer.ID, ps peer.Peerstore) (*peernet, error) {
n := &peernet{
mocknet: m,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment