Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
d50a2b56
提交
d50a2b56
authored
8月 29, 2017
作者:
Jeromy Johnson
提交者:
GitHub
8月 29, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4020 from JustinDrake/master
Do not publish public keys extractable from ID
上级
c5d362e3
cf5618c2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
127 行增加
和
6 行删除
+127
-6
publisher.go
namesys/publisher.go
+12
-6
publisher_test.go
namesys/publisher_test.go
+115
-0
没有找到文件。
namesys/publisher.go
浏览文件 @
d50a2b56
...
...
@@ -150,18 +150,24 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn
entry
.
Ttl
=
proto
.
Uint64
(
uint64
(
ttl
.
Nanoseconds
()))
}
errs
:=
make
(
chan
error
,
2
)
errs
:=
make
(
chan
error
,
2
)
// At most two errors (IPNS, and public key)
// Attempt to extract the public key from the ID
extractedPublicKey
:=
id
.
ExtractPublicKey
()
go
func
()
{
errs
<-
PublishEntry
(
ctx
,
r
,
ipnskey
,
entry
)
}()
go
func
()
{
errs
<-
PublishPublicKey
(
ctx
,
r
,
namekey
,
k
.
GetPublic
())
}()
// Publish the public key if a public key cannot be extracted from the ID
if
extractedPublicKey
==
nil
{
go
func
()
{
errs
<-
PublishPublicKey
(
ctx
,
r
,
namekey
,
k
.
GetPublic
())
}()
if
err
:=
waitOnErrChan
(
ctx
,
errs
);
err
!=
nil
{
return
err
if
err
:=
waitOnErrChan
(
ctx
,
errs
);
err
!=
nil
{
return
err
}
}
return
waitOnErrChan
(
ctx
,
errs
)
...
...
namesys/publisher_test.go
0 → 100644
浏览文件 @
d50a2b56
package
namesys
import
(
"context"
"crypto/rand"
"testing"
"time"
path
"github.com/ipfs/go-ipfs/path"
mockrouting
"github.com/ipfs/go-ipfs/routing/mock"
dshelp
"github.com/ipfs/go-ipfs/thirdparty/ds-help"
testutil
"github.com/ipfs/go-ipfs/thirdparty/testutil"
ds
"gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore"
dssync
"gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/sync"
ma
"gx/ipfs/QmXY77cVe7rVRQXZZQRioukUM7aRW3BTcAgJe12MCtb3Ji/go-multiaddr"
peer
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
ci
"gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
)
type
identity
struct
{
testutil
.
PeerNetParams
}
func
(
p
*
identity
)
ID
()
peer
.
ID
{
return
p
.
PeerNetParams
.
ID
}
func
(
p
*
identity
)
Address
()
ma
.
Multiaddr
{
return
p
.
Addr
}
func
(
p
*
identity
)
PrivateKey
()
ci
.
PrivKey
{
return
p
.
PrivKey
}
func
(
p
*
identity
)
PublicKey
()
ci
.
PubKey
{
return
p
.
PubKey
}
func
testNamekeyPublisher
(
t
*
testing
.
T
,
keyType
int
,
expectedErr
error
,
expectedExistence
bool
)
{
// Context
ctx
:=
context
.
Background
()
// Private key
privKey
,
pubKey
,
err
:=
ci
.
GenerateKeyPairWithReader
(
keyType
,
2048
,
rand
.
Reader
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// ID
var
id
peer
.
ID
switch
keyType
{
case
ci
.
Ed25519
:
id
,
err
=
peer
.
IDFromEd25519PublicKey
(
pubKey
)
default
:
id
,
err
=
peer
.
IDFromPublicKey
(
pubKey
)
}
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Value
value
:=
path
.
Path
(
"ipfs/TESTING"
)
// Seqnum
seqnum
:=
uint64
(
0
)
// Eol
eol
:=
time
.
Now
()
.
Add
(
24
*
time
.
Hour
)
// Routing value store
p
:=
testutil
.
PeerNetParams
{
ID
:
id
,
PrivKey
:
privKey
,
PubKey
:
pubKey
,
Addr
:
testutil
.
ZeroLocalTCPAddress
,
}
dstore
:=
dssync
.
MutexWrap
(
ds
.
NewMapDatastore
())
serv
:=
mockrouting
.
NewServer
()
r
:=
serv
.
ClientWithDatastore
(
context
.
Background
(),
&
identity
{
p
},
dstore
)
err
=
PutRecordToRouting
(
ctx
,
privKey
,
value
,
seqnum
,
eol
,
r
,
id
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Check for namekey existence in value store
namekey
,
_
:=
IpnsKeysForID
(
id
)
_
,
err
=
r
.
GetValue
(
ctx
,
namekey
)
if
err
!=
expectedErr
{
t
.
Fatal
(
err
)
}
// Also check datastore for completeness
key
:=
dshelp
.
NewKeyFromBinary
([]
byte
(
namekey
))
exists
,
err
:=
dstore
.
Has
(
key
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
exists
!=
expectedExistence
{
t
.
Fatal
(
"Unexpected key existence in datastore"
)
}
}
func
TestRSAPublisher
(
t
*
testing
.
T
)
{
testNamekeyPublisher
(
t
,
ci
.
RSA
,
nil
,
true
)
}
func
TestEd22519Publisher
(
t
*
testing
.
T
)
{
testNamekeyPublisher
(
t
,
ci
.
Ed25519
,
ds
.
ErrNotFound
,
false
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论