factomwire

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2015 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdVersion  = "version"
	CmdVerAck   = "verack"
	CmdGetAddr  = "getaddr"
	CmdAddr     = "addr"
	CmdInv      = "inv"
	CmdGetData  = "getdata"
	CmdNotFound = "notfound"

	// incoming blocks of the 3 special types & 1 general-purpose chain type:
	CmdBlock            = "factoidblock"
	CmdEntryCreditBlock = "ecblock"
	CmdDirectoryBlock   = "dirblock"
	CmdEntryBlock       = "entryblock"

	// entry itself
	CmdEntry = "entry"

	CmdTx          = "tx"
	CmdGetHeaders  = "getheaders"
	CmdHeaders     = "headers"
	CmdPing        = "ping"
	CmdPong        = "pong"
	CmdAlert       = "alert"
	CmdMemPool     = "mempool"
	CmdFilterAdd   = "filteradd"
	CmdFilterClear = "filterclear"
	CmdFilterLoad  = "filterload"
	CmdMerkleBlock = "merkleblock"
	CmdReject      = "reject"

	CmdCommitChain = "commitchain"
	CmdRevealChain = "revealchain"
	CmdCommitEntry = "commitentry"
	CmdRevealEntry = "revealentry"

	// using these commands we query & find the best chain & latest height for the Directory (all other chain heights are then known)
	CmdGetDirBlocks = "getdirblocks"

	CmdConfirmation = "confirmation"
	CmdMHashReveal  = "mhashreveal"
)

Commands used in bitcoin message headers which describe the type of message.

View Source
const (
	// ProtocolVersion is the latest protocol version this package supports.
	ProtocolVersion uint32 = 70002

	// MultipleAddressVersion is the protocol version which added multiple
	// addresses per message (pver >= MultipleAddressVersion).
	MultipleAddressVersion uint32 = 209

	// NetAddressTimeVersion is the protocol version which added the
	// timestamp field (pver >= NetAddressTimeVersion).
	NetAddressTimeVersion uint32 = 31402

	// RejectVersion is the protocol version which added a new reject
	// message.
	RejectVersion uint32 = 70002
)
View Source
const CommandSize = 12

CommandSize is the fixed size of all commands in the common bitcoin message header. Shorter commands must be zero padded.

View Source
const DefaultUserAgent = "/factomwire:0.2.0/"

DefaultUserAgent for factomwire in the stack

View Source
const HashSize = 32

Size of array used to store sha hashes. See ShaHash.

View Source
const MaxAddrPerMsg = 1000

MaxAddrPerMsg is the maximum number of addresses that can be in a single bitcoin addr message (MsgAddr).

View Source
const MaxAppMsgPayload = 10000 // 10 k bytes

MaxAppMsgPayload is the maximum bytes a factom app message can be in bytes.

View Source
const MaxBlockLocatorsPerMsg = 500

MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.

View Source
const MaxBlockPayload = 1000000 // Not actually 1MB which would be 1024 * 1024

MaxBlockPayload is the maximum bytes a block message can be in bytes.

View Source
const MaxHashStringSize = HashSize * 2

MaxHashStringSize is the maximum length of a ShaHash hash string.

View Source
const (
	// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
	// single bitcoin inv message.
	MaxInvPerMsg = 50000
)
View Source
const MaxMessagePayload = (1024 * 1024 * 32) // 32MB

MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.

View Source
const MaxUserAgentLen = 2000

MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).

View Source
const MaxVarIntPayload = 9

Maximum payload size for a variable length integer.

View Source
const MessageHeaderSize = 24

MessageHeaderSize is the number of bytes in a bitcoin message header. Bitcoin network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.

Variables

View Source
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)

ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.

View Source
var ErrInvalidNetAddr = errors.New("provided net.Addr is not a net.TCPAddr")

ErrInvalidNetAddr describes an error that indicates the caller didn't specify a TCP address as required.

Functions

func DoubleSha256

func DoubleSha256(b []byte) []byte

DoubleSha256 calculates sha256(sha256(b)) and returns the resulting bytes.

func RandomUint64

func RandomUint64() (uint64, error)

RandomUint64 returns a cryptographically random uint64 value.

func VarIntSerializeSize

func VarIntSerializeSize(val uint64) int

VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.

func WriteMessage

func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet FactomNet) error

WriteMessage writes a bitcoin Message to w including the necessary header information. This function is the same as WriteMessageN except it doesn't doesn't return the number of bytes written. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.

func WriteMessageN

func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet FactomNet) (int, error)

WriteMessageN writes a bitcoin Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessage except it also returns the number of bytes written.

Types

type Alert

type Alert struct {
	// Alert format version
	Version int32

	// Timestamp beyond which nodes should stop relaying this alert
	RelayUntil int64

	// Timestamp beyond which this alert is no longer in effect and
	// should be ignored
	Expiration int64

	// A unique ID number for this alert
	ID int32

	// All alerts with an ID less than or equal to this number should
	// cancelled, deleted and not accepted in the future
	Cancel int32

	// All alert IDs contained in this set should be cancelled as above
	SetCancel []int32

	// This alert only applies to versions greater than or equal to this
	// version. Other versions should still relay it.
	MinVer int32

	// This alert only applies to versions less than or equal to this version.
	// Other versions should still relay it.
	MaxVer int32

	// If this set contains any elements, then only nodes that have their
	// subVer contained in this set are affected by the alert. Other versions
	// should still relay it.
	SetSubVer []string

	// Relative priority compared to other alerts
	Priority int32

	// A comment on the alert that is not displayed
	Comment string

	// The alert message that is displayed to the user
	StatusBar string

	// Reserved
	Reserved string
}

Alert contains the data deserialized from the MsgAlert payload.

func NewAlert

func NewAlert(version int32, relayUntil int64, expiration int64,
	id int32, cancel int32, setCancel []int32, minVer int32,
	maxVer int32, setSubVer []string, priority int32, comment string,
	statusBar string) *Alert

NewAlert returns an new Alert with values provided.

func NewAlertFromPayload

func NewAlertFromPayload(serializedPayload []byte, pver uint32) (*Alert, error)

NewAlertFromPayload returns an Alert with values deserialized from the serialized payload.

func (*Alert) Deserialize

func (alert *Alert) Deserialize(r io.Reader, pver uint32) error

Deserialize decodes from r into the receiver using the alert protocol encoding format.

func (*Alert) Serialize

func (alert *Alert) Serialize(w io.Writer, pver uint32) error

Serialize encodes the alert to w using the alert protocol encoding format.

type FactomNet

type FactomNet uint32

FactomNet represents which bitcoin network a message belongs to.

const (
	// MainNet represents the main bitcoin network.
	MainNet FactomNet = 0xd9b4bef9

	// TestNet represents the regression test network.
	TestNet FactomNet = 0xdab5bffa

	// TestNet3 represents the test network (version 3).
	TestNet3 FactomNet = 0x0709110b

	// SimNet represents the simulation test network.
	SimNet FactomNet = 0x12141c16
)

Constants used to indicate the message bitcoin network. They can also be used to seek to the next message when a stream's state is unknown, but this package does not provide that functionality since it's generally a better idea to simply disconnect clients that are misbehaving over TCP.

func (FactomNet) String

func (n FactomNet) String() string

String returns the FactomNet in human-readable form.

type InvType

type InvType uint32

InvType represents the allowed types of inventory vectors. See InvVect.

const (
	InvTypeError InvType = 0
	InvTypeTx    InvType = 1

	InvTypeFactomDirBlock   InvType = 4
	InvTypeFactomEntryBlock InvType = 5
	InvTypeFactomEntry      InvType = 6

	InvTypeFactomControl InvType = 10 // Factom control messages
	InvTypeFactomRaw     InvType = 99 // Factom raw
)

These constants define the various supported inventory vector types.

func (InvType) String

func (invtype InvType) String() string

String returns the InvType in human-readable form.

type InvVect

type InvVect struct {
	Type InvType // Type of data
	Hash ShaHash // Hash of the data
}

InvVect defines a bitcoin inventory vector which is used to describe data, as specified by the Type field, that a peer wants, has, or does not have to another peer.

func NewInvVect

func NewInvVect(typ InvType, hash *ShaHash) *InvVect

NewInvVect returns a new InvVect using the provided type and hash.

type Message

type Message interface {
	BtcDecode(io.Reader, uint32) error
	BtcEncode(io.Writer, uint32) error
	Command() string
	MaxPayloadLength(uint32) uint32
}

Message is an interface that describes a bitcoin message. A type that implements Message has complete control over the representation of its data and may therefore contain additional or fewer fields than those which are used directly in the protocol encoded message.

func ReadMessage

func ReadMessage(r io.Reader, pver uint32, btcnet FactomNet) (Message, []byte, error)

ReadMessage reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the parsed Message and raw bytes which comprise the message. This function only differs from ReadMessageN in that it doesn't return the number of bytes read. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.

func ReadMessageN

func ReadMessageN(r io.Reader, pver uint32, btcnet FactomNet) (int, Message, []byte, error)

ReadMessageN reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessage except it also returns the number of bytes read.

type MessageError

type MessageError struct {
	Func        string // Function name
	Description string // Human readable description of the issue
}

MessageError describes an issue with a message. An example of some potential issues are messages from the wrong bitcoin network, invalid commands, mismatched checksums, and exceeding max payloads.

This provides a mechanism for the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that resulted from malformed messages.

func (*MessageError) Error

func (e *MessageError) Error() string

Error satisfies the error interface and prints human-readable errors.

type MsgAddr

type MsgAddr struct {
	AddrList []*NetAddress
}

MsgAddr implements the Message interface and represents a bitcoin addr message. It is used to provide a list of known active peers on the network. An active peer is considered one that has transmitted a message within the last 3 hours. Nodes which have not transmitted in that time frame should be forgotten. Each message is limited to a maximum number of addresses, which is currently 1000. As a result, multiple messages must be used to relay the full list.

Use the AddAddress function to build up the list of known addresses when sending an addr message to another peer.

func NewMsgAddr

func NewMsgAddr() *MsgAddr

NewMsgAddr returns a new bitcoin addr message that conforms to the Message interface. See MsgAddr for details.

func (*MsgAddr) AddAddress

func (msg *MsgAddr) AddAddress(na *NetAddress) error

AddAddress adds a known active peer to the message.

func (*MsgAddr) AddAddresses

func (msg *MsgAddr) AddAddresses(netAddrs ...*NetAddress) error

AddAddresses adds multiple known active peers to the message.

func (*MsgAddr) BtcDecode

func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgAddr) BtcEncode

func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgAddr) ClearAddresses

func (msg *MsgAddr) ClearAddresses()

ClearAddresses removes all addresses from the message.

func (*MsgAddr) Command

func (msg *MsgAddr) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgAddr) MaxPayloadLength

func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgAlert

type MsgAlert struct {
	// SerializedPayload is the alert payload serialized as a string so that the
	// version can change but the Alert can still be passed on by older
	// clients.
	SerializedPayload []byte

	// Signature is the ECDSA signature of the message.
	Signature []byte

	// Deserialized Payload
	Payload *Alert
}

MsgAlert implements the Message interface and defines a bitcoin alert message.

This is a signed message that provides notifications that the client should display if the signature matches the key. bitcoind/bitcoin-qt only checks against a signature from the core developers.

func NewMsgAlert

func NewMsgAlert(serializedPayload []byte, signature []byte) *MsgAlert

NewMsgAlert returns a new bitcoin alert message that conforms to the Message interface. See MsgAlert for details.

func (*MsgAlert) BtcDecode

func (msg *MsgAlert) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgAlert) BtcEncode

func (msg *MsgAlert) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgAlert) Command

func (msg *MsgAlert) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgAlert) MaxPayloadLength

func (msg *MsgAlert) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgCommitChain

type MsgCommitChain struct {
	ECPubKey         *notaryapi.Hash
	ChainID          *notaryapi.Hash
	EntryHash        *notaryapi.Hash
	EntryChainIDHash *notaryapi.Hash
	Credits          uint32
	Timestamp        uint64
	Sig              []byte
}

MsgCommitEntry implements the Message interface and represents a factom Commit-Entry message. It is used by client to commit the entry before revealing it.

func NewMsgCommitChain

func NewMsgCommitChain() *MsgCommitChain

NewMsgInv returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details.

func (*MsgCommitChain) BtcDecode

func (msg *MsgCommitChain) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgCommitChain) BtcEncode

func (msg *MsgCommitChain) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgCommitChain) Command

func (msg *MsgCommitChain) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgCommitChain) MaxPayloadLength

func (msg *MsgCommitChain) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgCommitEntry

type MsgCommitEntry struct {
	ECPubKey  *notaryapi.Hash
	EntryHash *notaryapi.Hash
	Credits   uint32
	Timestamp uint64
	Sig       []byte
}

MsgCommitEntry implements the Message interface and represents a factom Commit-Entry message. It is used by client to commit the entry before revealing it.

func NewMsgCommitEntry

func NewMsgCommitEntry() *MsgCommitEntry

NewMsgInv returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details.

func (*MsgCommitEntry) BtcDecode

func (msg *MsgCommitEntry) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgCommitEntry) BtcEncode

func (msg *MsgCommitEntry) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgCommitEntry) Command

func (msg *MsgCommitEntry) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgCommitEntry) MaxPayloadLength

func (msg *MsgCommitEntry) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgConfirmation

type MsgConfirmation struct {
	Height      uint64
	ChainID     notaryapi.Hash
	Index       uint32
	Affirmation [32]byte
	Hash        [32]byte
	Signature   [64]byte
	MsgHash     *ShaHash // hash of the msg being confirmed, unsure how I can use it yet
}

func NewMsgConfirmation

func NewMsgConfirmation(height uint64, index uint32) *MsgConfirmation

NewMsgConfirmation returns a new bitcoin ping message that conforms to the Message interface. See MsgConfirmation for details.

func (*MsgConfirmation) BtcDecode

func (msg *MsgConfirmation) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgConfirmation) BtcEncode

func (msg *MsgConfirmation) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgConfirmation) Command

func (msg *MsgConfirmation) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgConfirmation) MaxPayloadLength

func (msg *MsgConfirmation) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgGetAddr

type MsgGetAddr struct{}

MsgGetAddr implements the Message interface and represents a bitcoin getaddr message. It is used to request a list of known active peers on the network from a peer to help identify potential nodes. The list is returned via one or more addr messages (MsgAddr).

This message has no payload.

func NewMsgGetAddr

func NewMsgGetAddr() *MsgGetAddr

NewMsgGetAddr returns a new bitcoin getaddr message that conforms to the Message interface. See MsgGetAddr for details.

func (*MsgGetAddr) BtcDecode

func (msg *MsgGetAddr) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetAddr) BtcEncode

func (msg *MsgGetAddr) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetAddr) Command

func (msg *MsgGetAddr) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgGetAddr) MaxPayloadLength

func (msg *MsgGetAddr) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgGetBlocks

type MsgGetBlocks struct {
	ProtocolVersion    uint32
	BlockLocatorHashes []*ShaHash
	HashStop           ShaHash
}

MsgGetBlocks implements the Message interface and represents a bitcoin getblocks message. It is used to request a list of blocks starting after the last known hash in the slice of block locator hashes. The list is returned via an inv message (MsgInv) and is limited by a specific hash to stop at or the maximum number of blocks per message, which is currently 500.

Set the HashStop field to the hash at which to stop and use AddBlockLocatorHash to build up the list of block locator hashes.

The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. In order to keep the list of locator hashes to a reasonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.

func NewMsgGetBlocks

func NewMsgGetBlocks(hashStop *ShaHash) *MsgGetBlocks

NewMsgGetBlocks returns a new bitcoin getblocks message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgGetBlocks) AddBlockLocatorHash

func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *ShaHash) error

AddBlockLocatorHash adds a new block locator hash to the message.

func (*MsgGetBlocks) BtcDecode

func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetBlocks) BtcEncode

func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetBlocks) Command

func (msg *MsgGetBlocks) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgGetBlocks) MaxPayloadLength

func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgInv

type MsgInv struct {
	InvList []*InvVect
}

MsgInv implements the Message interface and represents a bitcoin inv message. It is used to advertise a peer's known data such as blocks and transactions through inventory vectors. It may be sent unsolicited to inform other peers of the data or in response to a getblocks message (MsgGetBlocks). Each message is limited to a maximum number of inventory vectors, which is currently 50,000.

Use the AddInvVect function to build up the list of inventory vectors when sending an inv message to another peer.

func NewMsgInv

func NewMsgInv() *MsgInv

NewMsgInv returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details.

func NewMsgInvSizeHint

func NewMsgInvSizeHint(sizeHint uint) *MsgInv

NewMsgInvSizeHint returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details. This function differs from NewMsgInv in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large amounts of inventory vectors with AddInvVect. Note that the specified hint is just that - a hint that is used for the default allocation size. Adding more (or less) inventory vectors will still work properly. The size hint is limited to MaxInvPerMsg.

func (*MsgInv) AddInvVect

func (msg *MsgInv) AddInvVect(iv *InvVect) error

AddInvVect adds an inventory vector to the message.

func (*MsgInv) BtcDecode

func (msg *MsgInv) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgInv) BtcEncode

func (msg *MsgInv) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgInv) Command

func (msg *MsgInv) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgInv) MaxPayloadLength

func (msg *MsgInv) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgNotFound

type MsgNotFound struct {
	InvList []*InvVect
}

MsgNotFound defines a bitcoin notfound message which is sent in response to a getdata message if any of the requested data in not available on the peer. Each message is limited to a maximum number of inventory vectors, which is currently 50,000.

Use the AddInvVect function to build up the list of inventory vectors when sending a notfound message to another peer.

func NewMsgNotFound

func NewMsgNotFound() *MsgNotFound

NewMsgNotFound returns a new bitcoin notfound message that conforms to the Message interface. See MsgNotFound for details.

func (*MsgNotFound) AddInvVect

func (msg *MsgNotFound) AddInvVect(iv *InvVect) error

AddInvVect adds an inventory vector to the message.

func (*MsgNotFound) BtcDecode

func (msg *MsgNotFound) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgNotFound) BtcEncode

func (msg *MsgNotFound) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgNotFound) Command

func (msg *MsgNotFound) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgNotFound) MaxPayloadLength

func (msg *MsgNotFound) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgPing

type MsgPing struct {
	// Unique value associated with message that is used to identify
	// specific ping message.
	Nonce uint64
}

MsgPing implements the Message interface and represents a bitcoin ping message.

For versions BIP0031Version and earlier, it is used primarily to confirm that a connection is still valid. A transmission error is typically interpreted as a closed connection and that the peer should be removed. For versions AFTER BIP0031Version it contains an identifier which can be returned in the pong message to determine network timing.

The payload for this message just consists of a nonce used for identifying it later.

func NewMsgPing

func NewMsgPing(nonce uint64) *MsgPing

NewMsgPing returns a new bitcoin ping message that conforms to the Message interface. See MsgPing for details.

func (*MsgPing) BtcDecode

func (msg *MsgPing) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgPing) BtcEncode

func (msg *MsgPing) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgPing) Command

func (msg *MsgPing) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgPing) MaxPayloadLength

func (msg *MsgPing) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgPong

type MsgPong struct {
	// Unique value associated with message that is used to identify
	// specific ping message.
	Nonce uint64
}

MsgPong implements the Message interface and represents a bitcoin pong message which is used primarily to confirm that a connection is still valid in response to a bitcoin ping message (MsgPing).

This message was not added until protocol versions AFTER BIP0031Version.

func NewMsgPong

func NewMsgPong(nonce uint64) *MsgPong

NewMsgPong returns a new bitcoin pong message that conforms to the Message interface. See MsgPong for details.

func (*MsgPong) BtcDecode

func (msg *MsgPong) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgPong) BtcEncode

func (msg *MsgPong) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgPong) Command

func (msg *MsgPong) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgPong) MaxPayloadLength

func (msg *MsgPong) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgReject

type MsgReject struct {
	// Cmd is the command for the message which was rejected such as
	// as CmdBlock or CmdTx.  This can be obtained from the Command function
	// of a Message.
	Cmd string

	// RejectCode is a code indicating why the command was rejected.  It
	// is encoded as a uint8 on the wire.
	Code RejectCode

	// Reason is a human-readable string with specific details (over and
	// above the reject code) about why the command was rejected.
	Reason string

	// Hash identifies a specific block or transaction that was rejected
	// and therefore only applies the MsgBlock and MsgTx messages.
	Hash ShaHash
}

MsgReject implements the Message interface and represents a bitcoin reject message.

This message was not added until protocol version RejectVersion.

func NewMsgReject

func NewMsgReject(command string, code RejectCode, reason string) *MsgReject

NewMsgReject returns a new bitcoin reject message that conforms to the Message interface. See MsgReject for details.

func (*MsgReject) BtcDecode

func (msg *MsgReject) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgReject) BtcEncode

func (msg *MsgReject) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgReject) Command

func (msg *MsgReject) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgReject) MaxPayloadLength

func (msg *MsgReject) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgRevealChain

type MsgRevealChain struct {
	Chain *notaryapi.EChain
}

MsgRevealChain implements the Message interface and represents a factom Reveal-Chain message. It is used by client to reveal the chain.

func NewMsgRevealChain

func NewMsgRevealChain() *MsgRevealChain

NewMsgInv returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details.

func (*MsgRevealChain) BtcDecode

func (msg *MsgRevealChain) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgRevealChain) BtcEncode

func (msg *MsgRevealChain) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgRevealChain) Command

func (msg *MsgRevealChain) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRevealChain) MaxPayloadLength

func (msg *MsgRevealChain) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgRevealEntry

type MsgRevealEntry struct {
	Entry *notaryapi.Entry
}

MsgRevealEntry implements the Message interface and represents a factom Reveal-Entry message. It is used by client to reveal the entry.

func NewMsgRevealEntry

func NewMsgRevealEntry() *MsgRevealEntry

NewMsgInv returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details.

func (*MsgRevealEntry) BtcDecode

func (msg *MsgRevealEntry) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgRevealEntry) BtcEncode

func (msg *MsgRevealEntry) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgRevealEntry) Command

func (msg *MsgRevealEntry) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRevealEntry) MaxPayloadLength

func (msg *MsgRevealEntry) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgTx

type MsgTx struct {
	Data []byte
}

this is the wire format for Factoin tx messages

func (*MsgTx) BtcDecode

func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) (err error)

func (*MsgTx) BtcEncode

func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) (err error)

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgTx) Command

func (msg *MsgTx) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgTx) MaxPayloadLength

func (msg *MsgTx) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

func (MsgTx) TxType

func (msg MsgTx) TxType() string

type MsgVerAck

type MsgVerAck struct{}

MsgVerAck defines a bitcoin verack message which is used for a peer to acknowledge a version message (MsgVersion) after it has used the information to negotiate parameters. It implements the Message interface.

This message has no payload.

func NewMsgVerAck

func NewMsgVerAck() *MsgVerAck

NewMsgVerAck returns a new bitcoin verack message that conforms to the Message interface.

func (*MsgVerAck) BtcDecode

func (msg *MsgVerAck) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgVerAck) BtcEncode

func (msg *MsgVerAck) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgVerAck) Command

func (msg *MsgVerAck) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgVerAck) MaxPayloadLength

func (msg *MsgVerAck) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgVersion

type MsgVersion struct {
	// Version of the protocol the node is using.
	ProtocolVersion int32

	// Bitfield which identifies the enabled services.
	Services ServiceFlag

	// Time the message was generated.  This is encoded as an int64 on the wire.
	Timestamp time.Time

	// Address of the remote peer.
	AddrYou NetAddress

	// Address of the local peer.
	AddrMe NetAddress

	// Unique value associated with message that is used to detect self
	// connections.
	Nonce uint64

	// The user agent that generated messsage.  This is a encoded as a varString
	// on the wire.  This has a max length of MaxUserAgentLen.
	UserAgent string

	// Last block seen by the generator of the version message.
	LastBlock int32

	// Don't announce transactions to peer.
	DisableRelayTx bool
}

MsgVersion implements the Message interface and represents a bitcoin version message. It is used for a peer to advertise itself as soon as an outbound connection is made. The remote peer then uses this information along with its own to negotiate. The remote peer must then respond with a version message of its own containing the negotiated values followed by a verack message (MsgVerAck). This exchange must take place before any further communication is allowed to proceed.

func NewMsgVersion

func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64,
	lastBlock int32) *MsgVersion

NewMsgVersion returns a new bitcoin version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func NewMsgVersionFromConn

func NewMsgVersionFromConn(conn net.Conn, nonce uint64,
	lastBlock int32) (*MsgVersion, error)

NewMsgVersionFromConn is a convenience function that extracts the remote and local address from conn and returns a new bitcoin version message that conforms to the Message interface. See NewMsgVersion.

func (*MsgVersion) AddService

func (msg *MsgVersion) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*MsgVersion) AddUserAgent

func (msg *MsgVersion) AddUserAgent(name string, version string,
	comments ...string) error

AddUserAgent adds a user agent to the user agent string for the version message. The version string is not defined to any strict format, although it is recommended to use the form "major.minor.revision" e.g. "2.6.41".

func (*MsgVersion) BtcDecode

func (msg *MsgVersion) BtcDecode(r io.Reader, pver uint32) error

BtcDecode decodes r using the bitcoin protocol encoding into the receiver. The version message is special in that the protocol version hasn't been negotiated yet. As a result, the pver field is ignored and any fields which are added in new versions are optional. This also mean that r must be a *bytes.Buffer so the number of remaining bytes can be ascertained.

This is part of the Message interface implementation.

func (*MsgVersion) BtcEncode

func (msg *MsgVersion) BtcEncode(w io.Writer, pver uint32) error

BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgVersion) Command

func (msg *MsgVersion) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgVersion) HasService

func (msg *MsgVersion) HasService(service ServiceFlag) bool

HasService returns whether the specified service is supported by the peer that generated the message.

func (*MsgVersion) MaxPayloadLength

func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type NetAddress

type NetAddress struct {
	// Last time the address was seen.  This is, unfortunately, encoded as a
	// uint32 on the wire and therefore is limited to 2106.  This field is
	// not present in the bitcoin version message (MsgVersion) nor was it
	// added until protocol version >= NetAddressTimeVersion.
	Timestamp time.Time

	// Bitfield which identifies the services supported by the address.
	Services ServiceFlag

	// IP address of the peer.
	IP net.IP

	// Port the peer is using.  This is encoded in big endian on the wire
	// which differs from most everything else.
	Port uint16
}

NetAddress defines information about a peer on the network including the time it was last seen, the services it supports, its IP address, and port.

func NewNetAddress

func NewNetAddress(addr net.Addr, services ServiceFlag) (*NetAddress, error)

NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.

Note that addr must be a net.TCPAddr. An ErrInvalidNetAddr is returned if it is not.

func NewNetAddressIPPort

func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress

NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and supported services with defaults for the remaining fields.

func (*NetAddress) AddService

func (na *NetAddress) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*NetAddress) HasService

func (na *NetAddress) HasService(service ServiceFlag) bool

HasService returns whether the specified service is supported by the address.

func (*NetAddress) SetAddress

func (na *NetAddress) SetAddress(ip net.IP, port uint16)

SetAddress is a convenience function to set the IP address and port in one call.

type RejectCode

type RejectCode uint8

RejectCode represents a numeric value by which a remote peer indicates why a message was rejected.

const (
	RejectMalformed       RejectCode = 0x01
	RejectInvalid         RejectCode = 0x10
	RejectObsolete        RejectCode = 0x11
	RejectDuplicate       RejectCode = 0x12
	RejectNonstandard     RejectCode = 0x40
	RejectDust            RejectCode = 0x41
	RejectInsufficientFee RejectCode = 0x42
	RejectCheckpoint      RejectCode = 0x43
)

These constants define the various supported reject codes.

func (RejectCode) String

func (code RejectCode) String() string

String returns the RejectCode in human-readable form.

type ServiceFlag

type ServiceFlag uint64

ServiceFlag identifies services supported by a bitcoin peer.

const (
	// SFNodeNetwork is a flag used to indicate a peer is a full node.
	SFNodeNetwork ServiceFlag = 1 << iota
)

func (ServiceFlag) String

func (f ServiceFlag) String() string

String returns the ServiceFlag in human-readable form.

type ShaHash

type ShaHash [HashSize]byte

ShaHash is used in several of the bitcoin messages and common structures. It typically represents the double sha256 of data.

func NewShaHash

func NewShaHash(newHash []byte) (*ShaHash, error)

NewShaHash returns a new ShaHash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.

func NewShaHashFromStr

func NewShaHashFromStr(hash string) (*ShaHash, error)

NewShaHashFromStr creates a ShaHash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the ShaHash.

func NewShaHashFromStruct

func NewShaHashFromStruct(DataStruct interface{}) (*ShaHash, error)

func (*ShaHash) Bytes

func (hash *ShaHash) Bytes() []byte

Bytes returns the bytes which represent the hash as a byte slice.

func (*ShaHash) IsEqual

func (hash *ShaHash) IsEqual(target *ShaHash) bool

IsEqual returns true if target is the same as hash.

func (*ShaHash) SetBytes

func (hash *ShaHash) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.

func (ShaHash) String

func (hash ShaHash) String() string

String returns the ShaHash as the hexadecimal string of the byte-reversed hash.

type TxMessage

type TxMessage interface {
	notaryapi.BinaryMarshallable
	TxType() string
}

TxMessage is an interface that describes a factom transaction message. TxMessage has already been decoded from the wire and is identified as CmdTx.

TxMessage is designed to be used for generic processing of all factom messages such factoid, entry=credit, commit/reveal chain/entry, and confirmations.

Initial implimentation will be for factoid only.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL