Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7f5e1371
提交
7f5e1371
authored
9月 25, 2014
作者:
Jeromy
提交者:
Juan Batiz-Benet
10月 01, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
writes to ipns work if the top object is the written file (no directories yet!)
上级
e61c5975
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
118 行增加
和
4 行删除
+118
-4
core.go
core/core.go
+5
-0
ipns_unix.go
fuse/ipns/ipns_unix.go
+112
-3
routing.go
routing/dht/routing.go
+1
-1
没有找到文件。
core/core.go
浏览文件 @
7f5e1371
...
...
@@ -62,6 +62,9 @@ type IpfsNode struct {
// the name system, resolves paths to hashes
Namesys
namesys
.
Resolver
// the routing publisher
Publisher
*
namesys
.
IpnsPublisher
}
// NewIpfsNode constructs a new IpfsNode based on the given config.
...
...
@@ -144,6 +147,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
dag
:=
&
merkledag
.
DAGService
{
Blocks
:
bs
}
resolve
:=
namesys
.
NewMasterResolver
(
route
,
dag
)
publisher
:=
namesys
.
NewPublisher
(
dag
,
route
)
success
=
true
return
&
IpfsNode
{
...
...
@@ -157,6 +161,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
Identity
:
local
,
Routing
:
route
,
Namesys
:
resolve
,
Publisher
:
publisher
,
},
nil
}
...
...
fuse/ipns/ipns_unix.go
浏览文件 @
7f5e1371
...
...
@@ -11,11 +11,14 @@ import (
"syscall"
"time"
"bytes"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"code.google.com/p/goprotobuf/proto"
"github.com/jbenet/go-ipfs/core"
ci
"github.com/jbenet/go-ipfs/crypto"
imp
"github.com/jbenet/go-ipfs/importer"
mdag
"github.com/jbenet/go-ipfs/merkledag"
u
"github.com/jbenet/go-ipfs/util"
"github.com/op/go-logging"
...
...
@@ -63,6 +66,33 @@ func CreateRoot(n *core.IpfsNode, keys []ci.PrivKey, ipfsroot string) (*Root, er
root
.
LocalLink
=
&
Link
{
u
.
Key
(
hash
)
.
Pretty
()}
}
for
_
,
k
:=
range
keys
{
hash
,
err
:=
k
.
GetPublic
()
.
Hash
()
if
err
!=
nil
{
log
.
Error
(
"failed to hash public key."
)
continue
}
name
:=
u
.
Key
(
hash
)
.
Pretty
()
nd
:=
new
(
Node
)
nd
.
Ipfs
=
n
nd
.
key
=
k
pointsTo
,
err
:=
n
.
Namesys
.
Resolve
(
name
)
if
err
!=
nil
{
log
.
Warning
(
"Could not resolve value for local ipns entry"
)
continue
}
node
,
err
:=
n
.
Resolver
.
ResolvePath
(
pointsTo
)
if
err
!=
nil
{
log
.
Warning
(
"Failed to resolve value from ipns entry in ipfs"
)
continue
}
nd
.
Nd
=
node
root
.
LocalDirs
[
name
]
=
nd
}
return
root
,
nil
}
...
...
@@ -147,10 +177,17 @@ func (r *Root) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
// Node is the core object representing a filesystem tree node.
type
Node
struct
{
nsRoot
*
Node
// Private keys held by nodes at the root of a keyspace
key
ci
.
PrivKey
Ipfs
*
core
.
IpfsNode
Nd
*
mdag
.
Node
fd
*
mdag
.
DagReader
cached
*
mdag
.
PBData
dataBuf
*
bytes
.
Buffer
changed
bool
}
func
(
s
*
Node
)
loadData
()
error
{
...
...
@@ -172,7 +209,7 @@ func (s *Node) Attr() fuse.Attr {
u
.
DOut
(
"this is a file.
\n
"
)
size
,
_
:=
s
.
Nd
.
Size
()
return
fuse
.
Attr
{
Mode
:
0
444
,
Mode
:
0
666
,
Size
:
uint64
(
size
),
Blocks
:
uint64
(
len
(
s
.
Nd
.
Links
)),
}
...
...
@@ -184,14 +221,25 @@ func (s *Node) Attr() fuse.Attr {
// Lookup performs a lookup under this node.
func
(
s
*
Node
)
Lookup
(
name
string
,
intr
fs
.
Intr
)
(
fs
.
Node
,
fuse
.
Error
)
{
u
.
DOut
(
"Lookup '%s'
\n
"
,
name
)
log
.
Debug
(
"ipns node Lookup '%s'
"
,
name
)
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolveLinks
(
s
.
Nd
,
[]
string
{
name
})
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
return
&
Node
{
Ipfs
:
s
.
Ipfs
,
Nd
:
nd
},
nil
child
:=
&
Node
{
Ipfs
:
s
.
Ipfs
,
Nd
:
nd
,
}
if
s
.
nsRoot
==
nil
{
child
.
nsRoot
=
s
}
else
{
child
.
nsRoot
=
s
.
nsRoot
}
return
child
,
nil
}
// ReadDir reads the link structure as directory entries
...
...
@@ -224,6 +272,67 @@ func (s *Node) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
return
ioutil
.
ReadAll
(
r
)
}
func
(
n
*
Node
)
Write
(
req
*
fuse
.
WriteRequest
,
resp
*
fuse
.
WriteResponse
,
intr
fs
.
Intr
)
fuse
.
Error
{
if
n
.
dataBuf
==
nil
{
n
.
dataBuf
=
new
(
bytes
.
Buffer
)
}
log
.
Debug
(
"ipns Node Write: flags = %s, offset = %d, size = %d"
,
req
.
Flags
.
String
(),
req
.
Offset
,
len
(
req
.
Data
))
if
req
.
Offset
==
0
{
n
.
dataBuf
.
Reset
()
n
.
dataBuf
.
Write
(
req
.
Data
)
n
.
changed
=
true
resp
.
Size
=
len
(
req
.
Data
)
}
else
{
log
.
Error
(
"Unhandled write to offset!"
)
}
return
nil
}
func
(
n
*
Node
)
Flush
(
req
*
fuse
.
FlushRequest
,
intr
fs
.
Intr
)
fuse
.
Error
{
log
.
Debug
(
"Got flush request!"
)
if
n
.
changed
{
//TODO:
// This operation holds everything in memory,
// should be changed to stream the block creation/storage
// but for now, since the buf is all in memory anyways...
nnode
,
err
:=
imp
.
NewDagFromReader
(
n
.
dataBuf
)
if
err
!=
nil
{
log
.
Error
(
"ipns Flush error: %s"
,
err
)
// return fuse.EVERYBAD
return
fuse
.
ENODATA
}
err
=
n
.
Ipfs
.
DAG
.
AddRecursive
(
nnode
)
if
err
!=
nil
{
log
.
Critical
(
"ipns Dag Add Error: %s"
,
err
)
}
n
.
Nd
=
nnode
n
.
changed
=
false
n
.
dataBuf
=
nil
ndkey
,
err
:=
nnode
.
Key
()
if
err
!=
nil
{
log
.
Error
(
"getKey error: %s"
,
err
)
// return fuse.ETHISREALLYSUCKS
return
fuse
.
ENODATA
}
log
.
Debug
(
"Publishing changes!"
)
err
=
n
.
Ipfs
.
Publisher
.
Publish
(
n
.
key
,
ndkey
)
if
err
!=
nil
{
log
.
Error
(
"ipns Publish Failed: %s"
,
err
)
}
}
return
nil
}
func
(
n
*
Node
)
Fsync
(
req
*
fuse
.
FsyncRequest
,
intr
fs
.
Intr
)
fuse
.
Error
{
log
.
Debug
(
"Got fsync request!"
)
return
nil
}
// Mount mounts an IpfsNode instance at a particular path. It
// serves until the process receives exit signals (to Unmount).
func
Mount
(
ipfs
*
core
.
IpfsNode
,
fpath
string
,
ipfspath
string
)
error
{
...
...
routing/dht/routing.go
浏览文件 @
7f5e1371
...
...
@@ -103,7 +103,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
dht
.
providers
.
AddProvider
(
key
,
dht
.
self
)
peers
:=
dht
.
routingTables
[
0
]
.
NearestPeers
(
kb
.
ConvertKey
(
key
),
PoolSize
)
if
len
(
peers
)
==
0
{
return
kb
.
ErrLookupFailure
return
nil
}
//TODO FIX: this doesn't work! it needs to be sent to the actual nearest peers.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论