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

refactor(core): NewIPFSNode constructor #538

Merged
merged 23 commits into from
Jan 11, 2015
Merged

Conversation

btc
Copy link
Contributor

@btc btc commented Jan 11, 2015

RFC/RFCR

This PR is a gradual refactor of the core.IPFSNode constructor.

Primary objectives:

Before

core.NewIpfsNode(context.Context, *config.Config, online bool) (*core.IpfsNode, error)

After

core.NewIPFSNode(context.Context, ConfigOption) (*core.IpfsNode, error)

The old signature can be emulated as follows:

// Standard is a higher order function. (this is simply partial application)
n, err := core.NewIPFSNode(ctx, core.Standard(config, online))

The crux of ConfigOption is that it allows for any number of custom configuration options. It takes ideas from Pike's self-referential functions, but is tailored to our specific needs and constraints (we have a lot of these).

http://commandcenter.blogspot.nl/2014/01/self-referential-functions-and-design.html

Some type signatures I've considered so far:

// extend the node and return it 
// PITFALL: unclear responsibilities for field initialization
type ConfigOption func(context.Context, *core.IpfsNode) (*core.IpfsNode, error)
type ConfigOption func(context.Context, *core.IpfsNode) (error) // alternative

// return some smaller building block and use it to construct the node in NewIPFSNode
// PITFALL: verbosity/duplication, ownership concerns
type ConfigOption func(context.Context) (someNodeComponents/Repo, error)

I've hit a point in the implementation where it is no longer possible to share more of the constructor code without making tough trade-offs. This is a good time to invite others into the design process.

(big refactor with lots of commits but all commits should pass all tests)

@btc btc added the status/in-progress In progress label Jan 11, 2015
@jbenet
Copy link
Member

jbenet commented Jan 11, 2015

@briantigerchow this is great stuff! very much needed.

return nil, err
}
return uio.NewDagReader(nodeCatted, catterdag)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is beautiful. and yes, +1 on free functions. btw, lots of it can probably be abstracted into an interface (i.e. cat shouldnt need to know what a path.Resolver is, and instead could call ipfs.Resolve(path))

@jbenet
Copy link
Member

jbenet commented Jan 11, 2015

❤️ want to merge this in asap.

@jbenet
Copy link
Member

jbenet commented Jan 11, 2015

(btw build err)

@btc
Copy link
Contributor Author

btc commented Jan 11, 2015

About to rebase on master and fixup the build error. Responding to your comments here since they'll disappear after the rebase:

+1 on free functions. btw, lots of it can probably be abstracted into an interface (i.e. cat shouldnt need to know what a path.Resolver is, and instead could call ipfs.Resolve(path))

For the free functions, would you prefer to see them in another package or here in core?

Can we get rid of this online bool?

not sure if this is still WIP, but the "connecting to bootstrap peers" part should be in this function too.

It originally used the bootstrap method, but was causing tests to hang. I'll put a TODO comment in the function as a reminder to address before merging.

func bootstrap(ctx context.Context, h host.Host, r *dht.IpfsDHT, ps peer.Peerstore, bootstrapPeers []peer.PeerInfo) error
  • find bug and use bootstrap

(btw build err)

doh!

@btc btc force-pushed the refactor/core-construction branch from ccb08af to e3ac6af Compare January 11, 2015 06:46
@jbenet
Copy link
Member

jbenet commented Jan 11, 2015

For the free functions, would you prefer to see them in another package or here in core?

Another package.

but was causing tests to hang.

interesing-- any idea why?

btw, tests can now use ipfs bootstrap rm --all

@btc btc force-pushed the refactor/core-construction branch 6 times, most recently from e9c2c8f to b0849fa Compare January 11, 2015 08:53
@btc
Copy link
Contributor Author

btc commented Jan 11, 2015

interesing-- any idea why?

@jbenet it's not hanging anymore. as of b0849fa it works fine.

@btc btc self-assigned this Jan 11, 2015
@jbenet
Copy link
Member

jbenet commented Jan 11, 2015

@briantigerchow LGTM, merge this in if you're ready.

@btc btc force-pushed the refactor/core-construction branch from b0849fa to a7f9587 Compare January 11, 2015 09:01
@btc btc force-pushed the refactor/core-construction branch from a7f9587 to 63c0d41 Compare January 11, 2015 09:23
btc pushed a commit that referenced this pull request Jan 11, 2015
refactor(core): NewIPFSNode constructor
@btc btc merged commit f44ef3f into master Jan 11, 2015
@btc btc removed the status/in-progress In progress label Jan 11, 2015
@btc btc deleted the refactor/core-construction branch January 11, 2015 09:47
@btc btc mentioned this pull request Jan 11, 2015
5 tasks
@btc btc removed their assignment Mar 30, 2015
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants