@@ -46,7 +46,6 @@ import (
46
46
exchange "github.com/ipfs/go-ipfs/exchange"
47
47
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
48
48
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
49
- offline "github.com/ipfs/go-ipfs/exchange/offline"
50
49
rp "github.com/ipfs/go-ipfs/exchange/reprovide"
51
50
52
51
mount "github.com/ipfs/go-ipfs/fuse/mount"
@@ -124,7 +123,9 @@ type Mounts struct {
124
123
125
124
type ConfigOption func (ctx context.Context ) (* IpfsNode , error )
126
125
126
+ // DEPRECATED
127
127
func NewIPFSNode (ctx context.Context , option ConfigOption ) (* IpfsNode , error ) {
128
+ log .Error ("Using deprecated node construction method, please update to NodeBuilder" )
128
129
node , err := option (ctx )
129
130
if err != nil {
130
131
return nil , err
@@ -175,80 +176,8 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
175
176
return node , nil
176
177
}
177
178
178
- func Offline (r repo.Repo ) ConfigOption {
179
- return Standard (r , false )
180
- }
181
-
182
- func OnlineWithOptions (r repo.Repo , router RoutingOption , ho HostOption ) ConfigOption {
183
- return standardWithRouting (r , true , router , ho )
184
- }
185
-
186
- func Online (r repo.Repo ) ConfigOption {
187
- return Standard (r , true )
188
- }
179
+ func (n * IpfsNode ) setupHost (ctx context.Context , hostOption HostOption ) {
189
180
190
- // DEPRECATED: use Online, Offline functions
191
- func Standard (r repo.Repo , online bool ) ConfigOption {
192
- return standardWithRouting (r , online , DHTOption , DefaultHostOption )
193
- }
194
-
195
- // TODO refactor so maybeRouter isn't special-cased in this way
196
- func standardWithRouting (r repo.Repo , online bool , routingOption RoutingOption , hostOption HostOption ) ConfigOption {
197
- return func (ctx context.Context ) (n * IpfsNode , err error ) {
198
- // FIXME perform node construction in the main constructor so it isn't
199
- // necessary to perform this teardown in this scope.
200
- success := false
201
- defer func () {
202
- if ! success && n != nil {
203
- n .teardown ()
204
- }
205
- }()
206
-
207
- // TODO move as much of node initialization as possible into
208
- // NewIPFSNode. The larger these config options are, the harder it is
209
- // to test all node construction code paths.
210
-
211
- if r == nil {
212
- return nil , fmt .Errorf ("repo required" )
213
- }
214
- n = & IpfsNode {
215
- mode : func () mode {
216
- if online {
217
- return onlineMode
218
- }
219
- return offlineMode
220
- }(),
221
- Repo : r ,
222
- }
223
-
224
- n .ctx = ctx
225
- n .proc = goprocessctx .WithContextAndTeardown (ctx , n .teardown )
226
-
227
- // setup Peerstore
228
- n .Peerstore = peer .NewPeerstore ()
229
-
230
- // setup local peer ID (private key is loaded in online setup)
231
- if err := n .loadID (); err != nil {
232
- return nil , err
233
- }
234
-
235
- n .Blockstore , err = bstore .WriteCached (bstore .NewBlockstore (n .Repo .Datastore ()), kSizeBlockstoreWriteCache )
236
- if err != nil {
237
- return nil , err
238
- }
239
-
240
- if online {
241
- do := setupDiscoveryOption (n .Repo .Config ().Discovery )
242
- if err := n .startOnlineServices (ctx , routingOption , hostOption , do ); err != nil {
243
- return nil , err
244
- }
245
- } else {
246
- n .Exchange = offline .Exchange (n .Blockstore )
247
- }
248
-
249
- success = true
250
- return n , nil
251
- }
252
181
}
253
182
254
183
func (n * IpfsNode ) startOnlineServices (ctx context.Context , routingOption RoutingOption , hostOption HostOption , do DiscoveryOption ) error {
@@ -378,10 +307,13 @@ func (n *IpfsNode) teardown() error {
378
307
// owned objects are closed in this teardown to ensure that they're closed
379
308
// regardless of which constructor was used to add them to the node.
380
309
closers := []io.Closer {
381
- n .Exchange ,
382
310
n .Repo ,
383
311
}
384
312
313
+ if n .Exchange != nil {
314
+ closers = append (closers , n .Exchange )
315
+ }
316
+
385
317
if n .Mounts .Ipfs != nil {
386
318
closers = append (closers , mount .Closer (n .Mounts .Ipfs ))
387
319
}
0 commit comments