|
|
@ -33,6 +33,7 @@ type mocknet struct { |
|
|
|
linkDefaults LinkOptions |
|
|
|
|
|
|
|
proc goprocess.Process // for Context closing
|
|
|
|
ctx context.Context |
|
|
|
sync.RWMutex |
|
|
|
} |
|
|
|
|
|
|
@ -42,6 +43,7 @@ func New(ctx context.Context) Mocknet { |
|
|
|
hosts: map[peer.ID]*bhost.BasicHost{}, |
|
|
|
links: map[peer.ID]map[peer.ID]map[*link]struct{}{}, |
|
|
|
proc: goprocessctx.WithContext(ctx), |
|
|
|
ctx: ctx, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -62,7 +64,7 @@ func (mn *mocknet) GenPeer() (host.Host, error) { |
|
|
|
} |
|
|
|
|
|
|
|
func (mn *mocknet) AddPeer(k ic.PrivKey, a ma.Multiaddr) (host.Host, error) { |
|
|
|
n, err := newPeernet(mn.cg.Context(), mn, k, a) |
|
|
|
n, err := newPeernet(mn.ctx, mn, k, a) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@ -70,7 +72,7 @@ func (mn *mocknet) AddPeer(k ic.PrivKey, a ma.Multiaddr) (host.Host, error) { |
|
|
|
h := bhost.New(n) |
|
|
|
log.Debugf("mocknet added listen addr for peer: %s -- %s", n.LocalPeer(), a) |
|
|
|
|
|
|
|
mn.cg.AddChild(n.cg) |
|
|
|
mn.proc.AddChild(n.proc) |
|
|
|
|
|
|
|
mn.Lock() |
|
|
|
mn.nets[n.peer] = n |
|
|
@ -298,11 +300,11 @@ func (mn *mocknet) ConnectAll() error { |
|
|
|
} |
|
|
|
|
|
|
|
func (mn *mocknet) ConnectPeers(a, b peer.ID) (inet.Conn, error) { |
|
|
|
return mn.Net(a).DialPeer(mn.cg.Context(), b) |
|
|
|
return mn.Net(a).DialPeer(mn.ctx, b) |
|
|
|
} |
|
|
|
|
|
|
|
func (mn *mocknet) ConnectNets(a, b inet.Network) (inet.Conn, error) { |
|
|
|
return a.DialPeer(mn.cg.Context(), b.LocalPeer()) |
|
|
|
return a.DialPeer(mn.ctx, b.LocalPeer()) |
|
|
|
} |
|
|
|
|
|
|
|
func (mn *mocknet) DisconnectPeers(p1, p2 peer.ID) error { |
|
|
|