@@ -2,25 +2,20 @@ package coremock
2
2
3
3
import (
4
4
"encoding/base64"
5
+ "net"
5
6
6
7
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
7
8
syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
8
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
9
10
10
- "github.com/ipfs/go-ipfs/blocks/blockstore"
11
- blockservice "github.com/ipfs/go-ipfs/blockservice"
12
11
commands "github.com/ipfs/go-ipfs/commands"
13
12
core "github.com/ipfs/go-ipfs/core"
14
- bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
15
- bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
16
- mdag "github.com/ipfs/go-ipfs/merkledag"
17
- nsys "github.com/ipfs/go-ipfs/namesys"
13
+ metrics "github.com/ipfs/go-ipfs/metrics"
14
+ host "github.com/ipfs/go-ipfs/p2p/host"
18
15
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
19
- path "github.com/ipfs/go-ipfs/path"
20
- pin "github.com/ipfs/go-ipfs/pin"
16
+ peer "github.com/ipfs/go-ipfs/p2p/peer"
21
17
"github.com/ipfs/go-ipfs/repo"
22
18
config "github.com/ipfs/go-ipfs/repo/config"
23
- dht "github.com/ipfs/go-ipfs/routing/dht"
24
19
ds2 "github.com/ipfs/go-ipfs/util/datastore2"
25
20
testutil "github.com/ipfs/go-ipfs/util/testutil"
26
21
)
@@ -48,55 +43,34 @@ func NewMockNodeOnNet(ctx context.Context, mn mocknet.Mocknet) (*core.IpfsNode,
48
43
return nil , err
49
44
}
50
45
46
+ a := testutil .RandLocalTCPAddress ()
51
47
c := config.Config {
52
48
Identity : config.Identity {
53
- PeerID : p .String (),
49
+ PeerID : p .Pretty (),
54
50
PrivKey : base64 .StdEncoding .EncodeToString (pkb ),
55
51
},
52
+ Addresses : config.Addresses {
53
+ Swarm : []string {
54
+ a .String (),
55
+ },
56
+ },
56
57
}
57
58
58
59
r := & repo.Mock {
59
60
C : c ,
60
61
D : ds2 .CloserWrap (syncds .MutexWrap (datastore .NewMapDatastore ())),
61
62
}
62
- nd , err := core .NewNode (ctx , & core.BuildCfg {
63
- Repo : r ,
63
+ return core .NewNode (ctx , & core.BuildCfg {
64
+ Online : true ,
65
+ Repo : r ,
66
+ Host : MockHostOption (mn ),
64
67
})
65
- if err != nil {
66
- return nil , err
67
- }
68
+ }
68
69
69
- nd . PeerHost , err = mn . AddPeer ( ident . PrivateKey (), ident . Address ())
70
- if err != nil {
71
- return nil , err
70
+ func MockHostOption ( mn mocknet. Mocknet ) core. HostOption {
71
+ return func ( ctx context. Context , id peer. ID , ps peer. Peerstore , bwr metrics. Reporter , fs [] * net. IPNet ) (host. Host , error ) {
72
+ return mn . AddPeerWithPeerstore ( id , ps )
72
73
}
73
-
74
- nd .Peerstore = nd .PeerHost .Peerstore ()
75
- nd .Peerstore .AddPrivKey (p , ident .PrivateKey ())
76
- nd .Peerstore .AddPubKey (p , ident .PublicKey ())
77
- nd .Identity = p
78
-
79
- // Routing
80
- nd .Routing = dht .NewDHT (ctx , nd .PeerHost , nd .Repo .Datastore ())
81
-
82
- // Bitswap
83
- bstore := blockstore .NewBlockstore (nd .Repo .Datastore ())
84
-
85
- bsn := bsnet .NewFromIpfsHost (nd .PeerHost , nd .Routing )
86
- nd .Exchange = bitswap .New (ctx , p , bsn , bstore , true )
87
-
88
- bserv := blockservice .New (bstore , nd .Exchange )
89
-
90
- nd .DAG = mdag .NewDAGService (bserv )
91
- nd .Pinning = pin .NewPinner (nd .Repo .Datastore (), nd .DAG )
92
-
93
- // Namespace resolver
94
- nd .Namesys = nsys .NewNameSystem (nd .Routing )
95
-
96
- // Path resolver
97
- nd .Resolver = & path.Resolver {DAG : nd .DAG }
98
-
99
- return nd , nil
100
74
}
101
75
102
76
func MockCmdsCtx () (commands.Context , error ) {
0 commit comments