Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
699b2c4b
提交
699b2c4b
authored
1月 25, 2018
作者:
Steven Allen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make code-climate happier
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
上级
0d12a971
隐藏空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
62 行增加
和
18 行删除
+62
-18
blockservice.go
blockservice/blockservice.go
+10
-4
helpers.go
importer/helpers/helpers.go
+7
-4
importer.go
importer/importer.go
+7
-4
node.go
merkledag/node.go
+4
-2
utils.go
merkledag/test/utils.go
+2
-0
diff.go
merkledag/utils/diff.go
+1
-0
utils.go
merkledag/utils/utils.go
+10
-2
utils_test.go
merkledag/utils/utils_test.go
+2
-2
dir.go
mfs/dir.go
+4
-0
resolver.go
path/resolver.go
+1
-0
format.go
tar/format.go
+4
-0
hamt.go
unixfs/hamt/hamt.go
+2
-0
dirbuilder.go
unixfs/io/dirbuilder.go
+2
-0
pbdagreader.go
unixfs/io/pbdagreader.go
+1
-0
utils.go
unixfs/test/utils.go
+5
-0
没有找到文件。
blockservice/blockservice.go
浏览文件 @
699b2c4b
...
...
@@ -22,6 +22,8 @@ var log = logging.Logger("blockservice")
var
ErrNotFound
=
errors
.
New
(
"blockservice: key not found"
)
// BlockGetter is the common interface shared between blockservice sessions and
// the blockservice.
type
BlockGetter
interface
{
// GetBlock gets the requested block.
GetBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
...
...
@@ -95,12 +97,14 @@ func NewWriteThrough(bs blockstore.Blockstore, rem exchange.Interface) BlockServ
}
}
func
(
bs
*
blockService
)
Blockstore
()
blockstore
.
Blockstore
{
return
bs
.
blockstore
// Blockstore returns the blockstore behind this blockservice.
func
(
s
*
blockService
)
Blockstore
()
blockstore
.
Blockstore
{
return
s
.
blockstore
}
func
(
bs
*
blockService
)
Exchange
()
exchange
.
Interface
{
return
bs
.
exchange
// Exchange returns the exchange behind this blockservice.
func
(
s
*
blockService
)
Exchange
()
exchange
.
Interface
{
return
s
.
exchange
}
// NewSession creates a bitswap session that allows for controlled exchange of
...
...
@@ -286,3 +290,5 @@ func (s *Session) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error
func
(
s
*
Session
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
)
<-
chan
blocks
.
Block
{
return
getBlocks
(
ctx
,
ks
,
s
.
bs
,
s
.
ses
)
}
var
_
BlockGetter
=
(
*
Session
)(
nil
)
importer/helpers/helpers.go
浏览文件 @
699b2c4b
...
...
@@ -65,10 +65,12 @@ func (n *UnixfsNode) SetPrefix(prefix *cid.Prefix) {
n
.
node
.
SetPrefix
(
prefix
)
}
// NumChildren returns the number of children referenced by this UnixfsNode.
func
(
n
*
UnixfsNode
)
NumChildren
()
int
{
return
n
.
ufmt
.
NumChildren
()
}
// Set replaces this UnixfsNode with another UnixfsNode
func
(
n
*
UnixfsNode
)
Set
(
other
*
UnixfsNode
)
{
n
.
node
=
other
.
node
n
.
raw
=
other
.
raw
...
...
@@ -78,6 +80,7 @@ func (n *UnixfsNode) Set(other *UnixfsNode) {
}
}
// GetChild gets the ith child of this node from the given DAGService.
func
(
n
*
UnixfsNode
)
GetChild
(
ctx
context
.
Context
,
i
int
,
ds
node
.
DAGService
)
(
*
UnixfsNode
,
error
)
{
nd
,
err
:=
n
.
node
.
Links
()[
i
]
.
GetNode
(
ctx
,
ds
)
if
err
!=
nil
{
...
...
@@ -92,8 +95,8 @@ func (n *UnixfsNode) GetChild(ctx context.Context, i int, ds node.DAGService) (*
return
NewUnixfsNodeFromDag
(
pbn
)
}
//
addChild will add
the given UnixfsNode as a child of the receiver.
//
t
he passed in DagBuilderHelper is used to store the child node an
//
AddChild adds
the given UnixfsNode as a child of the receiver.
//
T
he passed in DagBuilderHelper is used to store the child node an
// pin it locally so it doesnt get lost
func
(
n
*
UnixfsNode
)
AddChild
(
child
*
UnixfsNode
,
db
*
DagBuilderHelper
)
error
{
n
.
ufmt
.
AddBlockSize
(
child
.
FileSize
())
...
...
@@ -115,7 +118,7 @@ func (n *UnixfsNode) AddChild(child *UnixfsNode, db *DagBuilderHelper) error {
return
err
}
// Removes the child node at the given index
// Remove
Child remove
s the child node at the given index
func
(
n
*
UnixfsNode
)
RemoveChild
(
index
int
,
dbh
*
DagBuilderHelper
)
{
n
.
ufmt
.
RemoveBlockSize
(
index
)
n
.
node
.
SetLinks
(
append
(
n
.
node
.
Links
()[
:
index
],
n
.
node
.
Links
()[
index
+
1
:
]
...
))
...
...
@@ -140,7 +143,7 @@ func (n *UnixfsNode) SetPosInfo(offset uint64, fullPath string, stat os.FileInfo
}
}
//
g
etDagNode fills out the proper formatting for the unixfs node
//
G
etDagNode fills out the proper formatting for the unixfs node
// inside of a DAG node and returns the dag node
func
(
n
*
UnixfsNode
)
GetDagNode
()
(
node
.
Node
,
error
)
{
nd
,
err
:=
n
.
getBaseDagNode
()
...
...
importer/importer.go
浏览文件 @
699b2c4b
//
p
ackage importer implements utilities used to create IPFS DAGs from files
// and readers
//
P
ackage importer implements utilities used to create IPFS DAGs from files
// and readers
.
package
importer
import
(
...
...
@@ -15,8 +15,8 @@ import (
node
"gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
)
// Build
s a DAG from the given file, writing created blocks to disk as they are
// created
// Build
DagFromFile builds a DAG from the given file, writing created blocks to
//
disk as they are
created
func
BuildDagFromFile
(
fpath
string
,
ds
node
.
DAGService
)
(
node
.
Node
,
error
)
{
stat
,
err
:=
os
.
Lstat
(
fpath
)
if
err
!=
nil
{
...
...
@@ -36,6 +36,8 @@ func BuildDagFromFile(fpath string, ds node.DAGService) (node.Node, error) {
return
BuildDagFromReader
(
ds
,
chunk
.
DefaultSplitter
(
f
))
}
// BuildDagFromReader builds a DAG from the chunks returned by the given chunk
// splitter.
func
BuildDagFromReader
(
ds
node
.
DAGService
,
spl
chunk
.
Splitter
)
(
node
.
Node
,
error
)
{
dbp
:=
h
.
DagBuilderParams
{
Dagserv
:
ds
,
...
...
@@ -45,6 +47,7 @@ func BuildDagFromReader(ds node.DAGService, spl chunk.Splitter) (node.Node, erro
return
bal
.
BalancedLayout
(
dbp
.
New
(
spl
))
}
// BuildTrickleDagFromReader is similar to BuildDagFromReader but uses the trickle layout.
func
BuildTrickleDagFromReader
(
ds
node
.
DAGService
,
spl
chunk
.
Splitter
)
(
node
.
Node
,
error
)
{
dbp
:=
h
.
DagBuilderParams
{
Dagserv
:
ds
,
...
...
merkledag/node.go
浏览文件 @
699b2c4b
...
...
@@ -124,7 +124,7 @@ func (n *ProtoNode) AddRawLink(name string, l *node.Link) error {
return
nil
}
// Remove
a link on this node by the given name
// Remove
NodeLink removes a link on this node by the given name.
func
(
n
*
ProtoNode
)
RemoveNodeLink
(
name
string
)
error
{
n
.
encoded
=
nil
good
:=
make
([]
*
node
.
Link
,
0
,
len
(
n
.
links
))
...
...
@@ -146,7 +146,7 @@ func (n *ProtoNode) RemoveNodeLink(name string) error {
return
nil
}
//
Return a copy of the link with given name
//
GetNodeLink returns a copy of the link with the given name.
func
(
n
*
ProtoNode
)
GetNodeLink
(
name
string
)
(
*
node
.
Link
,
error
)
{
for
_
,
l
:=
range
n
.
links
{
if
l
.
Name
==
name
{
...
...
@@ -160,6 +160,7 @@ func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) {
return
nil
,
ErrLinkNotFound
}
// GetLinkedProtoNode returns a copy of the ProtoNode with the given name.
func
(
n
*
ProtoNode
)
GetLinkedProtoNode
(
ctx
context
.
Context
,
ds
node
.
DAGService
,
name
string
)
(
*
ProtoNode
,
error
)
{
nd
,
err
:=
n
.
GetLinkedNode
(
ctx
,
ds
,
name
)
if
err
!=
nil
{
...
...
@@ -174,6 +175,7 @@ func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds node.DAGService,
return
pbnd
,
nil
}
// GetLinkedNode returns a copy of the IPLD Node with the given name.
func
(
n
*
ProtoNode
)
GetLinkedNode
(
ctx
context
.
Context
,
ds
node
.
DAGService
,
name
string
)
(
node
.
Node
,
error
)
{
lnk
,
err
:=
n
.
GetNodeLink
(
name
)
if
err
!=
nil
{
...
...
merkledag/test/utils.go
浏览文件 @
699b2c4b
...
...
@@ -11,10 +11,12 @@ import (
node
"gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
)
// Mock returns a new thread-safe, mock DAGService.
func
Mock
()
node
.
DAGService
{
return
dag
.
NewDAGService
(
Bserv
())
}
// Bserv returns a new, thread-safe, mock BlockService.
func
Bserv
()
bsrv
.
BlockService
{
bstore
:=
blockstore
.
NewBlockstore
(
dssync
.
MutexWrap
(
ds
.
NewMapDatastore
()))
return
bsrv
.
New
(
bstore
,
offline
.
Exchange
(
bstore
))
...
...
merkledag/utils/diff.go
浏览文件 @
699b2c4b
...
...
@@ -37,6 +37,7 @@ func (c *Change) String() string {
}
}
// ApplyChange applies the requested changes to the given node in the given dag.
func
ApplyChange
(
ctx
context
.
Context
,
ds
node
.
DAGService
,
nd
*
dag
.
ProtoNode
,
cs
[]
*
Change
)
(
*
dag
.
ProtoNode
,
error
)
{
e
:=
NewDagEditor
(
nd
,
ds
)
for
_
,
c
:=
range
cs
{
...
...
merkledag/utils/utils.go
浏览文件 @
699b2c4b
...
...
@@ -27,6 +27,7 @@ type Editor struct {
src
node
.
DAGService
}
// NewMemoryDagService returns a new, thread-safe in-memory DAGService.
func
NewMemoryDagService
()
node
.
DAGService
{
// build mem-datastore for editor's intermediary nodes
bs
:=
bstore
.
NewBlockstore
(
syncds
.
MutexWrap
(
ds
.
NewMapDatastore
()))
...
...
@@ -34,7 +35,10 @@ func NewMemoryDagService() node.DAGService {
return
dag
.
NewDAGService
(
bsrv
)
}
// root is the node to be modified, source is the dagstore to pull nodes from (optional)
// NewDagEditor returns an ProtoNode editor.
//
// * root is the node to be modified
// * source is the dagstore to pull nodes from (optional)
func
NewDagEditor
(
root
*
dag
.
ProtoNode
,
source
node
.
DAGService
)
*
Editor
{
return
&
Editor
{
root
:
root
,
...
...
@@ -43,17 +47,19 @@ func NewDagEditor(root *dag.ProtoNode, source node.DAGService) *Editor {
}
}
// GetNode returns the a copy of the root node being edited.
func
(
e
*
Editor
)
GetNode
()
*
dag
.
ProtoNode
{
return
e
.
root
.
Copy
()
.
(
*
dag
.
ProtoNode
)
}
// GetDagService returns the DAGService used by this editor.
func
(
e
*
Editor
)
GetDagService
()
node
.
DAGService
{
return
e
.
tmp
}
func
addLink
(
ctx
context
.
Context
,
ds
node
.
DAGService
,
root
*
dag
.
ProtoNode
,
childname
string
,
childnd
node
.
Node
)
(
*
dag
.
ProtoNode
,
error
)
{
if
childname
==
""
{
return
nil
,
errors
.
New
(
"cannot create link with no name
!
"
)
return
nil
,
errors
.
New
(
"cannot create link with no name"
)
}
// ensure that the node we are adding is in the dagservice
...
...
@@ -188,6 +194,8 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string)
return
root
,
nil
}
// Finalize writes the new DAG to the given DAGService and returns the modified
// root node.
func
(
e
*
Editor
)
Finalize
(
ctx
context
.
Context
,
ds
node
.
DAGService
)
(
*
dag
.
ProtoNode
,
error
)
{
nd
:=
e
.
GetNode
()
err
:=
copyDag
(
ctx
,
nd
,
e
.
tmp
,
ds
)
...
...
merkledag/utils/utils_test.go
浏览文件 @
699b2c4b
...
...
@@ -70,8 +70,8 @@ func TestInsertNode(t *testing.T) {
testInsert
(
t
,
e
,
"a/b/c/d/f"
,
"baz"
,
true
,
""
)
testInsert
(
t
,
e
,
"a/b/c/d/f"
,
"bar"
,
true
,
""
)
testInsert
(
t
,
e
,
""
,
"bar"
,
true
,
"cannot create link with no name
!
"
)
testInsert
(
t
,
e
,
"////"
,
"slashes"
,
true
,
"cannot create link with no name
!
"
)
testInsert
(
t
,
e
,
""
,
"bar"
,
true
,
"cannot create link with no name"
)
testInsert
(
t
,
e
,
"////"
,
"slashes"
,
true
,
"cannot create link with no name"
)
c
:=
e
.
GetNode
()
.
Cid
()
...
...
mfs/dir.go
浏览文件 @
699b2c4b
...
...
@@ -40,6 +40,10 @@ type Directory struct {
name
string
}
// NewDirectory constructs a new MFS directory.
//
// You probably don't want to call this directly. Instead, construct a new root
// using NewRoot.
func
NewDirectory
(
ctx
context
.
Context
,
name
string
,
node
node
.
Node
,
parent
childCloser
,
dserv
node
.
DAGService
)
(
*
Directory
,
error
)
{
db
,
err
:=
uio
.
NewDirectoryFromNode
(
dserv
,
node
)
if
err
!=
nil
{
...
...
path/resolver.go
浏览文件 @
699b2c4b
...
...
@@ -40,6 +40,7 @@ type Resolver struct {
ResolveOnce
func
(
ctx
context
.
Context
,
ds
node
.
DAGService
,
nd
node
.
Node
,
names
[]
string
)
(
*
node
.
Link
,
[]
string
,
error
)
}
// NewBasicResolver constructs a new basic resolver.
func
NewBasicResolver
(
ds
node
.
DAGService
)
*
Resolver
{
return
&
Resolver
{
DAG
:
ds
,
...
...
tar/format.go
浏览文件 @
699b2c4b
...
...
@@ -34,6 +34,8 @@ func marshalHeader(h *tar.Header) ([]byte, error) {
return
buf
.
Bytes
(),
nil
}
// ImportTar imports a tar file into the given DAGService and returns the root
// node.
func
ImportTar
(
ctx
context
.
Context
,
r
io
.
Reader
,
ds
node
.
DAGService
)
(
*
dag
.
ProtoNode
,
error
)
{
tr
:=
tar
.
NewReader
(
r
)
...
...
@@ -194,6 +196,8 @@ func (tr *tarReader) Read(b []byte) (int, error) {
return
tr
.
Read
(
b
)
}
// ExportTar exports the passed DAG as a tar file. This function is the inverse
// of ImportTar.
func
ExportTar
(
ctx
context
.
Context
,
root
*
dag
.
ProtoNode
,
ds
node
.
DAGService
)
(
io
.
Reader
,
error
)
{
if
string
(
root
.
Data
())
!=
"ipfs/tar"
{
return
nil
,
errors
.
New
(
"not an IPFS tarchive"
)
...
...
unixfs/hamt/hamt.go
浏览文件 @
699b2c4b
...
...
@@ -66,6 +66,7 @@ type child interface {
Label
()
string
}
// NewHamtShard creates a new, empty HAMT shard with the given size.
func
NewHamtShard
(
dserv
node
.
DAGService
,
size
int
)
(
*
HamtShard
,
error
)
{
ds
,
err
:=
makeHamtShard
(
dserv
,
size
)
if
err
!=
nil
{
...
...
@@ -93,6 +94,7 @@ func makeHamtShard(ds node.DAGService, size int) (*HamtShard, error) {
},
nil
}
// NewHamtFromDag creates new a HAMT shard from the given DAG.
func
NewHamtFromDag
(
dserv
node
.
DAGService
,
nd
node
.
Node
)
(
*
HamtShard
,
error
)
{
pbnd
,
ok
:=
nd
.
(
*
dag
.
ProtoNode
)
if
!
ok
{
...
...
unixfs/io/dirbuilder.go
浏览文件 @
699b2c4b
...
...
@@ -51,6 +51,8 @@ func NewDirectory(dserv node.DAGService) *Directory {
// ErrNotADir implies that the given node was not a unixfs directory
var
ErrNotADir
=
fmt
.
Errorf
(
"merkledag node was not a directory or shard"
)
// NewDirectoryFromNode loads a unixfs directory from the given IPLD node and
// DAGService.
func
NewDirectoryFromNode
(
dserv
node
.
DAGService
,
nd
node
.
Node
)
(
*
Directory
,
error
)
{
pbnd
,
ok
:=
nd
.
(
*
mdag
.
ProtoNode
)
if
!
ok
{
...
...
unixfs/io/pbdagreader.go
浏览文件 @
699b2c4b
...
...
@@ -50,6 +50,7 @@ type pbDagReader struct {
var
_
DagReader
=
(
*
pbDagReader
)(
nil
)
// NewPBFileReader constructs a new PBFileReader.
func
NewPBFileReader
(
ctx
context
.
Context
,
n
*
mdag
.
ProtoNode
,
pb
*
ftpb
.
Data
,
serv
node
.
DAGService
)
*
pbDagReader
{
fctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
curLinks
:=
getLinkCids
(
n
)
...
...
unixfs/test/utils.go
浏览文件 @
699b2c4b
...
...
@@ -27,6 +27,7 @@ func SizeSplitterGen(size int64) chunk.SplitterGen {
}
}
// GetDAGServ returns a mock DAGService.
func
GetDAGServ
()
node
.
DAGService
{
return
mdagmock
.
Mock
()
}
...
...
@@ -51,6 +52,7 @@ func init() {
UseBlake2b256
.
Prefix
.
MhLength
=
-
1
}
// GetNode returns a unixfs file node with the specified data.
func
GetNode
(
t
testing
.
TB
,
dserv
node
.
DAGService
,
data
[]
byte
,
opts
NodeOpts
)
node
.
Node
{
in
:=
bytes
.
NewReader
(
data
)
...
...
@@ -69,10 +71,12 @@ func GetNode(t testing.TB, dserv node.DAGService, data []byte, opts NodeOpts) no
return
node
}
// GetEmptyNode returns an empty unixfs file node.
func
GetEmptyNode
(
t
testing
.
TB
,
dserv
node
.
DAGService
,
opts
NodeOpts
)
node
.
Node
{
return
GetNode
(
t
,
dserv
,
[]
byte
{},
opts
)
}
// GetRandomNode returns a random unixfs file node.
func
GetRandomNode
(
t
testing
.
TB
,
dserv
node
.
DAGService
,
size
int64
,
opts
NodeOpts
)
([]
byte
,
node
.
Node
)
{
in
:=
io
.
LimitReader
(
u
.
NewTimeSeededRand
(),
size
)
buf
,
err
:=
ioutil
.
ReadAll
(
in
)
...
...
@@ -96,6 +100,7 @@ func ArrComp(a, b []byte) error {
return
nil
}
// PrintDag pretty-prints the given dag to stdout.
func
PrintDag
(
nd
*
mdag
.
ProtoNode
,
ds
node
.
DAGService
,
indent
int
)
{
pbd
,
err
:=
ft
.
FromBytes
(
nd
.
Data
())
if
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论