Skip to content

Commit

Permalink
amendment to core context + cancels
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Tiger Chow committed Sep 23, 2014
1 parent c7913ef commit 2956dde
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
// derive this from a higher context.
// cancel if we need to fail early.
ctx, cancel := context.WithCancel(context.TODO())
success := false // flip to true after all sub-system inits succeed
defer func() {
if !success {
cancel()
}
}()

if cfg == nil {
cancel()
return nil, fmt.Errorf("configuration required")
}

d, err := makeDatastore(cfg.Datastore)
if err != nil {
cancel()
return nil, err
}

Expand All @@ -99,19 +103,16 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
// when not online, don't need to parse private keys (yet)
local, err := initIdentity(cfg)
if err != nil {
cancel()
return nil, err
}

dhtService := netservice.NewService(nil) // nil handler for now, need to patch it
exchangeService := netservice.NewService(nil) // nil handler for now, need to patch it

if err := dhtService.Start(ctx); err != nil {
cancel()
return nil, err
}
if err := exchangeService.Start(ctx); err != nil {
cancel()
return nil, err
}

Expand All @@ -121,7 +122,6 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
// add protocol services here.
})
if err != nil {
cancel()
return nil, err
}

Expand All @@ -140,12 +140,12 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
// session that simply doesn't return blocks
bs, err := bserv.NewBlockService(d, exchangeSession)
if err != nil {
cancel()
return nil, err
}

dag := &merkledag.DAGService{Blocks: bs}

success = true
return &IpfsNode{
Config: cfg,
Peerstore: peerstore,
Expand Down

0 comments on commit 2956dde

Please sign in to comment.