diff options
author | Felix Lange <fjl@twurst.com> | 2015-01-06 18:35:09 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-01-06 19:23:38 +0800 |
commit | eb0e7b1b8120852a1d56aa0ebd3a98e652965635 (patch) | |
tree | 9e87afc204d178d89ed24cc43afcc3da6b252a49 /eth/protocol.go | |
parent | 36e1e5f15142b37801844a072eb46ea67fbc8868 (diff) | |
download | dexon-eb0e7b1b8120852a1d56aa0ebd3a98e652965635.tar.gz dexon-eb0e7b1b8120852a1d56aa0ebd3a98e652965635.tar.zst dexon-eb0e7b1b8120852a1d56aa0ebd3a98e652965635.zip |
eth, p2p: remove EncodeMsg from p2p.MsgWriter
...and make it a top-level function instead.
The original idea behind having EncodeMsg in the interface was that
implementations might be able to encode RLP data to their underlying
writer directly instead of buffering the encoded data. The encoder
will buffer anyway, so that doesn't matter anymore.
Given the recent problems with EncodeMsg (copy-pasted implementation
bug) I'd rather implement once, correctly.
Diffstat (limited to 'eth/protocol.go')
-rw-r--r-- | eth/protocol.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/eth/protocol.go b/eth/protocol.go index b67e5aaea..723ab5502 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -140,7 +140,7 @@ func (self *ethProtocol) handle() error { return self.protoError(ErrDecode, "->msg %v: %v", msg, err) } hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount) - return self.rw.EncodeMsg(BlockHashesMsg, ethutil.ByteSliceToInterface(hashes)...) + return p2p.EncodeMsg(self.rw, BlockHashesMsg, ethutil.ByteSliceToInterface(hashes)...) case BlockHashesMsg: // TODO: redo using lazy decode , this way very inefficient on known chains @@ -185,7 +185,7 @@ func (self *ethProtocol) handle() error { break } } - return self.rw.EncodeMsg(BlocksMsg, blocks...) + return p2p.EncodeMsg(self.rw, BlocksMsg, blocks...) case BlocksMsg: msgStream := rlp.NewStream(msg.Payload) @@ -298,12 +298,12 @@ func (self *ethProtocol) handleStatus() error { func (self *ethProtocol) requestBlockHashes(from []byte) error { self.peer.Debugf("fetching hashes (%d) %x...\n", blockHashesBatchSize, from[0:4]) - return self.rw.EncodeMsg(GetBlockHashesMsg, interface{}(from), uint64(blockHashesBatchSize)) + return p2p.EncodeMsg(self.rw, GetBlockHashesMsg, interface{}(from), uint64(blockHashesBatchSize)) } func (self *ethProtocol) requestBlocks(hashes [][]byte) error { self.peer.Debugf("fetching %v blocks", len(hashes)) - return self.rw.EncodeMsg(GetBlocksMsg, ethutil.ByteSliceToInterface(hashes)...) + return p2p.EncodeMsg(self.rw, GetBlocksMsg, ethutil.ByteSliceToInterface(hashes)...) } func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *protocolError) { |