Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
be598ad1
提交
be598ad1
authored
3月 31, 2015
作者:
Jeromy Johnson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #987 from ipfs/feat/pubkey-cache
cache public keys and use better method for fetching
上级
5e3f9f35
bb1b0d50
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
36 行增加
和
25 行删除
+36
-25
routing.go
namesys/routing.go
+4
-13
records.go
routing/dht/records.go
+5
-12
routing.go
routing/routing.go
+27
-0
没有找到文件。
namesys/routing.go
浏览文件 @
be598ad1
...
...
@@ -7,7 +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"
routing
"github.com/ipfs/go-ipfs/routing"
u
"github.com/ipfs/go-ipfs/util"
)
...
...
@@ -64,25 +63,17 @@ func (r *routingResolver) Resolve(ctx context.Context, name string) (u.Key, erro
}
// name should be a public key retrievable from ipfs
// /ipfs/<name>
key
:=
u
.
Key
(
"/pk/"
+
string
(
hash
))
pkval
,
err
:=
r
.
routing
.
GetValue
(
ctx
,
key
)
pubkey
,
err
:=
routing
.
GetPublicKey
(
r
.
routing
,
ctx
,
hash
)
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
}
hsh
,
_
:=
pk
.
Hash
()
hsh
,
_
:=
pubkey
.
Hash
()
log
.
Debugf
(
"pk hash = %s"
,
u
.
Key
(
hsh
))
// check sig with pk
if
ok
,
err
:=
p
k
.
Verify
(
ipnsEntryDataForSig
(
entry
),
entry
.
GetSignature
());
err
!=
nil
||
!
ok
{
return
""
,
fmt
.
Errorf
(
"Invalid value. Not signed by PrivateKey corresponding to %v"
,
p
k
)
if
ok
,
err
:=
p
ubkey
.
Verify
(
ipnsEntryDataForSig
(
entry
),
entry
.
GetSignature
());
err
!=
nil
||
!
ok
{
return
""
,
fmt
.
Errorf
(
"Invalid value. Not signed by PrivateKey corresponding to %v"
,
p
ubkey
)
}
// ok sig checks out. this is a valid name.
...
...
routing/dht/records.go
浏览文件 @
be598ad1
...
...
@@ -6,19 +6,13 @@ 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
)
getPublicKeyOnline
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
ci
.
PubKey
,
error
)
{
func
(
dht
*
IpfsDHT
)
GetPublicKey
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
ci
.
PubKey
,
error
)
{
log
.
Debugf
(
"getPublicKey for: %s"
,
p
)
// check locally.
...
...
@@ -40,9 +34,8 @@ func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKe
// 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
)
// ok, now try the dht. Anyone who has previously fetched the key should have it
val
,
err
:=
dht
.
GetValue
(
ctxT
,
pkkey
)
if
err
!=
nil
{
log
.
Warning
(
"Failed to find requested public key."
)
...
...
@@ -66,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
...
...
@@ -132,7 +125,7 @@ func (dht *IpfsDHT) verifyRecordOnline(ctx context.Context, r *pb.Record) error
if
len
(
r
.
Signature
)
>
0
{
// get the public key, search for it if necessary.
p
:=
peer
.
ID
(
r
.
GetAuthor
())
pk
,
err
:=
dht
.
getPublicKeyOnline
(
ctx
,
p
)
pk
,
err
:=
dht
.
GetPublicKey
(
ctx
,
p
)
if
err
!=
nil
{
return
err
}
...
...
routing/routing.go
浏览文件 @
be598ad1
...
...
@@ -6,6 +6,7 @@ import (
"time"
context
"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"
u
"github.com/ipfs/go-ipfs/util"
)
...
...
@@ -46,3 +47,29 @@ type IpfsRouting interface {
// TODO expose io.Closer or plain-old Close error
}
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论