-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5939 from ipfs/misc/dag-coreapi
Port dag commansds to CoreAPI
- Loading branch information
Showing
5 changed files
with
93 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package coreapi | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ipfs/go-ipfs/pin" | ||
|
||
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid" | ||
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format" | ||
) | ||
|
||
type dagAPI struct { | ||
ipld.DAGService | ||
|
||
core *CoreAPI | ||
} | ||
|
||
type pinningAdder CoreAPI | ||
|
||
func (adder *pinningAdder) Add(ctx context.Context, nd ipld.Node) error { | ||
defer adder.blockstore.PinLock().Unlock() | ||
|
||
if err := adder.dag.Add(ctx, nd); err != nil { | ||
return err | ||
} | ||
|
||
adder.pinning.PinWithMode(nd.Cid(), pin.Recursive) | ||
|
||
return adder.pinning.Flush() | ||
} | ||
|
||
func (adder *pinningAdder) AddMany(ctx context.Context, nds []ipld.Node) error { | ||
defer adder.blockstore.PinLock().Unlock() | ||
|
||
if err := adder.dag.AddMany(ctx, nds); err != nil { | ||
return err | ||
} | ||
|
||
cids := cid.NewSet() | ||
|
||
for _, nd := range nds { | ||
c := nd.Cid() | ||
if cids.Visit(c) { | ||
adder.pinning.PinWithMode(c, pin.Recursive) | ||
} | ||
} | ||
|
||
return adder.pinning.Flush() | ||
} | ||
|
||
func (api *dagAPI) Pinning() ipld.NodeAdder { | ||
return (*pinningAdder)(api.core) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package iface | ||
|
||
import ( | ||
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format" | ||
) | ||
|
||
// APIDagService extends ipld.DAGService | ||
type APIDagService interface { | ||
ipld.DAGService | ||
|
||
// Pinning returns special NodeAdder which recursively pins added nodes | ||
Pinning() ipld.NodeAdder | ||
} |