good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
409b61fe
Commit
409b61fe
authored
7 years ago
by
holisticode
Committed by
Felix Lange
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
swarm/api: better name resolver handling (#3754)
Fixes #3608
parent
d5d910e8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/swarm/main.go
+2
-0
2 additions, 0 deletions
cmd/swarm/main.go
swarm/api/api.go
+15
-13
15 additions, 13 deletions
swarm/api/api.go
swarm/api/http/server_test.go
+28
-0
28 additions, 0 deletions
swarm/api/http/server_test.go
swarm/swarm.go
+8
-3
8 additions, 3 deletions
swarm/swarm.go
with
53 additions
and
16 deletions
cmd/swarm/main.go
+
2
−
0
View file @
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
)
}
...
...
This diff is collapsed.
Click to expand it.
swarm/api/api.go
+
15
−
13
View file @
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
)
...
...
This diff is collapsed.
Click to expand it.
swarm/api/http/server_test.go
+
28
−
0
View file @
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
))
}
}
}
This diff is collapsed.
Click to expand it.
swarm/swarm.go
+
8
−
3
View file @
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
()))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment