-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock.go
48 lines (41 loc) · 1.03 KB
/
mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package mocknet
import (
logging "github.com/ipfs/go-log/v2"
)
var log = logging.Logger("mocknet")
// WithNPeers constructs a Mocknet with N peers.
func WithNPeers(n int) (Mocknet, error) {
m := New()
for i := 0; i < n; i++ {
if _, err := m.GenPeer(); err != nil {
return nil, err
}
}
return m, nil
}
// FullMeshLinked constructs a Mocknet with full mesh of Links.
// This means that all the peers **can** connect to each other
// (not that they already are connected. you can use m.ConnectAll())
func FullMeshLinked(n int) (Mocknet, error) {
m, err := WithNPeers(n)
if err != nil {
return nil, err
}
if err := m.LinkAll(); err != nil {
return nil, err
}
return m, nil
}
// FullMeshConnected constructs a Mocknet with full mesh of Connections.
// This means that all the peers have dialed and are ready to talk to
// each other.
func FullMeshConnected(n int) (Mocknet, error) {
m, err := FullMeshLinked(n)
if err != nil {
return nil, err
}
if err := m.ConnectAllButSelf(); err != nil {
return nil, err
}
return m, nil
}