dcrd/wire
Dave Collins 756eff2fee peer: Refactor peer code into its own package.
Contains the following upstream commits:

- 00bddf7540
- 250228c32f
- f1bd2f8d6e
- cbbe3a8bbe
- aa03d68e1e

In addition to the normal required changes for syncing, the following
changes have been made in order to facilitate integration of the new
package into Decred:

- Removed check in PushRejectMsg against protocol version since all
  peers since the initial version support it
- Fixed leaked timer in `syncMiningStateAfterSync` function
- Add the Decred-specific OnGetMiningState and OnMiningState handlers to
  the new peer package
- Add handler for the new mining state messages to the 'serverPeer' type
  and register them
- Use the new constant for wire.InitialProtocolVersion in the reject
  message instead of hard coded number
- Remove logic specific to the regression network since Decred does not
  have it
2016-05-20 13:58:23 -05:00
..
bench_test.go wire: Export var length string serialization funcs. 2016-02-29 12:51:36 -05:00
blockheader_test.go Implmement BlockHeader BtcEncode/BtcDecode. 2016-05-11 15:10:12 -05:00
blockheader.go Implmement BlockHeader BtcEncode/BtcDecode. 2016-05-11 15:10:12 -05:00
common_test.go wire: Export var length string serialization funcs. 2016-02-29 12:51:36 -05:00
common.go Correct a few style related issues found by golint. 2016-05-19 11:37:05 -05:00
doc.go Sync upstream through Sep 28, 2015. 2016-05-17 14:01:54 -05:00
error.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
fakeconn_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
fakemessage_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
fixedIO_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
hash_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
internal_test.go Implmement BlockHeader BtcEncode/BtcDecode. 2016-05-11 15:10:12 -05:00
invvect_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
invvect.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
message_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
message.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgaddr_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgaddr.go Remove legacy Bitcoin addr encoding 2016-05-17 14:40:43 -04:00
msgalert_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgalert.go wire: Export var length string serialization funcs. 2016-02-29 12:51:36 -05:00
msgblock_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgblock.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgfilteradd_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgfilteradd.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgfilterclear_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgfilterclear.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgfilterload_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgfilterload.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetaddr_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetaddr.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetblocks_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetblocks.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetdata_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetdata.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetheaders_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetheaders.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msggetminingstate.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgheaders_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgheaders.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msginv_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msginv.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgmempool_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgmempool.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgmerkleblock_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgmerkleblock.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgminingstate_test.go Sync upstream through Sep 28, 2015. 2016-05-17 14:01:54 -05:00
msgminingstate.go Sync upstream through Sep 28, 2015. 2016-05-17 14:01:54 -05:00
msgnotfound_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgnotfound.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgping_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgping.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgpong_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgpong.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgreject_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgreject.go wire: Export var length string serialization funcs. 2016-02-29 12:51:36 -05:00
msgtx_test.go Resolve all remaining issues caught by goclean.sh 2016-02-15 11:24:00 -05:00
msgtx.go Work on improving the use of analysis tools in goclean.sh 2016-02-12 15:24:32 -05:00
msgverack_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgverack.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgversion_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
msgversion.go Sync upstream through Sep 28, 2015. 2016-05-17 14:01:54 -05:00
netaddress_test.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
netaddress.go Initial Decred Commit. 2016-02-07 14:00:12 -05:00
protocol_test.go Sync upstream through Sep 28, 2015. 2016-05-17 14:01:54 -05:00
protocol.go peer: Refactor peer code into its own package. 2016-05-20 13:58:23 -05:00
README.md Initial Decred Commit. 2016-02-07 14:00:12 -05:00

wire

![ISC License] (http://img.shields.io/badge/license-ISC-blue.svg)

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

There is an associated blog post about the release of this package here.

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.

Documentation

[GoDoc] (http://godoc.org/github.com/decred/dcrd/wire)

Full go doc style documentation for the project can be viewed online without installing this package by using the GoDoc site here: http://godoc.org/github.com/decred/dcrd/wire

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/decred/dcrd/wire

Installation

$ go get 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.