dcrd/wire
2019-06-18 14:20:06 -05:00
..
bench_test.go multi: Remove everything to do about bloom filters. 2018-05-01 11:43:32 -05:00
blockheader_test.go wire: Add tests for BlockHeader (From)Bytes. 2019-03-18 11:42:42 -05:00
blockheader.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
common_test.go multi: cleanup linter warnings 2019-02-13 08:38:25 -05:00
common.go multi: Remove everything to do about bloom filters. 2018-05-01 11:43:32 -05:00
doc.go multi: Resurrect regression network. 2018-10-09 18:52:13 -05:00
error.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
fakeconn_test.go wire: Consolidate tests into the wire pkg. 2016-11-14 15:29:40 -06:00
fakemessage_test.go wire: Consolidate tests into the wire pkg. 2016-11-14 15:29:40 -06:00
fixedIO_test.go multi: cleanup linter warnings 2019-02-13 08:38:25 -05:00
go.mod multi: Add go 1.11 directive to all modules. 2019-03-18 02:02:35 -05:00
go.sum multi: Remove non-root module replacements. 2019-02-08 18:01:43 -06:00
invvect_test.go multi: Upstream chainhash abstraction sync 2016-11-16 12:48:40 -06:00
invvect.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
message_test.go multi: Reset testnet and bump to version 3. 2018-08-08 08:09:32 -05:00
message.go multi: cleanup linter warnings 2019-02-13 08:38:25 -05:00
msgaddr_test.go wire: Fix maximum payload length of MsgAddr. 2019-03-10 12:41:28 -05:00
msgaddr.go wire: Fix maximum payload length of MsgAddr. 2019-03-10 12:41:28 -05:00
msgblock_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgblock.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgcfheaders_test.go wire: Add tests for MsgCFHeaders. 2019-05-22 04:06:06 -05:00
msgcfheaders.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msgcfilter_test.go wire: Add tests for MsgCFilter. 2019-06-08 01:10:40 -05:00
msgcfilter.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msgcftypes_test.go wire: Rename extended errors to malformed errors. 2019-06-07 13:51:46 -05:00
msgcftypes.go wire: Fix MsgCFTypes maximum payload length. 2019-03-25 17:01:20 -05:00
msgfeefilter_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgfeefilter.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msggetaddr_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msggetaddr.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msggetblocks_test.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msggetblocks.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msggetcfheaders_test.go wire: Add tests for MsgGetCFHeaders. 2019-05-21 20:15:04 -05:00
msggetcfheaders.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msggetcfilter_test.go wire: Add tests for MsgGetCFilter. 2019-03-21 15:43:23 -05:00
msggetcfilter.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msggetcftypes_test.go wire: Add tests for MsgGetCFTypes. 2019-03-28 11:09:24 -05:00
msggetcftypes.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msggetdata_test.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msggetdata.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msggetheaders_test.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msggetheaders.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msggetminingstate.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgheaders_test.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msgheaders.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msginv_test.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msginv.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msgmempool_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgmempool.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgminingstate_test.go wire: Consolidate tests into the wire pkg. 2016-11-14 15:29:40 -06:00
msgminingstate.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msgnotfound_test.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msgnotfound.go wire: Accurate calculations of maximum length. 2019-03-25 16:36:32 -05:00
msgping_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgping.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgpong_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgpong.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgreject_test.go wire: Consolidate tests into the wire pkg. 2016-11-14 15:29:40 -06:00
msgreject.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgsendheaders_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgsendheaders.go wire: Implement sendheaders command 2016-05-27 23:07:05 -05:00
msgtx_test.go multi: add valueIn parameter to wire.NewTxIn. 2018-06-15 19:13:41 -05:00
msgtx.go multi: fix recent govet findings 2019-04-29 17:58:06 -05:00
msgverack_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgverack.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgversion_test.go multi: various cleanups 2018-02-02 14:18:41 -06:00
msgversion.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
netaddress_test.go Preallocate the exact number of bytes if known. 2017-03-20 21:46:33 -05:00
netaddress.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
protocol_test.go multi: Remove testnet version 2 defs and refs. 2018-08-08 08:10:22 -05:00
protocol.go multi: Resurrect regression network. 2018-10-09 18:52:13 -05:00
README.md multi: Use https links where available. 2019-06-18 14:20:06 -05:00

wire

Build Status ISC License GoDoc

Package wire implements the Decred wire protocol. A comprehensive suite of tests with 100% test coverage is provided to ensure proper functionality.

This package has intentionally been designed so it can be used as a standalone package for any projects needing to interface with Decred peers at the wire protocol level.

Installation and Updating

$ go get -u github.com/decred/dcrd/wire

Decred Message Overview

The Decred protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it such as which decred network it is a part of, its type, how big it is, and a checksum to verify validity. All encoding and decoding of message headers is handled by this package.

To accomplish this, there is a generic interface for Decred messages named Message which allows messages of any type to be read, written, or passed around through channels, functions, etc. In addition, concrete implementations of most of the currently supported Decred messages are provided. For these supported messages, all of the details of marshalling and unmarshalling to and from the wire using Decred encoding are handled so the caller doesn't have to concern themselves with the specifics.

Reading Messages Example

In order to unmarshal Decred messages from the wire, use the ReadMessage function. It accepts any io.Reader, but typically this will be a net.Conn to a remote node running a Decred peer. Example syntax is:

	// Use the most recent protocol version supported by the package and the
	// main Decred network.
	pver := wire.ProtocolVersion
	dcrnet := wire.MainNet

	// Reads and validates the next Decred message from conn using the
	// protocol version pver and the Decred network dcrnet.  The returns
	// are a wire.Message, a []byte which contains the unmarshalled
	// raw payload, and a possible error.
	msg, rawPayload, err := wire.ReadMessage(conn, pver, dcrnet)
	if err != nil {
		// Log and handle the error
	}

See the package documentation for details on determining the message type.

Writing Messages Example

In order to marshal Decred messages to the wire, use the WriteMessage function. It accepts any io.Writer, but typically this will be a net.Conn to a remote node running a Decred peer. Example syntax to request addresses from a remote peer is:

	// Use the most recent protocol version supported by the package and the
	// main Decred network.
	pver := wire.ProtocolVersion
	dcrnet := wire.MainNet

	// Create a new getaddr Decred message.
	msg := wire.NewMsgGetAddr()

	// Writes a Decred message msg to conn using the protocol version
	// pver, and the Decred network dcrnet.  The return is a possible
	// error.
	err := wire.WriteMessage(conn, msg, pver, dcrnet)
	if err != nil {
		// Log and handle the error
	}

License

Package wire is licensed under the copyfree ISC License.