Commit graph

16 commits

Author SHA1 Message Date
Dave Collins
c2a1444a88 Add new reject command.
This commit adds the new reject protocol message added to recent versions
of the reference implementation.  This message is intended to be used in
response to messages from a remote peer when it is rejected for some
reason such as blocks being rejected due to not conforming to the chain
rules, transactions double spending inputs, and version messages sent
after they're already sent.

This is work toward issue #9.
2014-05-08 00:17:05 -05:00
David Hill
cf754d09bf Initial implementation of BIP0037.
Implement filteradd, filterclear, filterload, and merkleblock.
2014-05-07 23:41:39 -05:00
David Hill
805ce37d31 Use the stack for most known sizes.
By using the stack for known sizes, there is less pressure on the
garbage collector.
2014-04-08 15:55:21 -04:00
David Hill
b6e6fc25db Preallocate memory for the message header in WriteMessageN and the
serialization buffer in MsgTx's TxSha().

Benchmarking shows this is slightly faster due to avoiding the extra
garbage collection in addition to less peak memory usage.

Before: BenchmarkTxShaOld  500000         5626 ns/op
After:  BenchmarkTxShaNew  500000         5457 ns/op
2014-03-20 14:33:44 -04:00
Dave Collins
ff783faf53 Add Read/WriteMessageN to return number of bytes.
This commit adds two new funtions named ReadMessageN and WriteMessageN
which return an additional paramter for the number of bytes read or written,
respectively.

It also adds tests to ensure the number of bytes read and written are the
expected values both for successful reads/writes and unsuccessful ones.

Closes #6.
2014-02-03 23:12:43 -06:00
Dave Collins
6c7f45fdb7 Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
Dave Collins
14a1da417f Enforce max block payload size of 1MB.
This commit changes MsgBlock to enforce a 1MB max payload per the spec.
Previously it was only limited to the max overall message size.  While
here, also enforce max payloads per message type (instead of only the max
overall message payload) when writing messages.
2013-05-16 09:07:04 -05:00
Dave Collins
0400d0cec3 Remove dead error check in WriteMessage.
The io.Writer.Write function always returns an error if the bytes written
is less than provided, so there is no reason to further check if the
payload length matches after a successful write.
2013-05-11 23:22:09 -05:00
Dave Collins
20bebc13a5 Convert WriteMessage errors to MessgeError type. 2013-05-11 02:29:29 -05:00
Dave Collins
2aee754448 Add test for discarding invalid large messages. 2013-05-09 22:25:21 -05:00
Dave Collins
ec6ebb3916 Add initial implementation of MessageError type.
This commit adds a new MessageError type that is intended to allow the
caller to differentiate between general io errors and and errors that
resulted from malformed messages.
2013-05-09 20:58:17 -05:00
Dave Collins
6286a39378 Combine readMessage with ReadMessage.
These functions used to be split into multiple files, but since the code
was reorganized there is no longer any reason to split them.
2013-05-09 20:16:46 -05:00
Dave Collins
970b9c129d Remove dead error check.
The io.ReadFull function always returns an error if the full payload can't
be read, so there is no reason to further check if the payload length
matches after a successful read.
2013-05-09 15:23:31 -05:00
Dave Collins
c369c0c16e Correct discardInput comment for buffer size.
This was pointed out by kaptin on IRC.
2013-05-09 13:00:00 -05:00
Dave Collins
e473fd6eb8 Add message tests for MsgAlert and MsgMemPool. 2013-05-09 00:01:29 -05:00
Dave Collins
69b27dd5d3 Initial implementation. 2013-05-08 18:58:29 -05:00