Commit graph

214 commits

Author SHA1 Message Date
Dave Collins
3ae8056fdb Move the benchmarks into the main btcwire package.
The benchmarks are still only compiled when running 'go test' so this has
no effect on regular usage.  This is being done because benchmarks often
need access to internal state.

Normal tests are kept in a separate package since they also serve to
exercise the public API, and by intentionally making it more difficult to
reach into the internals, it helps ensure the public API is sanely usable.

Since the benchmarks can now access the internals directly, this commit
also removes the functions which exposed the internals to the test package
from internal_test.go which were only used by the benchmarks.
2015-01-14 00:19:07 -06:00
Josh Rickmar
0d01bb9cb9 Optimize NewShaHashFromStr. 2015-01-06 20:04:33 -05:00
Josh Rickmar
a9e05a3030 Implement String for OutPoint. 2015-01-05 18:40:32 -05:00
Josh Rickmar
df3469a792 Improve ShaHash.String comment and implementation.
The hash is not displayed big endian, but rather as a byte-reversed
hash as a hexidecimal string, so document it as such.

While here, speed up the function.  Some benchmarks:

BenchmarkShaHashString   2000000               996 ns/op
BenchmarkShaHashStringOld         100000             22701 ns/op
2015-01-05 17:18:25 -05:00
Dave Collins
a680fb6f25 Update badges in README.md to SVG.
Also add a license badge while here.
2014-12-22 23:13:10 -06:00
Dave Collins
90e8b84c8b Update TravisCI to goclean script.
- Also update to use the new container-based builds
- Modify the tests slightly to make golint happy
2014-12-22 23:10:16 -06:00
Dave Collins
5a477c332b Update TravisCI for Go 1.4 release.
Now that Go 1.4 has been released, this commit reverts the recent changes
which dealt with allowing TravisCI to work with go tip in between the Go
1.3 and Go 1.4 release cycle and updates the .travis.yml to invoke test
coverage tool from the new path in Go 1.4.
2014-12-11 10:43:17 -06:00
Dave Collins
7a1a260b78 Update TravisCI to work with go tip.
This commit modifies the .travis.yml to invoke a new script which has also
been added that gets the test coverage tool from the new path needed by go
tip.
2014-11-14 21:20:44 -06:00
Dave Collins
4b6cd17561 Make RandomUint64 block until entropy is available.
This commit modifies the RandomUint64 function so that rather than
returning an io.ErrShortBuffer when the system does not have enough
entropy available, it now blocks until it does have enough.  This means
that RandomUint64 will now always eventually succeed unless the entropy
source is closed (which only really ever happens when the operating system
is shutting down).

The tests have also been updated for the change in semantics to maintain
100% coverage.

Closes #23.
2014-11-14 12:17:18 -06:00
Jonathan Gillham
a0fe3822fc Fixed minTxInPayload documentation. 2014-10-01 18:14:42 +01:00
Jonathan Gillham
ccee51a0be Changed TxIn.PreviousOutpoint to TxIn.PreviousOutPoint for consistency. 2014-10-01 13:43:37 +01:00
Dave Collins
8733b9c8df Bump default user agent to 0.2.0. 2014-09-20 12:45:18 -05:00
Josh Rickmar
0127b3aafe Make ErrHashStrSize slightly more descriptive.
Add the word 'string' to the error string so if this is printed, it
will be clearer that it was a hash string decode that failed (as
opposed to other errors creating a ShaHash from a byte slice) and
change 'chars' to 'bytes', since the string length is measured in
bytes, not UTF-8 code points.

ok @davecgh
2014-09-12 08:44:15 -05:00
Dave Collins
225248d283 Use byte literals in tests to make go vet happy.
The go vet command complains about untagged struct initializers when
defining a ShaHash directly.  This seems to be a limitation where go vet
does not exclude the warning for types which are a constant size byte array
like it does for normal constant size byte array definition.

This commit simply modifies the tests to use a constant definition cast to a
ShaHash to overcome the limitation of go vet.
2014-09-05 13:58:40 -05:00
Dave Collins
4deb922c9d Export command constants.
Although it is possible to get the command name for each msg type by
creating an instances of the type and calling the Command method against
it, it's slightly more efficient to simply allows callers to have direct
access to the exported constants.

This is currently really useful for the reject message since callers need
to be able to examine the command type to determine whether or not the
hash field needs to be included.
2014-07-14 10:38:29 -05:00
Dave Collins
7ee3a2220b Use a more specific license adjective. 2014-07-13 12:15:50 -05:00
Dave Collins
dd70618cc1 Export CommandSize constant.
This commit exports the CommandSize constant to provide callers with the
ability to know the size of the command field in a bitcoin message header.
2014-07-12 17:35:14 -05:00
Dave Collins
3a1009529f goimports -w . 2014-07-02 19:43:33 -05:00
Dave Collins
5032b07c66 Rename blockHashLen to blockHeaderLen.
The old name no longer makes sense because the hash length is the same as
the header length.
2014-06-29 17:45:46 -05:00
Dave Collins
843e71515a Expose new SerializeSize API for blocks.
This commit adds a new function named SerializeSize to the public API for
MsgBlock which can be used to determine how many bytes the serialized data would
take without having to actually serialize it.  In addition, it makes the
exported BlockVersion an untyped constant as well as changes the block and
tx versions to a signed integer to more closely match the protocol.

Finally, this commit also adds tests for the new function.

The following benchmark shows the difference between using the new
function to get the serialize size for a typical block and serializing
into a temporary buffer and taking the length of it:

Bufffer: BenchmarkBlockSerializeSizeBuffer     200000          27050 ns/op
New:     BenchmarkBlockSerializeSizeNew     100000000             34 ns/op

Closes #19.
2014-06-29 17:43:54 -05:00
Josh Rickmar
7dcb68275f Make MaxMessagePayload an exported constant.
ok @davecgh
2014-06-06 22:33:39 -05:00
Dave Collins
ee46a0b108 Use bytes.NewReader for deserialize when possible.
Rather than using bytes.NewBuffer, which is a read/write entity
(io.ReadWriter), use bytes.NewReader which is only a read entitiy
(io.Reader) in all cases where it is possible.  Benchmarking shows it's
slightly faster and it's also technically more accurate since it ensures
the data is read-only.

There are a few cases where bytes.NewBuffer must still be used since a
buffer with a known length is required for those instances.
2014-06-04 23:39:03 -05:00
Dave Collins
2054fa7581 Update doc.go to reflect reality.
This commit updates doc.go to include the new simulation test network
magic constant as well as remove the information about BIP0037 not being
supported since that is no longer true.
2014-06-02 12:35:00 -05:00
Dave Collins
31ee545aa9 Add bitcoin network type for simulation testing. 2014-05-29 12:50:17 -05:00
Dave Collins
c4135db728 Move default network ports to btcnet package.
The default network ports are not really part of the wire protocol rather
they are part of a network parameters.  Thus, this commit moves them to
the btcnet package.
2014-05-29 12:45:11 -05:00
Dave Collins
dfdd223223 Move genesis blocks to btcnet package.
The genesis blocks are not really part of the wire protocol rather they
are part of a network parameters.  Thus, this commit moves the all of the
gensis blocks and tests to the btcnet package.

Also, create variables in the test package for the mainnet genesis hash,
merkle root, and coinbase transaction for use throughout the tests since
they the exported values are no longer available.
2014-05-28 09:14:38 -05:00
Dave Collins
a4978ba4c8 Add tests for the new MsgReject message.
This commit adds a full suite tests for the new reject message added in
protocol version 70002 to bring the overall test coverage of btcwire back
up to 100%.

Closes #9.
2014-05-08 00:17:11 -05:00
Dave Collins
f38e5854c1 Bump protocol version to 70002. 2014-05-08 00:17:11 -05:00
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
Dave Collins
f8ec476691 Complete BIP0037 support started by dhill.
- Correct MsgFilterLoad max payload
- Enforce max flag bytes per merkle block
- Improve and finish tests to include testing all error paths
- Add fast paths for BloomUpdateType
- Convert all byte fields to use read/writeVarBytes
- Style and consistency updates
- README.md and doc.go updates

Closes #12.
2014-05-07 23:57:55 -05:00
David Hill
cf754d09bf Initial implementation of BIP0037.
Implement filteradd, filterclear, filterload, and merkleblock.
2014-05-07 23:41:39 -05:00
Dave Collins
a98f5ca38e Cleanup a few nitpicks with recent alert additions.
- Group the new read/writeVarBytes functions together to be consistent
  with the existing code
- Modify the comments on the new read/writeVarBytes to be a little more
  descriptive and consistent with existing code
- Use "test payload" for field name in the tests for the
  read/writeVarBytes functions which is more accurate
- Remove reserved param from NewAlert since there is no point is having
  the caller deal with a reserved param
- Various comment tweaks for clarity and consistency
- Use camel case for fuction params for consistency
- Move the NewAlert and NewAlertFromPayload functions after the receiver
  definitions for code layout consistency

Closes #11.
2014-05-07 19:41:04 -05:00
Javed Khan
bdec7f8abb Implemented alert message serialize/deserialize
* Introduced common methods readVarBytes, writeVarBytes.
* Added type Alert which knows how to deserialize
the serialized payload and also serialize itself back.
* Updated MsgAlert BtcEncode/BtcDecode methods to handle the
new Alert.
* Sane limits are placed on variable length fields like SetCancel
and SetSubVer
2014-05-05 23:12:28 +05:30
Dave Collins
2cc89bbf5b Remove function name from ShaHash error message.
This makes golint happy.
2014-04-21 10:53:22 -05:00
Dave Collins
8857485fa8 Remove note that is no longer true.
The code was updated to automatically handle the transaction count in the
block header without having the additional field some time ago.  This
comment was outdated.
2014-04-20 23:24:56 -05:00
Dave Collins
d848bc453b Improve comments on new AddUserAgent function. 2014-04-20 17:44:46 -05:00
Javed Khan
620cbdeb8e Implemented BIP 0014 format for user agent
the new function AddUserAgent adds the user agent to the stack
and formats it as per BIP 0014
e.g: "/btcwire:0.1.4/myclient:1.2.3(optional; comments)/"

the validation on UserAgent has been moved to a new function
validateUserAgent
2014-04-21 02:36:13 +05:30
Dave Collins
a9293bd32e Add godoc reference badge to README.md. 2014-04-19 15:46:03 -05:00
Dave Collins
44e34926a7 Remove test coverage report refs from README.md.
This is no longer needed since the repository is now configured to work
with coveralls.io for test coverage reporting.

Closes #17
2014-04-19 14:49:42 -05:00
Dave Collins
755944738a Instruct TravisCI to install coverage report tool. 2014-04-19 14:41:52 -05:00
Dave Collins
6b82da13b4 Setup TravisCI to report cov stats to coveralls.io.
Also add a coveralls.io test coverage badge to the README.
2014-04-19 14:36:16 -05:00
Javed Khan
9130de2de2 add tmp wire file to .gitignore 2014-04-19 15:53:03 +05:30
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
Dave Collins
f0581b565c Correct two more comments in block bytes breakdown. 2014-04-06 14:14:48 -05:00
Dave Collins
0e1f8fda6d Correct some comments in block bytes breakdown. 2014-04-05 21:00:28 -05:00
Dave Collins
937374c95a Cleanup and finish relay transaction work.
- Coalesce the new bytes into the max message size constant to stay
  consistent
- Correct optional relay tx field handling
- Rename the relay transactions field to DisableRelayTx so the zero value
  of false has the correct default behavior
- Add tests for new bool fast paths in read/writeElement
- Stay consistent with version order in tests
- Add a single entry to TestVersionWire to test the new functionality
  instead of adding a whole new TextVersionRelayTx function.
- Use BIP0037 in tests instead of hard coding 70001
- Nuke XXX that 70001 is different since this is handled now
- Fix and cleanup some comments
- Update test coverage report
2014-03-31 11:35:36 -05:00
David Hill
e9a18fb14c Support RelayTx param in ver message for 70001+.
This commit adds support for the version message RelayTx parameter for
protocol version 70001+ as added by BIP0037.
2014-03-30 23:43:18 -05:00
Dave Collins
8721348051 Add tests for optional message fields.
Since fields of a version message after the AddrMe field are optional,
this commit adds a series of tests which ensure parsing version messages
which omit each of the optional fields works properly.
2014-03-30 23:39:28 -05:00
Dave Collins
c917899303 Allow optional fields in MsgVersion decode.
This commit modifies the MsgVersion.BtcDecode function to match the
behavior where fields after the first address field (AddrYou) are optional
and only read if the buffer contains remaining bytes.

Unfortunately this means the reader for MsgVersion.BtcDecode must be a
*bytes.Buffer or an error is returned.  This is not an issue for the vast
majority of cases since all of the message reading code which is the main
way messages are read is already using a *bytes.Buffer, however, this
change might affect external callers if they are doing something special
with custom readers.

Fixes #14.
2014-03-30 15:56:52 -05:00
Dave Collins
dfb2c149f6 Finish uncompleted comments in fixedIO_test.go. 2014-03-30 12:19:17 -05:00