diff options
author | Viktor TrĂ³n <viktor.tron@gmail.com> | 2016-11-28 20:29:33 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-11-28 20:29:33 +0800 |
commit | e949a2ed2f1c59ed5ff1f187ad987c882656e6ef (patch) | |
tree | 836c8b977ef61ddbc8163f70cbed118825822cbe /swarm | |
parent | 8d0108fc5df81c71010b9dfb11a5db5658fcb80a (diff) | |
download | go-tangerine-e949a2ed2f1c59ed5ff1f187ad987c882656e6ef.tar go-tangerine-e949a2ed2f1c59ed5ff1f187ad987c882656e6ef.tar.gz go-tangerine-e949a2ed2f1c59ed5ff1f187ad987c882656e6ef.tar.bz2 go-tangerine-e949a2ed2f1c59ed5ff1f187ad987c882656e6ef.tar.lz go-tangerine-e949a2ed2f1c59ed5ff1f187ad987c882656e6ef.tar.xz go-tangerine-e949a2ed2f1c59ed5ff1f187ad987c882656e6ef.tar.zst go-tangerine-e949a2ed2f1c59ed5ff1f187ad987c882656e6ef.zip |
cmd/bzzd: swarm daemon fixes (#3359)
* cmd/bzzd: add missing p2p/discovery flags
* cmd/bzzd: fix two bugs crashing bzzd if bootnodes flag given
* cmd/bzzd: make no swap default, renamed flag bzznoswap->bzzswap
* internal/web3ext: correct methods for bzz IPC module
* cmd/bzzd: ethapi param not mandatory. Warning if no blockchain
* cmd/bzzd: correct default IPC modules in help string
* cmd/utils: fix help description for networkId - add Ropsten
* cmd/bzz, swarm/api, swarm/network: add swarm networkId flag
* cmd/bzzd: change nosync flag to sync and BootTFlag
Diffstat (limited to 'swarm')
-rw-r--r-- | swarm/api/config.go | 4 | ||||
-rw-r--r-- | swarm/api/config_test.go | 7 | ||||
-rw-r--r-- | swarm/network/protocol.go | 18 | ||||
-rw-r--r-- | swarm/swarm.go | 4 |
4 files changed, 20 insertions, 13 deletions
diff --git a/swarm/api/config.go b/swarm/api/config.go index c04a015ef..f9d3575f7 100644 --- a/swarm/api/config.go +++ b/swarm/api/config.go @@ -54,11 +54,12 @@ type Config struct { PublicKey string BzzKey string EnsRoot common.Address + NetworkId uint64 } // config is agnostic to where private key is coming from // so managing accounts is outside swarm and left to wrappers -func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey) (self *Config, err error) { +func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey, networkId uint64) (self *Config, err error) { address := crypto.PubkeyToAddress(prvKey.PublicKey) // default beneficiary address dirpath := filepath.Join(path, "bzz-"+common.Bytes2Hex(address.Bytes())) err = os.MkdirAll(dirpath, os.ModePerm) @@ -82,6 +83,7 @@ func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey) ( PublicKey: pubkeyhex, BzzKey: keyhex, EnsRoot: toyNetEnsRoot, + NetworkId: networkId, } data, err = ioutil.ReadFile(confpath) if err != nil { diff --git a/swarm/api/config_test.go b/swarm/api/config_test.go index 8fe3ddacc..39ac2d067 100644 --- a/swarm/api/config_test.go +++ b/swarm/api/config_test.go @@ -83,7 +83,8 @@ var ( "Port": "8500", "PublicKey": "0x045f5cfd26692e48d0017d380349bcf50982488bc11b5145f3ddf88b24924299048450542d43527fbe29a5cb32f38d62755393ac002e6bfdd71b8d7ba725ecd7a3", "BzzKey": "0xe861964402c0b78e2d44098329b8545726f215afa737d803714a4338552fcb81", - "EnsRoot": "0xd344889e0be3e9ef6c26b0f60ef66a32e83c1b69" + "EnsRoot": "0xd344889e0be3e9ef6c26b0f60ef66a32e83c1b69", + "NetworkId": 323 }` ) @@ -95,7 +96,7 @@ func TestConfigWriteRead(t *testing.T) { defer os.RemoveAll(tmp) prvkey := crypto.ToECDSA(common.Hex2Bytes(hexprvkey)) - orig, err := NewConfig(tmp, common.Address{}, prvkey) + orig, err := NewConfig(tmp, common.Address{}, prvkey, 323) if err != nil { t.Fatalf("expected no error, got %v", err) } @@ -109,7 +110,7 @@ func TestConfigWriteRead(t *testing.T) { t.Fatalf("default config mismatch:\nexpected: %v\ngot: %v", exp, string(data)) } - conf, err := NewConfig(tmp, common.Address{}, prvkey) + conf, err := NewConfig(tmp, common.Address{}, prvkey, 323) if err != nil { t.Fatalf("expected no error, got %v", err) } diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index 5e65108d6..a3ffd338f 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -95,6 +95,7 @@ type bzz struct { errors *errs.Errors // errors table backend chequebook.Backend lastActive time.Time + NetworkId uint64 swap *swap.Swap // swap instance for the peer connection swapParams *bzzswap.SwapParams // swap settings both local and remote @@ -126,7 +127,7 @@ on each peer connection The Run function of the Bzz protocol class creates a bzz instance which will represent the peer for the swarm hive and all peer-aware components */ -func Bzz(cloud StorageHandler, backend chequebook.Backend, hive *Hive, dbaccess *DbAccess, sp *bzzswap.SwapParams, sy *SyncParams) (p2p.Protocol, error) { +func Bzz(cloud StorageHandler, backend chequebook.Backend, hive *Hive, dbaccess *DbAccess, sp *bzzswap.SwapParams, sy *SyncParams, networkId uint64) (p2p.Protocol, error) { // a single global request db is created for all peer connections // this is to persist delivery backlog and aid syncronisation @@ -134,13 +135,15 @@ func Bzz(cloud StorageHandler, backend chequebook.Backend, hive *Hive, dbaccess if err != nil { return p2p.Protocol{}, fmt.Errorf("error setting up request db: %v", err) } - + if networkId == 0 { + networkId = NetworkId + } return p2p.Protocol{ Name: "bzz", Version: Version, Length: ProtocolLength, Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error { - return run(requestDb, cloud, backend, hive, dbaccess, sp, sy, p, rw) + return run(requestDb, cloud, backend, hive, dbaccess, sp, sy, networkId, p, rw) }, }, nil } @@ -157,7 +160,7 @@ the main protocol loop that * whenever the loop terminates, the peer will disconnect with Subprotocol error * whenever handlers return an error the loop terminates */ -func run(requestDb *storage.LDBDatabase, depo StorageHandler, backend chequebook.Backend, hive *Hive, dbaccess *DbAccess, sp *bzzswap.SwapParams, sy *SyncParams, p *p2p.Peer, rw p2p.MsgReadWriter) (err error) { +func run(requestDb *storage.LDBDatabase, depo StorageHandler, backend chequebook.Backend, hive *Hive, dbaccess *DbAccess, sp *bzzswap.SwapParams, sy *SyncParams, networkId uint64, p *p2p.Peer, rw p2p.MsgReadWriter) (err error) { self := &bzz{ storage: depo, @@ -175,6 +178,7 @@ func run(requestDb *storage.LDBDatabase, depo StorageHandler, backend chequebook syncParams: sy, swapEnabled: hive.swapEnabled, syncEnabled: true, + NetworkId: networkId, } // handle handshake @@ -340,7 +344,7 @@ func (self *bzz) handleStatus() (err error) { Version: uint64(Version), ID: "honey", Addr: self.selfAddr(), - NetworkId: uint64(NetworkId), + NetworkId: uint64(self.NetworkId), Swap: &bzzswap.SwapProfile{ Profile: self.swapParams.Profile, PayProfile: self.swapParams.PayProfile, @@ -372,8 +376,8 @@ func (self *bzz) handleStatus() (err error) { return self.protoError(ErrDecode, " %v: %v", msg, err) } - if status.NetworkId != NetworkId { - return self.protoError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, NetworkId) + if status.NetworkId != self.NetworkId { + return self.protoError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, self.NetworkId) } if Version != status.Version { diff --git a/swarm/swarm.go b/swarm/swarm.go index 1dce8cafd..7e38944de 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -209,7 +209,7 @@ func (self *Swarm) Stop() error { // implements the node.Service interface func (self *Swarm) Protocols() []p2p.Protocol { - proto, err := network.Bzz(self.depo, self.backend, self.hive, self.dbAccess, self.config.Swap, self.config.SyncParams) + proto, err := network.Bzz(self.depo, self.backend, self.hive, self.dbAccess, self.config.Swap, self.config.SyncParams, self.config.NetworkId) if err != nil { return nil } @@ -279,7 +279,7 @@ func NewLocalSwarm(datadir, port string) (self *Swarm, err error) { return } - config, err := api.NewConfig(datadir, common.Address{}, prvKey) + config, err := api.NewConfig(datadir, common.Address{}, prvKey, network.NetworkId) if err != nil { return } |