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

CoreAPI: Global offline option #5825

Merged
merged 12 commits into from
Dec 20, 2018
Merged

CoreAPI: Global offline option #5825

merged 12 commits into from
Dec 20, 2018

Conversation

magik6k
Copy link
Member

@magik6k magik6k commented Dec 6, 2018

For #5654. This implements the 'Functional options on the constructor' approach.

I decided to not use core.IpfsNode directly in coreapi as this way we have much better control over how the internals are used. Longer term, after coreapi interface is extracted form go-ipfs, I plan on merging a lot of core node and coreapi functionality, but I want to do that together with go-ipfs constructor cleanup as it will be quite breaking for people using core.IpfsNode directly (there still are good reasons to do that)

A few bugs and todos are still left, reviews welcome

@magik6k magik6k requested a review from Kubuxu as a code owner December 6, 2018 21:39
@ghost ghost assigned magik6k Dec 6, 2018
@ghost ghost added the status/in-progress In progress label Dec 6, 2018
@magik6k magik6k added the topic/core-api Topic core-api label Dec 6, 2018
@magik6k magik6k mentioned this pull request Dec 6, 2018
51 tasks
@Stebalien Stebalien requested a review from schomatis December 7, 2018 23:03
Copy link
Contributor

@schomatis schomatis left a comment

Choose a reason for hiding this comment

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

The code in general LGTM (but I can't really comment on the design decision of extracting all of the IpfsNode attributes here).

core/coreapi/coreapi.go Outdated Show resolved Hide resolved

// TODO: this can be generalized to all functions when we implement some
// api based security mechanism
isPublishAllowed func() error
Copy link
Member

Choose a reason for hiding this comment

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

This method isn't really about security. Really, we should allow publishing IPNS records while /ipns is mounted. We don't currently because we haven't implemented that yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know, I just wanted to hint that something like this may be useful (but a full security layer implementing coreapi interface would probably be better)

core/coreapi/coreapi.go Outdated Show resolved Hide resolved
ctx, ok := env.(*commands.Context)
if !ok {
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
}

return ctx.GetAPI()
local, _ := req.Options["local"].(bool)
Copy link
Member

Choose a reason for hiding this comment

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

So, this'll apply this option (correctly) to all commands fixing part of #4182. I wonder if we should fix the "confusing" part while we're at it by renaming this option to "offline" (keeping a hidden alias for compatibility).

That would also allow us to share the same option with ipfs daemon --offline which should help to further reduce confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine with doing that (the hidden alias could throw warnings at people). This will probably need support on the js side too

Copy link
Member

Choose a reason for hiding this comment

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

I didn't realize js replicated that option.

@alanshaw how would you feel about switching from --local to --offline (keeping --local as a backcompat alias)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented, waiting for @alanshaw's opinion (assuming js-ipfs implements --local)

@magik6k magik6k force-pushed the feat/coreapi/opts branch 2 times, most recently from a16a5ba to 7ddb45f Compare December 12, 2018 12:06
core/commands/root.go Outdated Show resolved Hide resolved
core/coreapi/coreapi.go Outdated Show resolved Hide resolved
@magik6k magik6k force-pushed the feat/coreapi/opts branch 2 times, most recently from 4eccfa9 to 6de9b03 Compare December 17, 2018 08:15
core/coreapi/coreapi.go Outdated Show resolved Hide resolved
core/coreapi/coreapi.go Outdated Show resolved Hide resolved

cs := cfg.Ipns.ResolveCacheSize
if cs == 0 {
cs = 128
Copy link
Member

Choose a reason for hiding this comment

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

We should lift this to a constant.

}

bserv := blockservice.New(addblockstore, exch) // hash security 001
dserv := dag.NewDAGService(bserv)

fileAdder, err := coreunix.NewAdder(ctx, n.Pinning, n.Blockstore, dserv)
fileAdder, err := coreunix.NewAdder(ctx, pinning, addblockstore, dserv)
Copy link
Member

Choose a reason for hiding this comment

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

Is this a bugfix or a bug? It's now using addblocksore where it used to use the unmodified blockstore.

Copy link
Member Author

Choose a reason for hiding this comment

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

bugfix - coreunix.NewAdder uses it only for the GCLock, which we don't want/need to take from the 'real' node when we do add with OnlyHash set.

@Stebalien
Copy link
Member

Mostly nits at this point but you should take a look at #5825 (comment).

@Stebalien
Copy link
Member

@ipfs/go-team this is an interface change (but not a breaking one).

It replaces --local with --offline, leaving --local for backwards compatibility. It also makes --offline work with every command (--local currently only works with a few commands).

Suggestions? Objections?

@magik6k
Copy link
Member Author

magik6k commented Dec 20, 2018

(rebased)

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
@Stebalien Stebalien merged commit 28dabc7 into master Dec 20, 2018
@ghost ghost removed the status/in-progress In progress label Dec 20, 2018
@Stebalien Stebalien deleted the feat/coreapi/opts branch December 20, 2018 16:24
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
CoreAPI: Global offline option

This commit was moved from ipfs/kubo@28dabc7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFM topic/core-api Topic core-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants