btcd/peer
Dave Collins c440584efc
Implement infrastructure for BIP0009.
This commit adds all of the infrastructure needed to support BIP0009
soft forks.

The following is an overview of the changes:

- Add new configuration options to the chaincfg package which allows the
  rule deployments to be defined per chain
- Implement code to calculate the threshold state as required by BIP0009
  - Use threshold state caches that are stored to the database in order
    to accelerate startup time
  - Remove caches that are invalid due to definition changes in the
    params including additions, deletions, and changes to existing
    entries
- Detect and warn when a new unknown rule is about to activate or has
  been activated in the block connection code
- Detect and warn when 50% of the last 100 blocks have unexpected
  versions.
- Remove the latest block version from wire since it no longer applies
- Add a version parameter to the wire.NewBlockHeader function since the
  default is no longer available
- Update the miner block template generation code to use the calculated
  block version based on the currently defined rule deployments and
  their threshold states as of the previous block
- Add tests for new error type
- Add tests for threshold state cache
2016-11-30 13:51:59 -06:00
..
doc.go multi: Fix several misspellings in the comments. 2016-02-25 11:17:12 -06:00
example_test.go peer: rename peer.Connect to AssociateConnection 2016-10-21 14:13:18 -05:00
export_test.go peer: Refactor peer code into its own package. 2015-10-23 06:17:29 +05:30
log_test.go peer: Refactor peer code into its own package. 2015-10-23 06:17:29 +05:30
log.go multi: Simplify code per gosimple linter. 2016-11-03 13:00:35 -05:00
mruinvmap_test.go chainhash: Abstract hash logic to new package. (#729) 2016-08-08 14:04:33 -05:00
mruinvmap.go Optimize by removing defers 2016-10-18 17:56:51 -04:00
mrunoncemap_test.go peer: Refactor peer code into its own package. 2015-10-23 06:17:29 +05:30
mrunoncemap.go Optimize by removing defers 2016-10-18 17:56:51 -04:00
peer_test.go Implement infrastructure for BIP0009. 2016-11-30 13:51:59 -06:00
peer.go peer: disconnected peer - return non-nil LocalAddr 2016-11-19 15:05:51 -06:00
README.md docs: Make various README.md files consistent. 2015-10-23 14:51:36 -05:00

peer

[Build Status] (https://travis-ci.org/btcsuite/btcd) ![ISC License] (http://img.shields.io/badge/license-ISC-blue.svg) [GoDoc] (http://godoc.org/github.com/btcsuite/btcd/peer)

Package peer provides a common base for creating and managing bitcoin network peers.

This package has intentionally been designed so it can be used as a standalone package for any projects needing a full featured bitcoin peer base to build on.

Overview

This package builds upon the wire package, which provides the fundamental primitives necessary to speak the bitcoin wire protocol, in order to simplify the process of creating fully functional peers. In essence, it provides a common base for creating concurrent safe fully validating nodes, Simplified Payment Verification (SPV) nodes, proxies, etc.

A quick overview of the major features peer provides are as follows:

  • Provides a basic concurrent safe bitcoin peer for handling bitcoin communications via the peer-to-peer protocol
  • Full duplex reading and writing of bitcoin protocol messages
  • Automatic handling of the initial handshake process including protocol version negotiation
  • Asynchronous message queueing of outbound messages with optional channel for notification when the message is actually sent
  • Flexible peer configuration
    • Caller is responsible for creating outgoing connections and listening for incoming connections so they have flexibility to establish connections as they see fit (proxies, etc)
    • User agent name and version
    • Bitcoin network
    • Service support signalling (full nodes, bloom filters, etc)
    • Maximum supported protocol version
    • Ability to register callbacks for handling bitcoin protocol messages
  • Inventory message batching and send trickling with known inventory detection and avoidance
  • Automatic periodic keep-alive pinging and pong responses
  • Random nonce generation and self connection detection
  • Proper handling of bloom filter related commands when the caller does not specify the related flag to signal support
    • Disconnects the peer when the protocol version is high enough
    • Does not invoke the related callbacks for older protocol versions
  • Snapshottable peer statistics such as the total number of bytes read and written, the remote address, user agent, and negotiated protocol version
  • Helper functions pushing addresses, getblocks, getheaders, and reject messages
    • These could all be sent manually via the standard message output function, but the helpers provide additional nice functionality such as duplicate filtering and address randomization
  • Ability to wait for shutdown/disconnect
  • Comprehensive test coverage

Installation and Updating

$ go get -u github.com/btcsuite/btcd/peer

Examples

License

Package peer is licensed under the copyfree ISC License.