Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 77c2340

Browse files
committedAug 18, 2015
finish cleanup of old construction method
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 2cd6ca0 commit 77c2340

8 files changed

+62
-198
lines changed
 

‎core/core.go

-55
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
2121
ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
2222
goprocess "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
23-
goprocessctx "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
2423
mamask "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter"
2524
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
2625
diag "github.com/ipfs/go-ipfs/diagnostics"
@@ -38,7 +37,6 @@ import (
3837

3938
routing "github.com/ipfs/go-ipfs/routing"
4039
dht "github.com/ipfs/go-ipfs/routing/dht"
41-
kb "github.com/ipfs/go-ipfs/routing/kbucket"
4240
nilrouting "github.com/ipfs/go-ipfs/routing/none"
4341
offroute "github.com/ipfs/go-ipfs/routing/offline"
4442

@@ -122,59 +120,6 @@ type Mounts struct {
122120
Ipns mount.Mount
123121
}
124122

125-
// DEPRECATED: use BuildCfg instead
126-
type ConfigOption func(ctx context.Context) (*IpfsNode, error)
127-
128-
// DEPRECATED: use NewNode instead
129-
func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
130-
node, err := option(ctx)
131-
if err != nil {
132-
return nil, err
133-
}
134-
135-
if node.ctx == nil {
136-
node.ctx = ctx
137-
}
138-
if node.proc == nil {
139-
node.proc = goprocessctx.WithContextAndTeardown(node.ctx, node.teardown)
140-
}
141-
142-
success := false // flip to true after all sub-system inits succeed
143-
defer func() {
144-
if !success {
145-
node.proc.Close()
146-
}
147-
}()
148-
149-
// Need to make sure it's perfectly clear 1) which variables are expected
150-
// to be initialized at this point, and 2) which variables will be
151-
// initialized after this point.
152-
153-
node.Blocks = bserv.New(node.Blockstore, node.Exchange)
154-
155-
if node.Peerstore == nil {
156-
node.Peerstore = peer.NewPeerstore()
157-
}
158-
node.DAG = merkledag.NewDAGService(node.Blocks)
159-
node.Pinning, err = pin.LoadPinner(node.Repo.Datastore(), node.DAG)
160-
if err != nil {
161-
node.Pinning = pin.NewPinner(node.Repo.Datastore(), node.DAG)
162-
}
163-
node.Resolver = &path.Resolver{DAG: node.DAG}
164-
165-
// Setup the mutable ipns filesystem structure
166-
if node.OnlineMode() {
167-
fs, err := ipnsfs.NewFilesystem(ctx, node.DAG, node.Namesys, node.Pinning, node.PrivateKey)
168-
if err != nil && err != kb.ErrLookupFailure {
169-
return nil, err
170-
}
171-
node.IpnsFs = fs
172-
}
173-
174-
success = true
175-
return node, nil
176-
}
177-
178123
func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption RoutingOption, hostOption HostOption, do DiscoveryOption) error {
179124

180125
if n.PeerHost != nil { // already online.

‎core/mock/mock.go

+1-38
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package coremock
22

33
import (
4-
"encoding/base64"
54
"net"
65

76
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
@@ -25,45 +24,9 @@ func NewMockNode() (*core.IpfsNode, error) {
2524
ctx := context.Background()
2625

2726
// effectively offline, only peer in its network
28-
return NewMockNodeOnNet(ctx, mocknet.New(ctx))
29-
}
30-
31-
// TODO: shrink this function as much as possible, moving logic into NewNode
32-
func NewMockNodeOnNet(ctx context.Context, mn mocknet.Mocknet) (*core.IpfsNode, error) {
33-
34-
// Generate Identity
35-
ident, err := testutil.RandIdentity()
36-
if err != nil {
37-
return nil, err
38-
}
39-
p := ident.ID()
40-
41-
pkb, err := ident.PrivateKey().Bytes()
42-
if err != nil {
43-
return nil, err
44-
}
45-
46-
a := testutil.RandLocalTCPAddress()
47-
c := config.Config{
48-
Identity: config.Identity{
49-
PeerID: p.Pretty(),
50-
PrivKey: base64.StdEncoding.EncodeToString(pkb),
51-
},
52-
Addresses: config.Addresses{
53-
Swarm: []string{
54-
a.String(),
55-
},
56-
},
57-
}
58-
59-
r := &repo.Mock{
60-
C: c,
61-
D: ds2.CloserWrap(syncds.MutexWrap(datastore.NewMapDatastore())),
62-
}
6327
return core.NewNode(ctx, &core.BuildCfg{
6428
Online: true,
65-
Repo: r,
66-
Host: MockHostOption(mn),
29+
Host: MockHostOption(mocknet.New(ctx)),
6730
})
6831
}
6932

‎test/integration/addcat_test.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ import (
1818
mock "github.com/ipfs/go-ipfs/core/mock"
1919
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
2020
"github.com/ipfs/go-ipfs/p2p/peer"
21+
eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
2122
"github.com/ipfs/go-ipfs/thirdparty/unit"
2223
testutil "github.com/ipfs/go-ipfs/util/testutil"
2324
)
2425

26+
var log = eventlog.Logger("epictest")
27+
2528
const kSeed = 1
2629

2730
func Test1KBInstantaneous(t *testing.T) {
@@ -97,13 +100,19 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
97100
Bandwidth: math.MaxInt32,
98101
})
99102

100-
adder, err := mock.NewMockNodeOnNet(ctx, mn)
103+
adder, err := core.NewNode(ctx, &core.BuildCfg{
104+
Online: true,
105+
Host: mock.MockHostOption(mn),
106+
})
101107
if err != nil {
102108
return err
103109
}
104110
defer adder.Close()
105111

106-
catter, err := mock.NewMockNodeOnNet(ctx, mn)
112+
catter, err := core.NewNode(ctx, &core.BuildCfg{
113+
Online: true,
114+
Host: mock.MockHostOption(mn),
115+
})
107116
if err != nil {
108117
return err
109118
}

‎test/integration/bench_cat_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
4545
Bandwidth: math.MaxInt32,
4646
})
4747

48-
adder, err := mock.NewMockNodeOnNet(ctx, mn)
48+
adder, err := core.NewNode(ctx, &core.BuildCfg{
49+
Online: true,
50+
Host: mock.MockHostOption(mn),
51+
})
4952
if err != nil {
5053
return err
5154
}
5255
defer adder.Close()
5356

54-
catter, err := mock.NewMockNodeOnNet(ctx, mn)
57+
catter, err := core.NewNode(ctx, &core.BuildCfg{
58+
Online: true,
59+
Host: mock.MockHostOption(mn),
60+
})
5561
if err != nil {
5662
return err
5763
}

‎test/integration/bitswap_wo_routing_test.go

+10-17
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package integrationtest
22

33
import (
44
"bytes"
5-
"errors"
65
"testing"
7-
"time"
86

97
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
108
"github.com/ipfs/go-ipfs/blocks"
119
"github.com/ipfs/go-ipfs/core"
10+
"github.com/ipfs/go-ipfs/core/mock"
1211
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
13-
testutil "github.com/ipfs/go-ipfs/util/testutil"
1412
)
1513

1614
func TestBitswapWithoutRouting(t *testing.T) {
@@ -19,29 +17,24 @@ func TestBitswapWithoutRouting(t *testing.T) {
1917
const numPeers = 4
2018

2119
// create network
22-
mn, err := mocknet.FullMeshLinked(ctx, numPeers)
23-
if err != nil {
24-
t.Fatal(err)
25-
}
26-
27-
peers := mn.Peers()
28-
if len(peers) < numPeers {
29-
t.Fatal(errors.New("test initialization error"))
30-
}
31-
32-
// set the routing latency to infinity.
33-
conf := testutil.LatencyConfig{RoutingLatency: (525600 * time.Minute)}
20+
mn := mocknet.New(ctx)
3421

3522
var nodes []*core.IpfsNode
36-
for _, p := range peers {
37-
n, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(p, mn.Host(p), conf, core.NilRouterOption)))
23+
for i := 0; i < numPeers; i++ {
24+
n, err := core.NewNode(ctx, &core.BuildCfg{
25+
Online: true,
26+
Host: coremock.MockHostOption(mn),
27+
Routing: core.NilRouterOption, // no routing
28+
})
3829
if err != nil {
3930
t.Fatal(err)
4031
}
4132
defer n.Close()
4233
nodes = append(nodes, n)
4334
}
4435

36+
mn.LinkAll()
37+
4538
// connect them
4639
for _, n1 := range nodes {
4740
for _, n2 := range nodes {

‎test/integration/core.go

-54
This file was deleted.

‎test/integration/grandcentral_test.go

+15-19
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
core "github.com/ipfs/go-ipfs/core"
1717
"github.com/ipfs/go-ipfs/core/corerouting"
1818
"github.com/ipfs/go-ipfs/core/coreunix"
19+
mock "github.com/ipfs/go-ipfs/core/mock"
1920
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
2021
"github.com/ipfs/go-ipfs/p2p/peer"
21-
"github.com/ipfs/go-ipfs/thirdparty/iter"
2222
"github.com/ipfs/go-ipfs/thirdparty/unit"
2323
ds2 "github.com/ipfs/go-ipfs/util/datastore2"
2424
testutil "github.com/ipfs/go-ipfs/util/testutil"
@@ -82,28 +82,21 @@ func InitializeSupernodeNetwork(
8282
conf testutil.LatencyConfig) ([]*core.IpfsNode, []*core.IpfsNode, error) {
8383

8484
// create network
85-
mn, err := mocknet.FullMeshLinked(ctx, numServers+numClients)
86-
if err != nil {
87-
return nil, nil, err
88-
}
85+
mn := mocknet.New(ctx)
8986

9087
mn.SetLinkDefaults(mocknet.LinkOptions{
9188
Latency: conf.NetworkLatency,
9289
Bandwidth: math.MaxInt32,
9390
})
9491

95-
peers := mn.Peers()
96-
if len(peers) < numServers+numClients {
97-
return nil, nil, errors.New("test initialization error")
98-
}
99-
clientPeers, serverPeers := peers[0:numClients], peers[numClients:]
100-
10192
routingDatastore := ds2.CloserWrap(syncds.MutexWrap(datastore.NewMapDatastore()))
10293
var servers []*core.IpfsNode
103-
for i := range iter.N(numServers) {
104-
p := serverPeers[i]
105-
bootstrap, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf,
106-
corerouting.SupernodeServer(routingDatastore)))
94+
for i := 0; i < numServers; i++ {
95+
bootstrap, err := core.NewNode(ctx, &core.BuildCfg{
96+
Online: true,
97+
Host: mock.MockHostOption(mn),
98+
Routing: corerouting.SupernodeServer(routingDatastore),
99+
})
107100
if err != nil {
108101
return nil, nil, err
109102
}
@@ -117,15 +110,18 @@ func InitializeSupernodeNetwork(
117110
}
118111

119112
var clients []*core.IpfsNode
120-
for i := range iter.N(numClients) {
121-
p := clientPeers[i]
122-
n, err := core.NewIPFSNode(ctx, MocknetTestRepo(p, mn.Host(p), conf,
123-
corerouting.SupernodeClient(bootstrapInfos...)))
113+
for i := 0; i < numClients; i++ {
114+
n, err := core.NewNode(ctx, &core.BuildCfg{
115+
Online: true,
116+
Host: mock.MockHostOption(mn),
117+
Routing: corerouting.SupernodeClient(bootstrapInfos...),
118+
})
124119
if err != nil {
125120
return nil, nil, err
126121
}
127122
clients = append(clients, n)
128123
}
124+
mn.LinkAll()
129125

130126
bcfg := core.BootstrapConfigWithPeers(bootstrapInfos)
131127
for _, n := range clients {

‎test/integration/three_legged_cat_test.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
core "github.com/ipfs/go-ipfs/core"
1414
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
15+
mock "github.com/ipfs/go-ipfs/core/mock"
1516
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
1617
"github.com/ipfs/go-ipfs/p2p/peer"
1718
"github.com/ipfs/go-ipfs/thirdparty/unit"
@@ -67,35 +68,40 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
6768
const numPeers = 3
6869

6970
// create network
70-
mn, err := mocknet.FullMeshLinked(ctx, numPeers)
71-
if err != nil {
72-
return err
73-
}
71+
mn := mocknet.New(ctx)
7472
mn.SetLinkDefaults(mocknet.LinkOptions{
7573
Latency: conf.NetworkLatency,
7674
// TODO add to conf. This is tricky because we want 0 values to be functional.
7775
Bandwidth: math.MaxInt32,
7876
})
7977

80-
peers := mn.Peers()
81-
if len(peers) < numPeers {
82-
return errors.New("test initialization error")
83-
}
84-
bootstrap, err := core.NewIPFSNode(ctx, MocknetTestRepo(peers[2], mn.Host(peers[2]), conf, core.DHTOption))
78+
bootstrap, err := core.NewNode(ctx, &core.BuildCfg{
79+
Online: true,
80+
Host: mock.MockHostOption(mn),
81+
})
8582
if err != nil {
8683
return err
8784
}
8885
defer bootstrap.Close()
89-
adder, err := core.NewIPFSNode(ctx, MocknetTestRepo(peers[0], mn.Host(peers[0]), conf, core.DHTOption))
86+
87+
adder, err := core.NewNode(ctx, &core.BuildCfg{
88+
Online: true,
89+
Host: mock.MockHostOption(mn),
90+
})
9091
if err != nil {
9192
return err
9293
}
9394
defer adder.Close()
94-
catter, err := core.NewIPFSNode(ctx, MocknetTestRepo(peers[1], mn.Host(peers[1]), conf, core.DHTOption))
95+
96+
catter, err := core.NewNode(ctx, &core.BuildCfg{
97+
Online: true,
98+
Host: mock.MockHostOption(mn),
99+
})
95100
if err != nil {
96101
return err
97102
}
98103
defer catter.Close()
104+
mn.LinkAll()
99105

100106
bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
101107
bcfg := core.BootstrapConfigWithPeers([]peer.PeerInfo{bis})

0 commit comments

Comments
 (0)
Please sign in to comment.