Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
bb1b0d50
提交
bb1b0d50
authored
3月 31, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address comments from PR
上级
97aeda9a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
36 行删除
+28
-36
routing.go
namesys/routing.go
+3
-27
records.go
routing/dht/records.go
+3
-9
routing.go
routing/routing.go
+22
-0
没有找到文件。
namesys/routing.go
浏览文件 @
bb1b0d50
...
...
@@ -7,8 +7,6 @@ import (
mh
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
pb
"github.com/ipfs/go-ipfs/namesys/internal/pb"
ci
"github.com/ipfs/go-ipfs/p2p/crypto"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
routing
"github.com/ipfs/go-ipfs/routing"
u
"github.com/ipfs/go-ipfs/util"
)
...
...
@@ -65,31 +63,9 @@ func (r *routingResolver) Resolve(ctx context.Context, name string) (u.Key, erro
}
// name should be a public key retrievable from ipfs
// /ipfs/<name>
var
pubkey
ci
.
PubKey
if
dht
,
ok
:=
r
.
routing
.
(
routing
.
PubKeyFetcher
);
ok
{
// If we have a DHT as our routing system, use optimized fetcher
pk
,
err
:=
dht
.
GetPublicKey
(
ctx
,
peer
.
ID
(
hash
))
if
err
!=
nil
{
log
.
Warning
(
"RoutingResolve PubKey Get failed."
)
return
""
,
err
}
pubkey
=
pk
}
else
{
key
:=
u
.
Key
(
"/pk/"
+
string
(
hash
))
pkval
,
err
:=
r
.
routing
.
GetValue
(
ctx
,
key
)
if
err
!=
nil
{
log
.
Warning
(
"RoutingResolve PubKey Get failed."
)
return
""
,
err
}
// get PublicKey from node.Data
pk
,
err
:=
ci
.
UnmarshalPublicKey
(
pkval
)
if
err
!=
nil
{
return
""
,
err
}
pubkey
=
pk
pubkey
,
err
:=
routing
.
GetPublicKey
(
r
.
routing
,
ctx
,
hash
)
if
err
!=
nil
{
return
""
,
err
}
hsh
,
_
:=
pubkey
.
Hash
()
...
...
routing/dht/records.go
浏览文件 @
bb1b0d50
...
...
@@ -6,18 +6,12 @@ import (
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
ci
"github.com/ipfs/go-ipfs/p2p/crypto"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
routing
"github.com/ipfs/go-ipfs/routing"
pb
"github.com/ipfs/go-ipfs/routing/dht/pb"
record
"github.com/ipfs/go-ipfs/routing/record"
u
"github.com/ipfs/go-ipfs/util"
ctxutil
"github.com/ipfs/go-ipfs/util/ctx"
)
// KeyForPublicKey returns the key used to retrieve public keys
// from the dht.
func
KeyForPublicKey
(
id
peer
.
ID
)
u
.
Key
{
return
u
.
Key
(
"/pk/"
+
string
(
id
))
}
func
(
dht
*
IpfsDHT
)
GetPublicKey
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
ci
.
PubKey
,
error
)
{
log
.
Debugf
(
"getPublicKey for: %s"
,
p
)
...
...
@@ -40,7 +34,7 @@ func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, err
// last ditch effort: let's try the dht.
log
.
Debugf
(
"pk for %s not in peerstore, and peer failed. trying dht."
,
p
)
pkkey
:=
KeyForPublicKey
(
p
)
pkkey
:=
routing
.
KeyForPublicKey
(
p
)
val
,
err
:=
dht
.
GetValue
(
ctxT
,
pkkey
)
if
err
!=
nil
{
...
...
@@ -65,7 +59,7 @@ func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.Pub
return
pk
,
nil
}
pkkey
:=
KeyForPublicKey
(
p
)
pkkey
:=
routing
.
KeyForPublicKey
(
p
)
pmes
,
err
:=
dht
.
getValueSingle
(
ctx
,
p
,
pkkey
)
if
err
!=
nil
{
return
nil
,
err
...
...
routing/routing.go
浏览文件 @
bb1b0d50
...
...
@@ -51,3 +51,25 @@ type IpfsRouting interface {
type
PubKeyFetcher
interface
{
GetPublicKey
(
context
.
Context
,
peer
.
ID
)
(
ci
.
PubKey
,
error
)
}
// KeyForPublicKey returns the key used to retrieve public keys
// from the dht.
func
KeyForPublicKey
(
id
peer
.
ID
)
u
.
Key
{
return
u
.
Key
(
"/pk/"
+
string
(
id
))
}
func
GetPublicKey
(
r
IpfsRouting
,
ctx
context
.
Context
,
pkhash
[]
byte
)
(
ci
.
PubKey
,
error
)
{
if
dht
,
ok
:=
r
.
(
PubKeyFetcher
);
ok
{
// If we have a DHT as our routing system, use optimized fetcher
return
dht
.
GetPublicKey
(
ctx
,
peer
.
ID
(
pkhash
))
}
else
{
key
:=
u
.
Key
(
"/pk/"
+
string
(
pkhash
))
pkval
,
err
:=
r
.
GetValue
(
ctx
,
key
)
if
err
!=
nil
{
return
nil
,
err
}
// get PublicKey from node.Data
return
ci
.
UnmarshalPublicKey
(
pkval
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论