Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
e335fd32
提交
e335fd32
authored
10月 16, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
namesys: drop prefix args
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
7dbeb27e
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
25 行增加
和
22 行删除
+25
-22
name.go
core/coreapi/interface/name.go
+2
-2
base.go
namesys/base.go
+5
-5
dns.go
namesys/dns.go
+2
-2
ipns_resolver_validation_test.go
namesys/ipns_resolver_validation_test.go
+7
-6
namesys.go
namesys/namesys.go
+2
-2
proquint.go
namesys/proquint.go
+3
-2
routing.go
namesys/routing.go
+4
-3
没有找到文件。
core/coreapi/interface/name.go
浏览文件 @
e335fd32
...
@@ -40,7 +40,7 @@ type NameAPI interface {
...
@@ -40,7 +40,7 @@ type NameAPI interface {
// Search is a version of Resolve which outputs paths as they are discovered,
// Search is a version of Resolve which outputs paths as they are discovered,
// reducing the time to first entry
// reducing the time to first entry
//
//
// Note
that by default only the last path returned before the channel closes
// Note
: by default, all paths read from the channel are considered unsafe,
//
can be considered 'safe'
.
//
except the latest (last path in channel read buffer)
.
Search
(
ctx
context
.
Context
,
name
string
,
opts
...
options
.
NameResolveOption
)
(
<-
chan
IpnsResult
,
error
)
Search
(
ctx
context
.
Context
,
name
string
,
opts
...
options
.
NameResolveOption
)
(
<-
chan
IpnsResult
,
error
)
}
}
namesys/base.go
浏览文件 @
e335fd32
...
@@ -21,14 +21,14 @@ type resolver interface {
...
@@ -21,14 +21,14 @@ type resolver interface {
}
}
// resolve is a helper for implementing Resolver.ResolveN using resolveOnce.
// resolve is a helper for implementing Resolver.ResolveN using resolveOnce.
func
resolve
(
ctx
context
.
Context
,
r
resolver
,
name
string
,
options
opts
.
ResolveOpts
,
prefix
string
)
(
path
.
Path
,
error
)
{
func
resolve
(
ctx
context
.
Context
,
r
resolver
,
name
string
,
options
opts
.
ResolveOpts
)
(
path
.
Path
,
error
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
defer
cancel
()
err
:=
ErrResolveFailed
err
:=
ErrResolveFailed
var
p
path
.
Path
var
p
path
.
Path
resCh
:=
resolveAsync
(
ctx
,
r
,
name
,
options
,
prefix
)
resCh
:=
resolveAsync
(
ctx
,
r
,
name
,
options
)
for
res
:=
range
resCh
{
for
res
:=
range
resCh
{
p
,
err
=
res
.
Path
,
res
.
Err
p
,
err
=
res
.
Path
,
res
.
Err
...
@@ -40,7 +40,7 @@ func resolve(ctx context.Context, r resolver, name string, options opts.ResolveO
...
@@ -40,7 +40,7 @@ func resolve(ctx context.Context, r resolver, name string, options opts.ResolveO
return
p
,
err
return
p
,
err
}
}
func
resolveAsync
(
ctx
context
.
Context
,
r
resolver
,
name
string
,
options
opts
.
ResolveOpts
,
prefix
string
)
<-
chan
Result
{
func
resolveAsync
(
ctx
context
.
Context
,
r
resolver
,
name
string
,
options
opts
.
ResolveOpts
)
<-
chan
Result
{
resCh
:=
r
.
resolveOnceAsync
(
ctx
,
name
,
options
)
resCh
:=
r
.
resolveOnceAsync
(
ctx
,
name
,
options
)
depth
:=
options
.
Depth
depth
:=
options
.
Depth
outCh
:=
make
(
chan
Result
,
1
)
outCh
:=
make
(
chan
Result
,
1
)
...
@@ -86,8 +86,8 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
...
@@ -86,8 +86,8 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
subCtx
,
cancelSub
=
context
.
WithCancel
(
ctx
)
subCtx
,
cancelSub
=
context
.
WithCancel
(
ctx
)
defer
cancelSub
()
defer
cancelSub
()
p
:=
strings
.
TrimPrefix
(
res
.
value
.
String
(),
p
refix
)
p
:=
strings
.
TrimPrefix
(
res
.
value
.
String
(),
ipnsP
refix
)
subCh
=
resolveAsync
(
subCtx
,
r
,
p
,
subopts
,
prefix
)
subCh
=
resolveAsync
(
subCtx
,
r
,
p
,
subopts
)
case
res
,
ok
:=
<-
subCh
:
case
res
,
ok
:=
<-
subCh
:
if
!
ok
{
if
!
ok
{
subCh
=
nil
subCh
=
nil
...
...
namesys/dns.go
浏览文件 @
e335fd32
...
@@ -28,12 +28,12 @@ func NewDNSResolver() *DNSResolver {
...
@@ -28,12 +28,12 @@ func NewDNSResolver() *DNSResolver {
// Resolve implements Resolver.
// Resolve implements Resolver.
func
(
r
*
DNSResolver
)
Resolve
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
(
path
.
Path
,
error
)
{
func
(
r
*
DNSResolver
)
Resolve
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
(
path
.
Path
,
error
)
{
return
resolve
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
)
,
"/ipns/"
)
return
resolve
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
))
}
}
// ResolveAsync implements Resolver.
// ResolveAsync implements Resolver.
func
(
r
*
DNSResolver
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
<-
chan
Result
{
func
(
r
*
DNSResolver
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
<-
chan
Result
{
return
resolveAsync
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
)
,
"/ipns/"
)
return
resolveAsync
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
))
}
}
type
lookupRes
struct
{
type
lookupRes
struct
{
...
...
namesys/ipns_resolver_validation_test.go
浏览文件 @
e335fd32
...
@@ -5,9 +5,10 @@ import (
...
@@ -5,9 +5,10 @@ import (
"testing"
"testing"
"time"
"time"
opts
"github.com/ipfs/go-ipfs/namesys/opts"
path
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
path
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
opts
"github.com/ipfs/go-ipfs/namesys/opts"
testutil
"gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil"
testutil
"gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil"
u
"gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
u
"gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
routing
"gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
routing
"gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
...
@@ -57,7 +58,7 @@ func TestResolverValidation(t *testing.T) {
...
@@ -57,7 +58,7 @@ func TestResolverValidation(t *testing.T) {
}
}
// Resolve entry
// Resolve entry
resp
,
err
:=
resolve
(
ctx
,
resolver
,
id
.
Pretty
(),
opts
.
DefaultResolveOpts
()
,
"/ipns/"
)
resp
,
err
:=
resolve
(
ctx
,
resolver
,
id
.
Pretty
(),
opts
.
DefaultResolveOpts
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -77,7 +78,7 @@ func TestResolverValidation(t *testing.T) {
...
@@ -77,7 +78,7 @@ func TestResolverValidation(t *testing.T) {
}
}
// Record should fail validation because entry is expired
// Record should fail validation because entry is expired
_
,
err
=
resolve
(
ctx
,
resolver
,
id
.
Pretty
(),
opts
.
DefaultResolveOpts
()
,
"/ipns/"
)
_
,
err
=
resolve
(
ctx
,
resolver
,
id
.
Pretty
(),
opts
.
DefaultResolveOpts
())
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"ValidateIpnsRecord should have returned error"
)
t
.
Fatal
(
"ValidateIpnsRecord should have returned error"
)
}
}
...
@@ -99,7 +100,7 @@ func TestResolverValidation(t *testing.T) {
...
@@ -99,7 +100,7 @@ func TestResolverValidation(t *testing.T) {
// Record should fail validation because public key defined by
// Record should fail validation because public key defined by
// ipns path doesn't match record signature
// ipns path doesn't match record signature
_
,
err
=
resolve
(
ctx
,
resolver
,
id2
.
Pretty
(),
opts
.
DefaultResolveOpts
()
,
"/ipns/"
)
_
,
err
=
resolve
(
ctx
,
resolver
,
id2
.
Pretty
(),
opts
.
DefaultResolveOpts
())
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"ValidateIpnsRecord should have failed signature verification"
)
t
.
Fatal
(
"ValidateIpnsRecord should have failed signature verification"
)
}
}
...
@@ -117,7 +118,7 @@ func TestResolverValidation(t *testing.T) {
...
@@ -117,7 +118,7 @@ func TestResolverValidation(t *testing.T) {
// Record should fail validation because public key is not available
// Record should fail validation because public key is not available
// in peer store or on network
// in peer store or on network
_
,
err
=
resolve
(
ctx
,
resolver
,
id3
.
Pretty
(),
opts
.
DefaultResolveOpts
()
,
"/ipns/"
)
_
,
err
=
resolve
(
ctx
,
resolver
,
id3
.
Pretty
(),
opts
.
DefaultResolveOpts
())
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"ValidateIpnsRecord should have failed because public key was not found"
)
t
.
Fatal
(
"ValidateIpnsRecord should have failed because public key was not found"
)
}
}
...
@@ -132,7 +133,7 @@ func TestResolverValidation(t *testing.T) {
...
@@ -132,7 +133,7 @@ func TestResolverValidation(t *testing.T) {
// public key is available in the peer store by looking it up in
// public key is available in the peer store by looking it up in
// the DHT, which causes the DHT to fetch it and cache it in the
// the DHT, which causes the DHT to fetch it and cache it in the
// peer store
// peer store
_
,
err
=
resolve
(
ctx
,
resolver
,
id3
.
Pretty
(),
opts
.
DefaultResolveOpts
()
,
"/ipns/"
)
_
,
err
=
resolve
(
ctx
,
resolver
,
id3
.
Pretty
(),
opts
.
DefaultResolveOpts
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
namesys/namesys.go
浏览文件 @
e335fd32
...
@@ -62,7 +62,7 @@ func (ns *mpns) Resolve(ctx context.Context, name string, options ...opts.Resolv
...
@@ -62,7 +62,7 @@ func (ns *mpns) Resolve(ctx context.Context, name string, options ...opts.Resolv
return
path
.
ParsePath
(
"/ipfs/"
+
name
)
return
path
.
ParsePath
(
"/ipfs/"
+
name
)
}
}
return
resolve
(
ctx
,
ns
,
name
,
opts
.
ProcessOpts
(
options
)
,
"/ipns/"
)
return
resolve
(
ctx
,
ns
,
name
,
opts
.
ProcessOpts
(
options
))
}
}
func
(
ns
*
mpns
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
<-
chan
Result
{
func
(
ns
*
mpns
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
<-
chan
Result
{
...
@@ -79,7 +79,7 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R
...
@@ -79,7 +79,7 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R
return
res
return
res
}
}
return
resolveAsync
(
ctx
,
ns
,
name
,
opts
.
ProcessOpts
(
options
)
,
"/ipns/"
)
return
resolveAsync
(
ctx
,
ns
,
name
,
opts
.
ProcessOpts
(
options
))
}
}
// resolveOnce implements resolver.
// resolveOnce implements resolver.
...
...
namesys/proquint.go
浏览文件 @
e335fd32
...
@@ -4,16 +4,17 @@ import (
...
@@ -4,16 +4,17 @@ import (
"context"
"context"
"errors"
"errors"
opts
"github.com/ipfs/go-ipfs/namesys/opts"
proquint
"gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint"
proquint
"gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint"
path
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
path
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
opts
"github.com/ipfs/go-ipfs/namesys/opts"
)
)
type
ProquintResolver
struct
{}
type
ProquintResolver
struct
{}
// Resolve implements Resolver.
// Resolve implements Resolver.
func
(
r
*
ProquintResolver
)
Resolve
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
(
path
.
Path
,
error
)
{
func
(
r
*
ProquintResolver
)
Resolve
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
(
path
.
Path
,
error
)
{
return
resolve
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
)
,
"/ipns/"
)
return
resolve
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
))
}
}
// resolveOnce implements resolver. Decodes the proquint string.
// resolveOnce implements resolver. Decodes the proquint string.
...
...
namesys/routing.go
浏览文件 @
e335fd32
...
@@ -5,9 +5,10 @@ import (
...
@@ -5,9 +5,10 @@ import (
"strings"
"strings"
"time"
"time"
opts
"github.com/ipfs/go-ipfs/namesys/opts"
path
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
path
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
opts
"github.com/ipfs/go-ipfs/namesys/opts"
cid
"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
cid
"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
routing
"gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
routing
"gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
mh
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
mh
"gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
...
@@ -39,12 +40,12 @@ func NewIpnsResolver(route routing.ValueStore) *IpnsResolver {
...
@@ -39,12 +40,12 @@ func NewIpnsResolver(route routing.ValueStore) *IpnsResolver {
// Resolve implements Resolver.
// Resolve implements Resolver.
func
(
r
*
IpnsResolver
)
Resolve
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
(
path
.
Path
,
error
)
{
func
(
r
*
IpnsResolver
)
Resolve
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
(
path
.
Path
,
error
)
{
return
resolve
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
)
,
"/ipns/"
)
return
resolve
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
))
}
}
// ResolveAsync implements Resolver.
// ResolveAsync implements Resolver.
func
(
r
*
IpnsResolver
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
<-
chan
Result
{
func
(
r
*
IpnsResolver
)
ResolveAsync
(
ctx
context
.
Context
,
name
string
,
options
...
opts
.
ResolveOpt
)
<-
chan
Result
{
return
resolveAsync
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
)
,
"/ipns/"
)
return
resolveAsync
(
ctx
,
r
,
name
,
opts
.
ProcessOpts
(
options
))
}
}
// resolveOnce implements resolver. Uses the IPFS routing system to
// resolveOnce implements resolver. Uses the IPFS routing system to
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论