Fix bootstrap
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Apr 1, 2019 at 13:45 UTC
bfaffb2d757014d334e2bb23e984acfc6cb53e50
3 files changed
+52
-49
core/builder.go
+24
-15
@@ -245,18 +245,18 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
245
n.IsOnline = cfg.Online
246
n.app = app
247
248
-/* n := &IpfsNode{
249
- IsOnline: cfg.Online,
250
- Repo: cfg.Repo,
251
- ctx: ctx,
252
- Peerstore: pstoremem.NewPeerstore(),
253
- }
248
+ /* n := &IpfsNode{
249
+ IsOnline: cfg.Online,
250
+ Repo: cfg.Repo,
251
+ ctx: ctx,
252
+ Peerstore: pstoremem.NewPeerstore(),
253
+ }
254
255
- n.RecordValidator = record.NamespacedValidator{
256
- "pk": record.PublicKeyValidator{},
257
- "ipns": ipns.Validator{KeyBook: n.Peerstore},
258
- }
259
-*/
255
+ n.RecordValidator = record.NamespacedValidator{
256
+ "pk": record.PublicKeyValidator{},
257
+ "ipns": ipns.Validator{KeyBook: n.Peerstore},
258
+ }
259
+ */
260
// TODO: port to lifetimes
261
// n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)
262
@@ -264,11 +264,20 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
264
n.Close()
265
return nil, err
266
}*/
267
- if app.Err() != nil {
268
- return nil, app.Err()
269
- }
267
+ if app.Err() != nil {
268
+ return nil, app.Err()
269
+ }
270
+
271
+ if err := app.Start(ctx); err != nil {
272
+ return nil, err
273
+ }
274
+
275
+ // TODO: DI-ify bootstrap
276
+ if !cfg.Online {
277
+ return n, nil
278
+ }
279
271
- return n, app.Start(ctx)
280
+ return n, n.Bootstrap(DefaultBootstrapConfig)
281
}
282
283
func isTooManyFDError(err error) bool {
core/core.go
+20
-20
@@ -100,13 +100,13 @@ type IpfsNode struct {
100
Repo repo.Repo
101
102
// Local node
103
- Pinning pin.Pinner // the pinning manager
104
- Mounts Mounts `optional:"true"` // current mount state, if any.
105
- PrivateKey ic.PrivKey // the local node's private Key
106
- PNetFingerprint PNetFingerprint `optional:"true"` // fingerprint of private network
103
+ Pinning pin.Pinner // the pinning manager
104
+ Mounts Mounts `optional:"true"` // current mount state, if any.
105
+ PrivateKey ic.PrivKey // the local node's private Key
106
+ PNetFingerprint PNetFingerprint `optional:"true"` // fingerprint of private network
107
108
// Services
109
- Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances
109
+ Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances
110
Blockstore bstore.GCBlockstore // the block store (lower level)
111
Filestore *filestore.Filestore // the filestore blockstore
112
BaseBlocks bstore.Blockstore // the raw blockstore, no filestore wrapping
@@ -114,35 +114,35 @@ type IpfsNode struct {
114
Blocks bserv.BlockService // the block service, get/add blocks.
115
DAG ipld.DAGService // the merkle dag service, get/add objects.
116
Resolver *resolver.Resolver // the path resolution system
117
- Reporter metrics.Reporter `optional:"true"`
118
- Discovery discovery.Service `optional:"true"`
117
+ Reporter metrics.Reporter `optional:"true"`
118
+ Discovery discovery.Service `optional:"true"`
119
FilesRoot *mfs.Root
120
RecordValidator record.Validator
121
122
// Online
123
- PeerHost p2phost.Host `optional:"true"` // the network host (server+client)
123
+ PeerHost p2phost.Host `optional:"true"` // the network host (server+client)
124
Bootstrapper io.Closer `optional:"true"` // the periodic bootstrapper
125
Routing routing.IpfsRouting `optional:"true"` // the routing system. recommend ipfs-dht
126
Exchange exchange.Interface // the block exchange + strategy (bitswap)
127
Namesys namesys.NameSystem // the name system, resolves paths to hashes
128
- Provider provider.Provider // the value provider system
129
- Reprovider *rp.Reprovider `optional:"true"` // the value reprovider system
128
+ Provider provider.Provider // the value provider system
129
+ Reprovider *rp.Reprovider `optional:"true"` // the value reprovider system
130
IpnsRepub *ipnsrp.Republisher `optional:"true"`
131
132
- AutoNAT *autonat.AutoNATService `optional:"true"`
133
- PubSub *pubsub.PubSub `optional:"true"`
132
+ AutoNAT *autonat.AutoNATService `optional:"true"`
133
+ PubSub *pubsub.PubSub `optional:"true"`
134
PSRouter *psrouter.PubsubValueStore `optional:"true"`
135
- DHT *dht.IpfsDHT `optional:"true"`
136
- P2P *p2p.P2P `optional:"true"`
135
+ DHT *dht.IpfsDHT `optional:"true"`
136
+ P2P *p2p.P2P `optional:"true"`
137
138
Process goprocess.Process
139
- ctx context.Context
139
+ ctx context.Context
140
141
app *fx.App
142
143
// Flags
144
- IsOnline bool `optional:"true"` // Online is set when networking is enabled.
145
- IsDaemon bool `optional:"true"` // Daemon is set when running on a long-running daemon.
144
+ IsOnline bool `optional:"true"` // Online is set when networking is enabled.
145
+ IsDaemon bool `optional:"true"` // Daemon is set when running on a long-running daemon.
146
}
147
148
// Mounts defines what the node's mount state is. This should
@@ -206,9 +206,9 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
206
log.Warning("This might be configuration mistake.")
207
}
208
}
209
- //case <-n.Process().Closing():
210
- // t.Stop()
211
- // return
209
+ //case <-n.Process().Closing():
210
+ // t.Stop()
211
+ // return
212
}
213
}
214
}()
core/ncore.go
+8
-14
@@ -452,11 +452,11 @@ func p2pHost(lc fx.Lifecycle, params p2pHostIn) (out p2pHostOut, err error) {
452
type p2pRoutingIn struct {
453
fx.In
454
455
- BCfg *BuildCfg
456
- Repo repo.Repo
457
- Validator record.Validator
458
- Host p2phost.Host
459
- PubSub *pubsub.PubSub
455
+ BCfg *BuildCfg
456
+ Repo repo.Repo
457
+ Validator record.Validator
458
+ Host p2phost.Host
459
+ PubSub *pubsub.PubSub
460
461
BaseRouting BaseRouting
462
}
@@ -553,7 +553,6 @@ func offlineNamesysCtor(rt routing.IpfsRouting, repo repo.Repo) (namesys.NameSys
553
return namesys.NewNameSystem(rt, repo.Datastore(), 0), nil
554
}
555
556
-
556
////////////
557
// IPFS services
558
@@ -621,7 +620,7 @@ func ipnsRepublisher(lc lcProcess, cfg *iconfig.Config, namesys namesys.NameSyst
620
}
621
622
type discoveryHandler struct {
624
- ctx context.Context
623
+ ctx context.Context
624
host p2phost.Host
625
}
626
@@ -636,7 +635,7 @@ func (dh *discoveryHandler) HandlePeerFound(p pstore.PeerInfo) {
635
636
func newDiscoveryHandler(lc fx.Lifecycle, host p2phost.Host) *discoveryHandler {
637
return &discoveryHandler{
639
- ctx: lifecycleCtx(lc),
638
+ ctx: lifecycleCtx(lc),
639
host: host,
640
}
641
}
@@ -739,11 +738,6 @@ func files(lc fx.Lifecycle, repo repo.Repo, dag format.DAGService) (*mfs.Root, e
738
return mfs.NewRoot(ctx, dag, nd, pf)
739
}
740
742
-// TODO !!!!!!!!
743
-func bootstrap(n IpfsNode) error {
744
- return n.Bootstrap(DefaultBootstrapConfig)
745
-}
746
-
741
////////////
742
// Hacks
743
@@ -765,7 +759,7 @@ func lifecycleCtx(lc fx.Lifecycle) context.Context {
759
type lcProcess struct {
760
fx.In
761
768
- LC fx.Lifecycle
762
+ LC fx.Lifecycle
763
Proc goprocess.Process
764
}
765