Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
dfd4f94b
提交
dfd4f94b
authored
8月 03, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: dag: Batching interface
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
d0a1cee9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
81 行增加
和
22 行删除
+81
-22
dag.go
core/coreapi/dag.go
+63
-19
dag.go
core/coreapi/interface/dag.go
+18
-3
没有找到文件。
core/coreapi/dag.go
浏览文件 @
dfd4f94b
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"context"
"context"
"fmt"
"fmt"
"io"
"io"
"sync"
gopath
"path"
gopath
"path"
...
@@ -17,34 +18,25 @@ import (
...
@@ -17,34 +18,25 @@ import (
type
DagAPI
CoreAPI
type
DagAPI
CoreAPI
type
dagBatch
struct
{
api
*
DagAPI
toPut
[]
ipld
.
Node
lk
sync
.
Mutex
}
// Put inserts data using specified format and input encoding. Unless used with
// Put inserts data using specified format and input encoding. Unless used with
// `WithCodes` or `WithHash`, the defaults "dag-cbor" and "sha256" are used.
// `WithCodes` or `WithHash`, the defaults "dag-cbor" and "sha256" are used.
// Returns the path of the inserted data.
// Returns the path of the inserted data.
func
(
api
*
DagAPI
)
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
caopts
.
DagPutOption
)
(
coreiface
.
ResolvedPath
,
error
)
{
func
(
api
*
DagAPI
)
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
caopts
.
DagPutOption
)
(
coreiface
.
ResolvedPath
,
error
)
{
settings
,
err
:=
caopts
.
DagPutOptions
(
opts
...
)
nd
,
err
:=
getNode
(
src
,
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
codec
,
ok
:=
cid
.
CodecToStr
[
settings
.
Codec
]
err
=
api
.
node
.
DAG
.
Add
(
ctx
,
nd
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid codec %d"
,
settings
.
Codec
)
}
nds
,
err
:=
coredag
.
ParseInputs
(
settings
.
InputEnc
,
codec
,
src
,
settings
.
MhType
,
settings
.
MhLength
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
len
(
nds
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"no node returned from ParseInputs"
)
}
err
=
api
.
node
.
DAG
.
Add
(
ctx
,
nds
[
0
])
return
coreiface
.
IpldPath
(
nd
.
Cid
()),
nil
if
err
!=
nil
{
return
nil
,
err
}
return
coreiface
.
IpldPath
(
nds
[
0
]
.
Cid
()),
nil
}
}
// Get resolves `path` using Unixfs resolver, returns the resolved Node.
// Get resolves `path` using Unixfs resolver, returns the resolved Node.
...
@@ -75,6 +67,58 @@ func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, opts ...caopts.Da
...
@@ -75,6 +67,58 @@ func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, opts ...caopts.Da
return
out
,
nil
return
out
,
nil
}
}
func
(
api
*
DagAPI
)
Batch
(
ctx
context
.
Context
)
coreiface
.
DagBatch
{
return
&
dagBatch
{
api
:
api
}
}
func
(
b
*
dagBatch
)
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
caopts
.
DagPutOption
)
(
coreiface
.
ResolvedPath
,
error
)
{
nd
,
err
:=
getNode
(
src
,
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
b
.
lk
.
Lock
()
b
.
toPut
=
append
(
b
.
toPut
,
nd
)
b
.
lk
.
Unlock
()
return
coreiface
.
IpldPath
(
nd
.
Cid
()),
nil
}
func
(
b
*
dagBatch
)
Commit
(
ctx
context
.
Context
)
error
{
b
.
lk
.
Lock
()
defer
b
.
lk
.
Unlock
()
defer
func
()
{
b
.
toPut
=
nil
}()
return
b
.
api
.
node
.
DAG
.
AddMany
(
ctx
,
b
.
toPut
)
}
func
getNode
(
src
io
.
Reader
,
opts
...
caopts
.
DagPutOption
)
(
ipld
.
Node
,
error
)
{
settings
,
err
:=
caopts
.
DagPutOptions
(
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
codec
,
ok
:=
cid
.
CodecToStr
[
settings
.
Codec
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid codec %d"
,
settings
.
Codec
)
}
nds
,
err
:=
coredag
.
ParseInputs
(
settings
.
InputEnc
,
codec
,
src
,
settings
.
MhType
,
settings
.
MhLength
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
nds
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"no node returned from ParseInputs"
)
}
if
len
(
nds
)
!=
1
{
return
nil
,
fmt
.
Errorf
(
"got more that one node from ParseInputs"
)
}
return
nds
[
0
],
nil
}
func
(
api
*
DagAPI
)
core
()
coreiface
.
CoreAPI
{
func
(
api
*
DagAPI
)
core
()
coreiface
.
CoreAPI
{
return
(
*
CoreAPI
)(
api
)
return
(
*
CoreAPI
)(
api
)
}
}
core/coreapi/interface/dag.go
浏览文件 @
dfd4f94b
...
@@ -4,21 +4,36 @@ import (
...
@@ -4,21 +4,36 @@ import (
"context"
"context"
"io"
"io"
options
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
ipld
"gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
ipld
"gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
)
)
// Dag
API specifies the interface to IPLD
// Dag
Ops groups operations that can be batched together
type
Dag
API
interface
{
type
Dag
Ops
interface
{
// Put inserts data using specified format and input encoding.
// Put inserts data using specified format and input encoding.
// Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
// Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
// "sha256" are used.
// "sha256" are used.
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
options
.
DagPutOption
)
(
ResolvedPath
,
error
)
Put
(
ctx
context
.
Context
,
src
io
.
Reader
,
opts
...
options
.
DagPutOption
)
(
ResolvedPath
,
error
)
}
// DagBatch is the batching version of DagAPI. All implementations of DagBatch
// should be threadsafe
type
DagBatch
interface
{
DagOps
Commit
(
ctx
context
.
Context
)
error
}
// DagAPI specifies the interface to IPLD
type
DagAPI
interface
{
DagOps
// Get attempts to resolve and get the node specified by the path
// Get attempts to resolve and get the node specified by the path
Get
(
ctx
context
.
Context
,
path
Path
)
(
ipld
.
Node
,
error
)
Get
(
ctx
context
.
Context
,
path
Path
)
(
ipld
.
Node
,
error
)
// Tree returns list of paths within a node specified by the path.
// Tree returns list of paths within a node specified by the path.
Tree
(
ctx
context
.
Context
,
path
Path
,
opts
...
options
.
DagTreeOption
)
([]
Path
,
error
)
Tree
(
ctx
context
.
Context
,
path
Path
,
opts
...
options
.
DagTreeOption
)
([]
Path
,
error
)
Batch
(
ctx
context
.
Context
)
DagBatch
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论