mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
rebase on current develop branch 2016-07-09 swarm/services/ens: * Rework ENS functionality to use the current spec. * Refactor ens.go to set up sessions as needed * Refactoring to support independent registrar and personal resolver contracts * fixed tests swarm/examples/album: improve upload UX * No more unhandled errors and loose ends in the UI. * Forward/Back buttons work as undo/redo * all long operations display an informative modal dialog * minor problems with cursor movements fixed * reorder labels * throbber as default image * change browser history after delete or upload photo swarm/storage: * optimise splitter * simplify reader * benchmarks, tests improved * simplify IO, remove chunkreader.go and io.SectionReader clone * simplify error/timeout handling * port pyramid splitter by karalabe, adapt to Splitter/DPA interface, rework params etc * make NetStore.Put -> cloud.Store synchronous * chunker join fix process leak and keep parallelisation limited to depth 1 * reset the base hash to SHA3. !!hard fork = no backward compatibility :) * SectionReader -> LazySectionReader: Size method signature change * introduce abort channel to joiner to fix process leak * add abort channel context to all manifest retrieval methods * global waitgroup fixes intermittent upload test failures due to unfinished storage of chunks * streamline joiner logic, contexts now unique to each readAt call * LazyChunkReader seeker complains about missing size only if whence=2 * chunker join fix process leak and keep parallelisation limited to depth 1 swarm/network/kademlia: * simplify code * now really fix prox limit adjustment + tests and comments * simplify and make readable findclosest algo code + comments * reset initial time interval settings for kaddb findbest * fix bucket replace scheme to optimise stability and availability * absolute idle peers are disconnected after maxIdleInterval * fix index out of range when deleting last idle peer from kaddb * unwanted peers (due to full kad bucket) are now properly dropped with ErrUnwanted * improve logging and reorg in kademlia * simplify and fix code that deletes expired/unconnectable nodes * kaddb.findBest does not get stuck on empty row but finds an actual missing node * must replace node if bucket is full otherwise nodes will get stuck on empty rows * kademlia: timer fix * remove logging the state when syncing (resulting in deadlock) * improved logs, fix potential deadlock in String() * native go time marshalling * tests fixed swarm/network: * log node address consistently in syncdb * syncer logs queue cardinalities properly in syncUnSyncedKeys loop * fix hive stop issue leading to send on closed chan + minor logging fixes * better logging * hive interface change * fix process leak by adding select to state.synced <- false swarm/cmd: swarm control cli improvements * no more alias, swarm is executable so it can be called via ssh * environment vars now set to default, no need to preconfigure * local and remote hive monitoring * gethup.sh script now merged into swarm script and nice modularised * simplify bash code and fix e2e tests in swarm/test * stop method falls back to kill -9 after 10s * enode method now supplies ip addr via ipecho request * execute, options, rawoptions, setup, create-account addpeers and hive subcommands * update-src -> update * remote-update-scripts, remote-update-bin and remote-run * local and remote monitoring of kademlia * extensive documentation in swarm/cmd/README.md * add cleanlog, cleanbzz, update-src, remote-update-scripts, remote-update-bin, remote-run * for remote binary update, take scripts from swarm/cmd/swarm * raise default maxpeers to 40 * add latency loggingo to upload and download * add checkdownload and checkaccess subcommands * add mem/cpu/disk-info commands * include randomfile cmd from test * add enode, connect subcommands, improve startup (only one round needed) * TODO: simplify tests using new checks swarm/api/http: server handler: check protocol substring length to fix slice out of bounds crash swarm/api: * fix filesystem API - upload/Modify tests * simplify downloader code and fix process leak * change KAD defaults bucketsize 4, minproxbinsize 2 * add back final slash to paths in manifest matching * fix filesystem api tests
108 lines
3.4 KiB
Go
108 lines
3.4 KiB
Go
package api
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
)
|
|
|
|
var (
|
|
hexprvkey = "65138b2aa745041b372153550584587da326ab440576b2a1191dd95cee30039c"
|
|
defaultConfig = `{
|
|
"ChunkDbPath": "` + filepath.Join("TMPDIR", "0d2f62485607cf38d9d795d93682a517661e513e", "chunks") + `",
|
|
"DbCapacity": 5000000,
|
|
"CacheCapacity": 5000,
|
|
"Radius": 0,
|
|
"Branches": 128,
|
|
"Hash": "SHA3",
|
|
"CallInterval": 3000000000,
|
|
"KadDbPath": "` + filepath.Join("TMPDIR", "0d2f62485607cf38d9d795d93682a517661e513e", "bzz-peers.json") + `",
|
|
"MaxProx": 8,
|
|
"ProxBinSize": 2,
|
|
"BucketSize": 4,
|
|
"PurgeInterval": 151200000000000,
|
|
"InitialRetryInterval": 42000000,
|
|
"MaxIdleInterval": 4200000000,
|
|
"ConnRetryExp": 2,
|
|
"Swap": {
|
|
"BuyAt": 20000000000,
|
|
"SellAt": 20000000000,
|
|
"PayAt": 100,
|
|
"DropAt": 10000,
|
|
"AutoCashInterval": 300000000000,
|
|
"AutoCashThreshold": 50000000000000,
|
|
"AutoDepositInterval": 300000000000,
|
|
"AutoDepositThreshold": 50000000000000,
|
|
"AutoDepositBuffer": 100000000000000,
|
|
"PublicKey": "0x045f5cfd26692e48d0017d380349bcf50982488bc11b5145f3ddf88b24924299048450542d43527fbe29a5cb32f38d62755393ac002e6bfdd71b8d7ba725ecd7a3",
|
|
"Contract": "0x0000000000000000000000000000000000000000",
|
|
"Beneficiary": "0x0d2f62485607cf38d9d795d93682a517661e513e"
|
|
},
|
|
"RequestDbPath": "` + filepath.Join("TMPDIR", "0d2f62485607cf38d9d795d93682a517661e513e", "requests") + `",
|
|
"RequestDbBatchSize": 512,
|
|
"KeyBufferSize": 1024,
|
|
"SyncBatchSize": 128,
|
|
"SyncBufferSize": 128,
|
|
"SyncCacheSize": 1024,
|
|
"SyncPriorities": [
|
|
2,
|
|
1,
|
|
1,
|
|
0,
|
|
0
|
|
],
|
|
"SyncModes": [
|
|
true,
|
|
true,
|
|
true,
|
|
true,
|
|
false
|
|
],
|
|
"Path": "` + filepath.Join("TMPDIR", "0d2f62485607cf38d9d795d93682a517661e513e") + `",
|
|
"Port": "8500",
|
|
"PublicKey": "0x045f5cfd26692e48d0017d380349bcf50982488bc11b5145f3ddf88b24924299048450542d43527fbe29a5cb32f38d62755393ac002e6bfdd71b8d7ba725ecd7a3",
|
|
"BzzKey": "0xe861964402c0b78e2d44098329b8545726f215afa737d803714a4338552fcb81",
|
|
"EnsRoot": "0x0000000000000000000000000000000000000000"
|
|
}`
|
|
)
|
|
|
|
func TestConfigWriteRead(t *testing.T) {
|
|
tmp, err := ioutil.TempDir(os.TempDir(), "bzz-test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(tmp)
|
|
|
|
prvkey := crypto.ToECDSA(common.Hex2Bytes(hexprvkey))
|
|
orig, err := NewConfig(tmp, common.Address{}, prvkey)
|
|
if err != nil {
|
|
t.Fatalf("expected no error, got %v", err)
|
|
}
|
|
account := crypto.PubkeyToAddress(prvkey.PublicKey)
|
|
dirpath := filepath.Join(tmp, common.Bytes2Hex(account.Bytes()))
|
|
confpath := filepath.Join(dirpath, "config.json")
|
|
data, err := ioutil.ReadFile(confpath)
|
|
if err != nil {
|
|
t.Fatalf("default config file cannot be read: %v", err)
|
|
}
|
|
exp := strings.Replace(defaultConfig, "TMPDIR", tmp, -1)
|
|
exp = strings.Replace(exp, "\\", "\\\\", -1)
|
|
|
|
if string(data) != exp {
|
|
t.Fatalf("default config mismatch:\nexpected:\n'%v'\ngot:\n'%v'", exp, string(data))
|
|
}
|
|
|
|
conf, err := NewConfig(tmp, common.Address{}, prvkey)
|
|
if err != nil {
|
|
t.Fatalf("expected no error, got %v", err)
|
|
}
|
|
if conf.Swap.Beneficiary.Hex() != orig.Swap.Beneficiary.Hex() {
|
|
t.Fatalf("expected beneficiary from loaded config %v to match original %v", conf.Swap.Beneficiary.Hex(), orig.Swap.Beneficiary.Hex())
|
|
}
|
|
|
|
}
|