Skip to content

Commit 4d59db2

Browse files
Arachnidzelig
authored andcommitted
swarm/services/ens:
* Fix tests by including ENS contracts to deploy * update bin with bytecode compiled with solc v0.3.5-0 * update go bindings with abigen * complete README with generate instructions * simplify ens.Resolve removing legacy versioning support * remove glogging from test swarm/network: guard against short data in store requests cmd/utils: add missing file input.go for relocated UnlockAccount
1 parent 0460fba commit 4d59db2

File tree

12 files changed

+964
-22
lines changed

12 files changed

+964
-22
lines changed

cmd/utils/input.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2016 The go-ethereum Authors
2+
// This file is part of go-ethereum.
3+
//
4+
// go-ethereum is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// go-ethereum is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package utils
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/ethereum/go-ethereum/accounts"
23+
// "strings"
24+
"github.com/ethereum/go-ethereum/console"
25+
"github.com/ethereum/go-ethereum/logger"
26+
"github.com/ethereum/go-ethereum/logger/glog"
27+
"gopkg.in/urfave/cli.v1"
28+
// "github.com/peterh/liner"
29+
)
30+
31+
// tries unlocking the specified account a few times.
32+
func UnlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i int, passwords []string) (accounts.Account, string) {
33+
account, err := MakeAddress(accman, address)
34+
if err != nil {
35+
Fatalf("Could not list accounts: %v", err)
36+
}
37+
for trials := 0; trials < 3; trials++ {
38+
prompt := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", address, trials+1, 3)
39+
password := GetPassPhrase(prompt, false, i, passwords)
40+
err = accman.Unlock(account, password)
41+
if err == nil {
42+
glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
43+
return account, password
44+
}
45+
if err, ok := err.(*accounts.AmbiguousAddrError); ok {
46+
glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
47+
return AmbiguousAddrRecovery(accman, err, password), password
48+
}
49+
if err != accounts.ErrDecrypt {
50+
// No need to prompt again if the error is not decryption-related.
51+
break
52+
}
53+
}
54+
// All trials expended to unlock account, bail out
55+
Fatalf("Failed to unlock account %s (%v)", address, err)
56+
return accounts.Account{}, ""
57+
}
58+
59+
// getPassPhrase retrieves the passwor associated with an account, either fetched
60+
// from a list of preloaded passphrases, or requested interactively from the user.
61+
func GetPassPhrase(prompt string, confirmation bool, i int, passwords []string) string {
62+
// If a list of passwords was supplied, retrieve from them
63+
if len(passwords) > 0 {
64+
if i < len(passwords) {
65+
return passwords[i]
66+
}
67+
return passwords[len(passwords)-1]
68+
}
69+
// Otherwise prompt the user for the password
70+
if prompt != "" {
71+
fmt.Println(prompt)
72+
}
73+
password, err := console.Stdin.PromptPassword("Passphrase: ")
74+
if err != nil {
75+
Fatalf("Failed to read passphrase: %v", err)
76+
}
77+
if confirmation {
78+
confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ")
79+
if err != nil {
80+
Fatalf("Failed to read passphrase confirmation: %v", err)
81+
}
82+
if password != confirm {
83+
Fatalf("Passphrases do not match")
84+
}
85+
}
86+
return password
87+
}
88+
89+
func AmbiguousAddrRecovery(am *accounts.Manager, err *accounts.AmbiguousAddrError, auth string) accounts.Account {
90+
fmt.Printf("Multiple key files exist for address %x:\n", err.Addr)
91+
for _, a := range err.Matches {
92+
fmt.Println(" ", a.File)
93+
}
94+
fmt.Println("Testing your passphrase against all of them...")
95+
var match *accounts.Account
96+
for _, a := range err.Matches {
97+
if err := am.Unlock(a, auth); err == nil {
98+
match = &a
99+
break
100+
}
101+
}
102+
if match == nil {
103+
Fatalf("None of the listed files could be unlocked.")
104+
}
105+
fmt.Printf("Your passphrase unlocked %s\n", match.File)
106+
fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
107+
for _, a := range err.Matches {
108+
if a != *match {
109+
fmt.Println(" ", a.File)
110+
}
111+
}
112+
return *match
113+
}

swarm/network/depo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (self *Depo) HandleStoreRequestMsg(req *storeRequestMsgData, p *peer) {
112112
}
113113

114114
// update chunk with size and data
115-
chunk.SData = req.SData
115+
chunk.SData = req.SData // protocol validates that SData is minimum 9 bytes long (int64 size + at least one byte of data)
116116
chunk.Size = int64(binary.LittleEndian.Uint64(req.SData[0:8]))
117117
glog.V(logger.Detail).Infof("[BZZ] delivery of %p from %v", chunk, p)
118118
chunk.Source = p
@@ -136,7 +136,7 @@ func (self *Depo) HandleRetrieveRequestMsg(req *retrieveRequestMsgData, p *peer)
136136

137137
// call storage.NetStore#Get which
138138
// blocks until local retrieval finished
139-
// launches cloud retrieval in a separate go routine
139+
// launches cloud retrieval
140140
chunk, _ := self.netStore.Get(req.Key)
141141
req = self.strategyUpdateRequest(chunk.Req, req)
142142
// check if we can immediately deliver

swarm/network/protocol.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func (self *bzz) handle() error {
226226
if err := msg.Decode(&req); err != nil {
227227
return self.protoError(ErrDecode, "<- %v: %v", msg, err)
228228
}
229+
if len(req.SData) < 9 {
230+
return self.protoError(ErrDecode, "<- %v: Data too short (%v)", msg)
231+
}
229232
glog.V(logger.Detail).Infof("[BZZ] incoming store request: %s", req.String())
230233
// swap accounting is done within forwarding
231234
self.storage.HandleStoreRequestMsg(&req, &peer{bzz: self})

swarm/services/ens/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Swarm ENS interface
2+
3+
The ABI and BIN files in contract subdirectory implement simple registrar and personal resolver contracts; they're used in tests, and can be used to deploy these contracts for your own purposes.
4+
5+
The solidity source code can be found at [github.com/arachnid/ens/](https://github.com/arachnid/ens/).
6+
7+
The ABI and BIN files in the contract subdirectory were generated by
8+
9+
```shell
10+
solc -o `pwd` --optimise --abi --bin OpenRegistrar.sol
11+
solc -o `pwd` --optimise --abi --bin PersonalResolver.sol
12+
```
13+
14+
using the .sol files in [revision 8b38b23a23100d5c325ae3fa24935f5ab93d61ba](https://github.com/Arachnid/ens/commit/8b38b23a23100d5c325ae3fa24935f5ab93d61ba)
15+
with solc version 0.3.5-0/RelWithDebInfo-Linux/g++/Interpreter
16+
17+
The go bindings for ENS contracts are generated using `abigen` via the go generator:
18+
19+
```shell
20+
godep go generate ./swarm/services/ens
21+
```
22+
23+
see the preprocessor directives in leading comments of ens.go and ens_test.go
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"constant":false,"inputs":[{"name":"label","type":"bytes32"},{"name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"id","type":"bytes32"}],"name":"getExtended","outputs":[{"name":"data","type":"bytes"}],"type":"function"},{"constant":true,"inputs":[{"name":"nodeId","type":"bytes12"},{"name":"qtype","type":"bytes32"},{"name":"index","type":"uint16"}],"name":"resolve","outputs":[{"name":"rcode","type":"uint16"},{"name":"rtype","type":"bytes16"},{"name":"ttl","type":"uint32"},{"name":"len","type":"uint16"},{"name":"data","type":"bytes32"}],"type":"function"},{"constant":false,"inputs":[{"name":"label","type":"bytes32"},{"name":"resolver","type":"address"},{"name":"nodeId","type":"bytes12"}],"name":"register","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"label","type":"bytes32"},{"name":"resolver","type":"address"},{"name":"nodeId","type":"bytes12"}],"name":"setResolver","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"label","type":"bytes32"}],"name":"getOwner","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[{"name":"nodeId","type":"bytes12"},{"name":"label","type":"bytes32"}],"name":"findResolver","outputs":[{"name":"rcode","type":"uint16"},{"name":"ttl","type":"uint32"},{"name":"rnode","type":"bytes12"},{"name":"raddress","type":"address"}],"type":"function"}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
60606040526103b1806100126000396000f3606060405236156100615760e060020a60003504635b0fc9c381146100635780638021061c14610085578063a16fdafa146100a2578063a1f8f8f0146100d5578063a9f2a1b2146100fa578063deb931a21461011f578063edc0277c14610145575b005b610061600435602435600081600160a060020a03166000141561028157610002565b6101956004356000606081905260a060405260809081525b919050565b610203600435602435604435600080808080600160a060020a0319881681146100ca57600394505b939792965093509350565b610061600435602435604435600082600160a060020a0316600014156102c157610002565b610061600435602435604435600082600160a060020a03166000141561033657610002565b610229600435600081815260208190526040902060010154600160a060020a031661009d565b6102466004356024356000818152602081905260408120819081908190600160a060020a031987168214158061018757506001810154600160a060020a031682145b1561038957600394506103a7565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101f55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b50505061ffff919091166060908152608082905260a082815260c083905260e092909252f35b60408051600160a060020a03929092168252519081900360200190f35b61ffff93909316606090815263ffffffff929092166080908152600160a060020a03199190911660a052600160a060020a039290921660c052f35b828152602081905260409020600181015433600160a060020a039081169116146102aa57610002565b6001018054600160a060020a031916909117905550565b83815260208190526040812060018101549091600160a060020a03909116146102e957610002565b60018101805460c0604052606085905260808490523360a08190528354600160a060020a03199081168717600160a060020a031660a060020a808804021785559190911617905550505050565b838152602081905260409020600181015433600160a060020a0390811691161461035f57610002565b8054600160a060020a031916909217600160a060020a031660a060020a9182900490910217905550565b8054610e10945060a060020a808204029350600160a060020a031691505b509295919450925056

0 commit comments

Comments
 (0)