From 6e7e5d5fd56a9a6f73e51239ed6648d76db9650d Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 4 Mar 2015 13:12:50 +0100 Subject: eth, whisper: fix msg.Payload reads --- eth/protocol.go | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'eth') diff --git a/eth/protocol.go b/eth/protocol.go index 663af43fe..b86f33614 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -3,7 +3,6 @@ package eth import ( "bytes" "fmt" - "io" "math/big" "github.com/ethereum/go-ethereum/core/types" @@ -188,33 +187,37 @@ func (self *ethProtocol) handle() error { case BlockHashesMsg: msgStream := rlp.NewStream(msg.Payload) - var err error - var i int + if _, err := msgStream.List(); err != nil { + return err + } + var i int iter := func() (hash []byte, ok bool) { - hash, err = msgStream.Bytes() - if err == nil { - i++ - ok = true - } else { - if err != io.EOF { - self.protoError(ErrDecode, "msg %v: after %v hashes : %v", msg, i, err) - } + hash, err := msgStream.Bytes() + if err == rlp.EOL { + return nil, false + } else if err != nil { + self.protoError(ErrDecode, "msg %v: after %v hashes : %v", msg, i, err) + return nil, false } - return + i++ + return hash, true } - self.blockPool.AddBlockHashes(iter, self.id) case GetBlocksMsg: msgStream := rlp.NewStream(msg.Payload) + if _, err := msgStream.List(); err != nil { + return err + } + var blocks []interface{} var i int for { i++ var hash []byte if err := msgStream.Decode(&hash); err != nil { - if err == io.EOF { + if err == rlp.EOL { break } else { return self.protoError(ErrDecode, "msg %v: %v", msg, err) @@ -232,10 +235,13 @@ func (self *ethProtocol) handle() error { case BlocksMsg: msgStream := rlp.NewStream(msg.Payload) + if _, err := msgStream.List(); err != nil { + return err + } for { var block types.Block if err := msgStream.Decode(&block); err != nil { - if err == io.EOF { + if err == rlp.EOL { break } else { return self.protoError(ErrDecode, "msg %v: %v", msg, err) -- cgit From 215c763d53fc8e06e8c9807875eacaccf3ef45fa Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 4 Mar 2015 16:54:36 +0100 Subject: eth, p2p: delete p2p.Blacklist It is unused and untested right now. We can bring it back later if required. --- eth/backend.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'eth') diff --git a/eth/backend.go b/eth/backend.go index 5cd7b308f..8b76e0ca3 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -108,11 +108,9 @@ func (cfg *Config) nodeKey() (*ecdsa.PrivateKey, error) { type Ethereum struct { // Channel for shutting down the ethereum shutdownChan chan bool - quit chan bool // DB interface - db ethutil.Database - blacklist p2p.Blacklist + db ethutil.Database //*** SERVICES *** // State manager for processing new blocks and managing the over all states @@ -170,10 +168,8 @@ func New(config *Config) (*Ethereum, error) { eth := &Ethereum{ shutdownChan: make(chan bool), - quit: make(chan bool), db: db, keyManager: keyManager, - blacklist: p2p.NewBlacklist(), eventMux: &event.TypeMux{}, logger: ethlogger, } @@ -206,7 +202,6 @@ func New(config *Config) (*Ethereum, error) { Name: config.Name, MaxPeers: config.MaxPeers, Protocols: protocols, - Blacklist: eth.blacklist, NAT: config.NAT, NoDial: !config.Dial, BootstrapNodes: config.parseBootNodes(), @@ -280,8 +275,6 @@ func (s *Ethereum) Stop() { // Close the database defer s.db.Close() - close(s.quit) - s.txSub.Unsubscribe() // quits txBroadcastLoop s.blockSub.Unsubscribe() // quits blockBroadcastLoop -- cgit