Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amendment to core context + cancels #105

Merged
merged 1 commit into from
Sep 27, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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