Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
409b61fe
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
409b61fe
编写于
4月 13, 2017
作者:
H
holisticode
提交者:
Felix Lange
4月 13, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
swarm/api: better name resolver handling (#3754)
Fixes #3608
上级
d5d910e8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
16 deletion
+53
-16
cmd/swarm/main.go
cmd/swarm/main.go
+2
-0
swarm/api/api.go
swarm/api/api.go
+15
-13
swarm/api/http/server_test.go
swarm/api/http/server_test.go
+28
-0
swarm/swarm.go
swarm/swarm.go
+8
-3
未找到文件。
cmd/swarm/main.go
浏览文件 @
409b61fe
...
...
@@ -358,6 +358,8 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
if
err
!=
nil
{
utils
.
Fatalf
(
"Can't connect: %v"
,
err
)
}
}
else
{
swapEnabled
=
false
}
return
swarm
.
NewSwarm
(
ctx
,
client
,
bzzconfig
,
swapEnabled
,
syncEnabled
,
cors
)
}
...
...
swarm/api/api.go
浏览文件 @
409b61fe
...
...
@@ -17,7 +17,6 @@
package
api
import
(
"errors"
"fmt"
"io"
"net/http"
...
...
@@ -84,25 +83,28 @@ type ErrResolve error
// DNS Resolver
func
(
self
*
Api
)
Resolve
(
uri
*
URI
)
(
storage
.
Key
,
error
)
{
log
.
Trace
(
fmt
.
Sprintf
(
"Resolving : %v"
,
uri
.
Addr
))
var
err
error
if
!
uri
.
Immutable
()
{
if
self
.
dns
!=
nil
{
resolved
,
err
:=
self
.
dns
.
Resolve
(
uri
.
Addr
)
if
err
==
nil
{
return
resolved
[
:
],
nil
}
}
else
{
err
=
fmt
.
Errorf
(
"no DNS to resolve name"
)
}
}
if
hashMatcher
.
MatchString
(
uri
.
Addr
)
{
log
.
Trace
(
fmt
.
Sprintf
(
"addr is a hash: %q"
,
uri
.
Addr
))
return
storage
.
Key
(
common
.
Hex2Bytes
(
uri
.
Addr
)),
nil
}
if
uri
.
Immutable
()
{
return
nil
,
errors
.
New
(
"refusing to resolve immutable address"
)
}
if
self
.
dns
==
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to resolve addr %q, resolver not configured"
,
uri
.
Addr
)
}
hash
,
err
:=
self
.
dns
.
Resolve
(
uri
.
Addr
)
if
err
!=
nil
{
log
.
Warn
(
fmt
.
Sprintf
(
"DNS error resolving addr %q: %s"
,
uri
.
Addr
,
err
))
return
nil
,
ErrResolve
(
err
)
return
nil
,
fmt
.
Errorf
(
"'%s' does not resolve: %v but is not a content hash"
,
uri
.
Addr
,
err
)
}
log
.
Trace
(
fmt
.
Sprintf
(
"addr lookup: %v -> %v"
,
uri
.
Addr
,
hash
))
return
hash
[
:
],
nil
return
nil
,
fmt
.
Errorf
(
"'%s' is not a content hash"
,
uri
.
Addr
)
}
// Put provides singleton manifest creation on top of dpa store
func
(
self
*
Api
)
Put
(
content
,
contentType
string
)
(
storage
.
Key
,
error
)
{
r
:=
strings
.
NewReader
(
content
)
...
...
swarm/api/http/server_test.go
浏览文件 @
409b61fe
...
...
@@ -99,4 +99,32 @@ func TestBzzrGetPath(t *testing.T) {
}
}
nonhashtests
:=
[]
string
{
srv
.
URL
+
"/bzz:/name"
,
srv
.
URL
+
"/bzzi:/nonhash"
,
srv
.
URL
+
"/bzzr:/nonhash"
,
}
nonhashresponses
:=
[]
string
{
"error resolving name: 'name' does not resolve: no DNS to resolve name but is not a content hash
\n
"
,
"error resolving nonhash: 'nonhash' is not a content hash
\n
"
,
"error resolving nonhash: 'nonhash' does not resolve: no DNS to resolve name but is not a content hash
\n
"
,
}
for
i
,
url
:=
range
nonhashtests
{
var
resp
*
http
.
Response
var
respbody
[]
byte
resp
,
err
=
http
.
Get
(
url
)
if
err
!=
nil
{
t
.
Fatalf
(
"Request failed: %v"
,
err
)
}
defer
resp
.
Body
.
Close
()
respbody
,
err
=
ioutil
.
ReadAll
(
resp
.
Body
)
if
string
(
respbody
)
!=
nonhashresponses
[
i
]
{
t
.
Fatalf
(
"Non-Hash response body does not match, expected: %v, got: %v"
,
nonhashresponses
[
i
],
string
(
respbody
))
}
}
}
swarm/swarm.go
浏览文件 @
409b61fe
...
...
@@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/contracts/chequebook"
"github.com/ethereum/go-ethereum/contracts/ens"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
...
...
@@ -134,9 +135,13 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
// set up high level api
transactOpts
:=
bind
.
NewKeyedTransactor
(
self
.
privateKey
)
self
.
dns
,
err
=
ens
.
NewENS
(
transactOpts
,
config
.
EnsRoot
,
self
.
backend
)
if
err
!=
nil
{
return
nil
,
err
if
backend
==
(
*
ethclient
.
Client
)(
nil
)
{
log
.
Warn
(
"No ENS, please specify non-empty --ethapi to use domain name resolution"
)
}
else
{
self
.
dns
,
err
=
ens
.
NewENS
(
transactOpts
,
config
.
EnsRoot
,
self
.
backend
)
if
err
!=
nil
{
return
nil
,
err
}
}
log
.
Debug
(
fmt
.
Sprintf
(
"-> Swarm Domain Name Registrar @ address %v"
,
config
.
EnsRoot
.
Hex
()))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录