dcrd/wire
Josh Rickmar 71500c80f2 multi: Add initial committed filter (CF) support
This change begins the work of bringing committed filters to the
network consensus daemon.  Committed filters are designed to enable
light wallets without many of the privacy issues associated with
server-side bloom filtering.

The new gcs package provides the primitives for creating and matching
against Golomb-coded sets (GCS) filters while the blockcf package
provides creation of filters and filter entries for data structures
found in blocks.

The wire package has been updated to define a new protocol version and
service flag for advertising CF support and includes types for the
following new messages: cfheaders, cfilter, cftypes, getcfheaders,
getcfilter, getcftypes.  The peer package and server implementation
have been updated to include support for the new protocol version and
messages.

Filters are created using a collision probability of 2^-20 and are
saved to a new optional database index when running with committed
filter support enabled (the default).  At first startup, if support is
not disabled, the index will be created and populated with filters and
filter headers for all preexisting blocks, and new filters will be
recorded for processed blocks.

Multiple filter types are supported.  The regular filter commits to
output scripts and previous outpoints that any non-voting wallet will
require access to.  Scripts and previous outpoints that can only be
spent by votes and revocations are not committed to the filter.  The
extended filter is a supplementary filter which commits to all
transaction hashes and script data pushes from the input scripts of
non-coinbase regular and ticket purchase transactions.  Creating these
filters is based on the algorithm defined by BIP0158 but is modified
to only commit "regular" data in stake transactions to prevent
committed filters from being used to create SPV voting wallets.
2018-03-30 13:52:12 -04:00
..
bench_test.go multi: Separate tx serialization type from version. 2017-08-07 14:10:27 -05:00
blockheader_test.go multi: Separate tx serialization type from version. 2017-08-07 14:10:27 -05:00
blockheader.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
common_test.go multi: Upstream chainhash abstraction sync 2016-11-16 12:48:40 -06:00
common.go multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
doc.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06: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 travis: add gosimple linter 2017-11-20 18:49:55 -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: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
message.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msgaddr_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgaddr.go Merge in btcd commit '2adfb3b56acd280e84451e94dd0c06203eef9832' 2016-09-23 18:02:41 -04: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.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msgcfilter.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msgcftypes.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04: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
msgfilteradd_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgfilteradd.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgfilterclear_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgfilterclear.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgfilterload_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgfilterload.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -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 travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msggetblocks.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msggetcfheaders.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msggetcfilter.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msggetcftypes.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
msggetdata_test.go multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
msggetdata.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msggetheaders_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msggetheaders.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msggetminingstate.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgheaders_test.go travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgheaders.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msginv_test.go multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
msginv.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06: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
msgmerkleblock_test.go multi: Implement block size hard fork demo voting. 2017-02-13 13:28:21 -06:00
msgmerkleblock.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 multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
msgnotfound_test.go multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
msgnotfound.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06: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 travis: add gosimple linter 2017-11-20 18:49:55 -06:00
msgtx.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06: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: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
protocol.go multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
README.md multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06: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.