lbcd/peer
Josh Rickmar a6965d493f all: Remove seelog logger.
The btclog package has been changed to defining its own logging
interface (rather than seelog's) and provides a default implementation
for callers to use.

There are two primary advantages to the new logger implementation.

First, all log messages are created before the call returns.  Compared
to seelog, this prevents data races when mutable variables are logged.

Second, the new logger does not implement any kind of artifical rate
limiting (what seelog refers to as "adaptive logging").  Log messages
are outputted as soon as possible and the application will appear to
perform much better when watching standard output.

Because log rotation is not a feature of the btclog logging
implementation, it is handled by the main package by importing a file
rotation package that provides an io.Reader interface for creating
output to a rotating file output.  The rotator has been configured
with the same defaults that btcd previously used in the seelog config
(10MB file limits with maximum of 3 rolls) but now compresses newly
created roll files.  Due to the high compressibility of log text, the
compressed files typically reduce to around 15-30% of the original
10MB file.
2017-06-19 16:46:50 -04: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.go all: Remove seelog logger. 2017-06-19 16:46:50 -04:00
mruinvmap.go Optimize by removing defers 2016-10-18 17:56:51 -04:00
mruinvmap_test.go chainhash: Abstract hash logic to new package. (#729) 2016-08-08 14:04:33 -05:00
mrunoncemap.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
peer.go Fix a ton of typos accumulated over time 2017-05-30 16:59:51 +02:00
peer_test.go config: Add user agent comments flag --uacomment 2017-05-17 13:22:26 +02:00
README.md multi: Update markdown files for GFM changes. 2017-05-25 12:06:16 -05:00

peer

Build Status ISC License GoDoc

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

  • New Outbound Peer Example
    Demonstrates the basic process for initializing and creating an outbound peer. Peers negotiate by exchanging version and verack messages. For demonstration, a simple handler for the version message is attached to the peer.

License

Package peer is licensed under the copyfree ISC License.