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.
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:
communications via the peer-to-peer protocol
negotiation
notification when the message is actually sent
- 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
and avoidance
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
written, the remote address, user agent, and negotiated protocol version
- 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
$ go get -u github.com/p9c/p9/peer
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.
Package peer is licensed under the copyfree ISC License.