replace nodebuilder with a nicer interface
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> use NewNode instead of NewIPFSNode in most of the codebase License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> make mocknet work with node constructor better License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> finish cleanup of old construction method License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> blockservice.New doesnt return an error anymore License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> break up node construction into separate function License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> add error case to default filling on node constructor License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
parent
fc3c6838fb
commit
0f3e3fe264
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue