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 { ...@@ -25,6 +25,7 @@ type Mocknet interface {
// AddPeer adds an existing peer. we need both a privkey and addr. // AddPeer adds an existing peer. we need both a privkey and addr.
// ID is derived from PrivKey // ID is derived from PrivKey
AddPeer(ic.PrivKey, ma.Multiaddr) (host.Host, error) AddPeer(ic.PrivKey, ma.Multiaddr) (host.Host, error)
AddPeerWithPeerstore(peer.ID, peer.Peerstore) (host.Host, error)
// retrieve things (with randomized iteration order) // retrieve things (with randomized iteration order)
Peers() []peer.ID Peers() []peer.ID
......
...@@ -64,13 +64,26 @@ func (mn *mocknet) GenPeer() (host.Host, error) { ...@@ -64,13 +64,26 @@ func (mn *mocknet) GenPeer() (host.Host, error) {
} }
func (mn *mocknet) AddPeer(k ic.PrivKey, a ma.Multiaddr) (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 { if err != nil {
return nil, err return nil, err
} }
h := bhost.New(n) h := bhost.New(n)
log.Debugf("mocknet added listen addr for peer: %s -- %s", n.LocalPeer(), a)
mn.proc.AddChild(n.proc) mn.proc.AddChild(n.proc)
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"math/rand" "math/rand"
"sync" "sync"
ic "github.com/ipfs/go-ipfs/p2p/crypto"
inet "github.com/ipfs/go-ipfs/p2p/net" inet "github.com/ipfs/go-ipfs/p2p/net"
peer "github.com/ipfs/go-ipfs/p2p/peer" peer "github.com/ipfs/go-ipfs/p2p/peer"
...@@ -40,19 +39,7 @@ type peernet struct { ...@@ -40,19 +39,7 @@ type peernet struct {
} }
// newPeernet constructs a new peernet // newPeernet constructs a new peernet
func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey, func newPeernet(ctx context.Context, m *mocknet, p peer.ID, ps peer.Peerstore) (*peernet, error) {
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())
n := &peernet{ n := &peernet{
mocknet: m, 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