@cryptotaxi247 / kubo / commits / 7b85579d7

core: move online service init block into own func

addresses CR comments

Juan Batiz-Benet committed Jan 31, 2015 at 17:20 UTC 7b85579d7a00a01febc0073a76ce49552ba70f46
1 file changed +25 -21
core/core.go
+25 -21
@@ -220,27 +220,8 @@ func (n *IpfsNode) StartOnlineServices(ctx context.Context) error {
220 }
221 n.PeerHost = peerhost
222
223 - // this block is the set of services which need to be initialized with the host
224 - // and _before_ we start listening.
225 - {
226 - // setup diagnostics service
227 - n.Diagnostics = diag.NewDiagnostics(n.Identity, n.PeerHost)
228 -
229 - // setup routing service
230 - dhtRouting, err := constructDHTRouting(ctx, n.PeerHost, n.Repo.Datastore())
231 - if err != nil {
232 - return debugerror.Wrap(err)
233 - }
234 - n.Routing = dhtRouting
235 -
236 - // setup exchange service
237 - const alwaysSendToPeer = true // use YesManStrategy
238 - bitswapNetwork := bsnet.NewFromIpfsHost(n.PeerHost, n.Routing)
239 - n.Exchange = bitswap.New(ctx, n.Identity, bitswapNetwork, n.Blockstore, alwaysSendToPeer)
240 -
241 - // setup name system
242 - // TODO implement an offline namesys that serves only local names.
243 - n.Namesys = namesys.NewNameSystem(n.Routing)
223 + if err := n.startOnlineServicesWithHost(ctx); err != nil {
224 + return err
225 }
226
227 // Ok, now we're ready to listen.
@@ -254,6 +235,29 @@ func (n *IpfsNode) StartOnlineServices(ctx context.Context) error {
235 return n.Bootstrap(DefaultBootstrapConfig)
236 }
237
238 +// startOnlineServicesWithHost is the set of services which need to be
239 +// initialized with the host and _before_ we start listening.
240 +func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context) error {
241 + // setup diagnostics service
242 + n.Diagnostics = diag.NewDiagnostics(n.Identity, n.PeerHost)
243 +
244 + // setup routing service
245 + dhtRouting, err := constructDHTRouting(ctx, n.PeerHost, n.Repo.Datastore())
246 + if err != nil {
247 + return debugerror.Wrap(err)
248 + }
249 + n.Routing = dhtRouting
250 +
251 + // setup exchange service
252 + const alwaysSendToPeer = true // use YesManStrategy
253 + bitswapNetwork := bsnet.NewFromIpfsHost(n.PeerHost, n.Routing)
254 + n.Exchange = bitswap.New(ctx, n.Identity, bitswapNetwork, n.Blockstore, alwaysSendToPeer)
255 +
256 + // setup name system
257 + n.Namesys = namesys.NewNameSystem(n.Routing)
258 + return nil
259 +}
260 +
261 // teardown closes owned children. If any errors occur, this function returns
262 // the first error.
263 func (n *IpfsNode) teardown() error {