Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeMessage(msg Message) []byte
- func EncodeMsgObjectHeader(w io.Writer, nonce uint64, expiresTime time.Time, objectType ObjectType, ...) error
- func RandomUint64() (uint64, error)
- func WriteMessage(w io.Writer, msg Message, bmnet BitmessageNet) error
- func WriteMessageN(w io.Writer, msg Message, bmnet BitmessageNet) (int, error)
- type BitmessageNet
- type InvVect
- type Message
- type MessageError
- type MsgAddr
- func (msg *MsgAddr) AddAddress(na *NetAddress) error
- func (msg *MsgAddr) AddAddresses(netAddrs ...*NetAddress) error
- func (msg *MsgAddr) ClearAddresses()
- func (msg *MsgAddr) Command() string
- func (msg *MsgAddr) Decode(r io.Reader) error
- func (msg *MsgAddr) Encode(w io.Writer) error
- func (msg *MsgAddr) MaxPayloadLength() int
- type MsgBroadcast
- type MsgGetData
- type MsgGetPubKey
- type MsgInv
- type MsgMsg
- type MsgPubKey
- type MsgUnknownObject
- type MsgVerAck
- type MsgVersion
- func (msg *MsgVersion) AddService(service ServiceFlag)
- func (msg *MsgVersion) AddUserAgent(name string, version string, comments ...string) error
- func (msg *MsgVersion) Command() string
- func (msg *MsgVersion) Decode(r io.Reader) error
- func (msg *MsgVersion) Encode(w io.Writer) error
- func (msg *MsgVersion) HasService(service ServiceFlag) bool
- func (msg *MsgVersion) MaxPayloadLength() int
- type NetAddress
- type ObjectType
- type PubKey
- type RipeHash
- type ServiceFlag
- type ShaHash
Constants ¶
const ( CmdVersion = "version" CmdVerAck = "verack" CmdAddr = "addr" CmdInv = "inv" CmdGetData = "getdata" CmdObject = "object" )
Commands used in bitmessage message headers which describe the type of message.
const ( // SimplePubKeyVersion is the version in which pubkeys are sent unencrypted // without any details of PoW required by the sender. SimplePubKeyVersion = 2 // ExtendedPubKeyVersion is the version in which pubkeys are sent // unencrypted with details of PoW required by the sender. ExtendedPubKeyVersion = 3 // EncryptedPubKeyVersion is the version from which pubkeys started to be // sent as an encrypted ExtendedPubKey, decryptable by those who had the // addresses of the owners of those keys. EncryptedPubKeyVersion = 4 )
const CommandSize = 12
CommandSize is the fixed size of all commands in the common bitmessage message header. Shorter commands must be zero padded.
const DefaultUserAgent = "/wire:0.1.0/"
DefaultUserAgent for wire
const HashSize = 32
HashSize is the size of the array used to store SHA hashes.
const HashStringSize = HashSize * 2
HashStringSize is the maximum length of a ShaHash hash string.
const MaxAddrPerMsg = 1000
MaxAddrPerMsg is the maximum number of addresses that can be in a single bitmessage addr message (MsgAddr).
const ( // MaxInvPerMsg is the maximum number of inventory vectors that can be in a // single bitmessage inv message. MaxInvPerMsg = 50000 )
const MaxMessagePayload = 1600100
MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves. ~1.6 MB, which is which is the maximum possible size of an inv message.
const ( // MaxPayloadOfMsgObject is the the maximum payload of object message = 2^18 bytes. // (not to be confused with the object payload) MaxPayloadOfMsgObject = 262144 )
const MaxPubKeyStringSize = PubKeySize * 2
MaxPubKeyStringSize is the maximum length of a PubKey string.
const MaxStreams = 1
MaxStreams is the maximum number of allowed streams to request according to the bitmessage protocol. Keeping it at 1 for now.
const MaxUserAgentLen = 5000
MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).
const MessageHeaderSize = 24
MessageHeaderSize is the number of bytes in a bitmessage message header. Bitmessage network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.
const ( // ProtocolVersion is the latest protocol version this package supports. ProtocolVersion uint32 = 3 )
const PubKeySize = 64
PubKeySize is the size of array used to store uncompressed public keys. Note that the first byte (0x04) is excluded when storing them.
const RipeHashSize = 20
RipeHashSize is the size of array used to store ripe hashes.
const RipeHashStringSize = RipeHashSize * 2
HashStringSize is the maximum length of a Ripe hash string.
const ( // TagBroadcastVersion is the broadcast version from which tags for light // clients started being added at the beginning of the broadcast message. TagBroadcastVersion = 5 )
const ( // TagGetPubKeyVersion specifies the version of MsgGetPubKey from which // tags started being encoded in messages and not ripe. This was done to // thwart any public key/address harvesting attempts. TagGetPubKeyVersion = 4 )
Variables ¶
var ErrHashStrSize = fmt.Errorf("string length must be %v chars", HashStringSize)
ErrHashStrSize describes an error that indicates the caller specified a hash string that does not have the right number of characters.
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.
var ErrPubKeyStrSize = fmt.Errorf("string length must be %v chars", MaxPubKeyStringSize)
ErrPubKeyStrSize describes an error that indicates the caller specified a PubKey string that does not have the right number of characters.
var ErrRipeHashStrSize = fmt.Errorf("string length must be %v chars", RipeHashStringSize)
ErrRipeHashStrSize describes an error that indicates the caller specified a hash string that does not have the right number of characters.
Functions ¶
func EncodeMessage ¶
EncodeMessage takes a message and returns a representation of it as a byte array as the message would appear in the database. This array is missing the the standard bitmessage header that goes along with every message sent over the p2p connection.
func EncodeMsgObjectHeader ¶
func EncodeMsgObjectHeader(w io.Writer, nonce uint64, expiresTime time.Time, objectType ObjectType, version uint64, streamNumber uint64) error
EncodeMsgObjectHeader encodes the object header to the given writer. Object header consists of Nonce, ExpiresTime, ObjectType, Version and Stream, in that order. Read Protocol Specifications for more information.
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
func WriteMessage ¶
func WriteMessage(w io.Writer, msg Message, bmnet BitmessageNet) error
WriteMessage writes a bitmessage 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 ¶
WriteMessageN writes a bitmessage 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 BitmessageNet ¶
type BitmessageNet uint32
BitmessageNet represents which bitmessage network a message belongs to.
const ( // MainNet represents the main bitmessage network. MainNet BitmessageNet = 0xe9beb4d9 )
Constants used to indicate the message bitmessage 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 (BitmessageNet) String ¶
func (n BitmessageNet) String() string
String returns the BitmessageNet in human-readable form.
type InvVect ¶
type InvVect struct {
Hash ShaHash // Hash of the data
}
InvVect defines a bitmessage 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 ¶
NewInvVect returns a new InvVect using the provided type and hash.
type Message ¶
type Message interface { Decode(io.Reader) error Encode(io.Writer) error Command() string MaxPayloadLength() int }
Message is an interface that describes a bitmessage 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 DecodeMsgObject ¶
DecodeMsgObject takes a byte array and turns it into an object message.
func ReadMessage ¶
ReadMessage reads, validates, and parses the next bitmessage Message from r for bitmessage 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 useful for callers that don't care about byte counts.
func ReadMessageN ¶
ReadMessageN reads, validates, and parses the next bitmessage Message from r for the provided protocol version and bitmessage 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 bitmessage 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 bitmessage 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 bitmessage 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) ClearAddresses ¶
func (msg *MsgAddr) ClearAddresses()
ClearAddresses removes all addresses from the message.
func (*MsgAddr) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgAddr) Decode ¶
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgAddr) Encode ¶
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgAddr) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgBroadcast ¶
type MsgBroadcast struct { Nonce uint64 ExpiresTime time.Time ObjectType ObjectType Version uint64 StreamNumber uint64 Tag *ShaHash Encrypted []byte AddressVersion uint64 FromStreamNumber uint64 Behavior uint32 SigningKey *PubKey EncryptKey *PubKey NonceTrials uint64 ExtraBytes uint64 Destination *RipeHash Encoding uint64 Message []byte Signature []byte }
MsgBroadcast implements the Message interface and represents a broadcast message that can be decrypted by all the clients that know the address of the sender.
func NewMsgBroadcast ¶
func NewMsgBroadcast(nonce uint64, expires time.Time, version, streamNumber uint64, tag *ShaHash, encrypted []byte, addressVersion, fromStreamNumber uint64, behavior uint32, signingKey, encryptKey *PubKey, nonceTrials, extraBytes uint64, destination *RipeHash, encoding uint64, message, signature []byte) *MsgBroadcast
NewMsgBroadcast returns a new object message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgBroadcast) Command ¶
func (msg *MsgBroadcast) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgBroadcast) Decode ¶
func (msg *MsgBroadcast) Decode(r io.Reader) error
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgBroadcast) Encode ¶
func (msg *MsgBroadcast) Encode(w io.Writer) error
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgBroadcast) MaxPayloadLength ¶
func (msg *MsgBroadcast) MaxPayloadLength() int
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgBroadcast) String ¶
func (msg *MsgBroadcast) String() string
type MsgGetData ¶
type MsgGetData struct {
InvList []*InvVect
}
MsgGetData implements the Message interface and represents a bitmessage getdata message. It is used to request data such as messages and broadcasts from another peer. It should be used in response to the inv (MsgInv) message to request the actual data referenced by each inventory vector the receiving peer doesn't already have. Each message is limited to a maximum number of inventory vectors, which is currently 50,000. As a result, multiple messages must be used to request larger amounts of data.
Use the AddInvVect function to build up the list of inventory vectors when sending a getdata message to another peer.
func NewMsgGetData ¶
func NewMsgGetData() *MsgGetData
NewMsgGetData returns a new bitmessage getdata message that conforms to the Message interface. See MsgGetData for details.
func NewMsgGetDataSizeHint ¶
func NewMsgGetDataSizeHint(sizeHint uint) *MsgGetData
NewMsgGetDataSizeHint returns a new bitmessage getdata message that conforms to the Message interface. See MsgGetData for details. This function differs from NewMsgGetData 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 (*MsgGetData) AddInvVect ¶
func (msg *MsgGetData) AddInvVect(iv *InvVect) error
AddInvVect adds an inventory vector to the message.
func (*MsgGetData) Command ¶
func (msg *MsgGetData) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetData) Decode ¶
func (msg *MsgGetData) Decode(r io.Reader) error
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetData) Encode ¶
func (msg *MsgGetData) Encode(w io.Writer) error
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgGetData) MaxPayloadLength ¶
func (msg *MsgGetData) MaxPayloadLength() int
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetPubKey ¶
type MsgGetPubKey struct { Nonce uint64 ExpiresTime time.Time ObjectType ObjectType Version uint64 StreamNumber uint64 Ripe *RipeHash Tag *ShaHash }
MsgGetPubKey implements the Message interface and represents a request for a public key. If Version <= TagGetPubKeyVersion, tag is encoded in message and not ripe.
func NewMsgGetPubKey ¶
func NewMsgGetPubKey(nonce uint64, expires time.Time, version, streamNumber uint64, ripe *RipeHash, tag *ShaHash) *MsgGetPubKey
NewMsgGetPubKey returns a new object message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgGetPubKey) Command ¶
func (msg *MsgGetPubKey) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetPubKey) Decode ¶
func (msg *MsgGetPubKey) Decode(r io.Reader) error
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetPubKey) Encode ¶
func (msg *MsgGetPubKey) Encode(w io.Writer) error
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgGetPubKey) MaxPayloadLength ¶
func (msg *MsgGetPubKey) MaxPayloadLength() int
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgGetPubKey) String ¶
func (msg *MsgGetPubKey) String() string
type MsgInv ¶
type MsgInv struct {
InvList []*InvVect
}
MsgInv implements the Message interface and represents a bitmessage inv message. It is used to advertise a peer's known data such as messages and broadcasts through inventory vectors. 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 bitmessage inv message that conforms to the Message interface. See MsgInv for details.
func NewMsgInvSizeHint ¶
NewMsgInvSizeHint returns a new bitmessage 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 ¶
AddInvVect adds an inventory vector to the message.
func (*MsgInv) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgInv) Decode ¶
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgInv) Encode ¶
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgInv) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgMsg ¶
type MsgMsg struct { Nonce uint64 ExpiresTime time.Time ObjectType ObjectType Version uint64 StreamNumber uint64 Encrypted []byte AddressVersion uint64 FromStreamNumber uint64 Behavior uint32 SigningKey *PubKey EncryptionKey *PubKey NonceTrials uint64 ExtraBytes uint64 Destination *RipeHash Encoding uint64 Message []byte Ack []byte Signature []byte }
MsgMsg implements the Message interface and represents a message sent between two addresses. It can be decrypted only by those that have the private encryption key that corresponds to the destination address.
func NewMsgMsg ¶
func NewMsgMsg(nonce uint64, expires time.Time, version, streamNumber uint64, encrypted []byte, addressVersion, fromStreamNumber uint64, behavior uint32, signingKey, encryptKey *PubKey, nonceTrials, extraBytes uint64, destination *RipeHash, encoding uint64, message, ack, signature []byte) *MsgMsg
NewMsgMsg returns a new object message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgMsg) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgMsg) Decode ¶
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgMsg) Encode ¶
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgMsg) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgPubKey ¶
type MsgPubKey struct { Nonce uint64 ExpiresTime time.Time ObjectType ObjectType Version uint64 StreamNumber uint64 Behavior uint32 SigningKey *PubKey EncryptionKey *PubKey NonceTrials uint64 ExtraBytes uint64 Signature []byte Tag *ShaHash Encrypted []byte }
MsgPubKey implements the Message interface and represents a pubkey sent in response to MsgGetPubKey.
func NewMsgPubKey ¶
func NewMsgPubKey(nonce uint64, expires time.Time, version, streamNumber uint64, behavior uint32, signingKey, encryptKey *PubKey, nonceTrials, extraBytes uint64, signature []byte, tag *ShaHash, encrypted []byte) *MsgPubKey
NewMsgPubKey returns a new object message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgPubKey) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgPubKey) Decode ¶
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgPubKey) Encode ¶
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgPubKey) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgUnknownObject ¶
type MsgUnknownObject struct { Nonce uint64 ExpiresTime time.Time ObjectType ObjectType Version uint64 StreamNumber uint64 Payload []byte }
MsgUnknownObject implements the Message interface and represents an unknown object.
func NewMsgUnknownObject ¶
func NewMsgUnknownObject(nonce uint64, expires time.Time, objectType ObjectType, version, streamNumber uint64, payload []byte) *MsgUnknownObject
NewMsgUnknownObject returns a new object message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgUnknownObject) Command ¶
func (msg *MsgUnknownObject) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgUnknownObject) Decode ¶
func (msg *MsgUnknownObject) Decode(r io.Reader) error
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgUnknownObject) Encode ¶
func (msg *MsgUnknownObject) Encode(w io.Writer) error
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgUnknownObject) MaxPayloadLength ¶
func (msg *MsgUnknownObject) MaxPayloadLength() int
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgUnknownObject) String ¶
func (msg *MsgUnknownObject) String() string
type MsgVerAck ¶
type MsgVerAck struct{}
MsgVerAck defines a bitmessage 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 bitmessage verack message that conforms to the Message interface.
func (*MsgVerAck) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgVerAck) Decode ¶
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgVerAck) Encode ¶
Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.
func (*MsgVerAck) MaxPayloadLength ¶
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 // The stream numbers of interest. StreamNumbers []uint32 }
MsgVersion implements the Message interface and represents a bitmessage 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, streams []uint32) *MsgVersion
NewMsgVersion returns a new bitmessage 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, currentStream uint32, allStreams []uint32) (*MsgVersion, error)
NewMsgVersionFromConn is a convenience function that extracts the remote and local address from conn and returns a new bitmessage 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) 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) Decode ¶
func (msg *MsgVersion) Decode(r io.Reader) error
Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgVersion) Encode ¶
func (msg *MsgVersion) Encode(w io.Writer) error
Encode encodes the receiver to w using the bitmessage protocol encoding. 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() int
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. Timestamp time.Time // Stream that the address is a member of. Stream uint32 // 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, stream uint32, 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, stream uint32, services ServiceFlag) *NetAddress
NewNetAddressIPPort returns a new NetAddress using the provided IP, port, stream and supported services with Timestamp being time.Now().
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 ObjectType ¶
type ObjectType uint32
ObjectType represents the type of object than an object message contains. Objects in bitmessage are things on the network that get propagated. This can include requests/responses for pubkeys, messages and broadcasts.
const ( ObjectTypeGetPubKey ObjectType = 0 ObjectTypePubKey ObjectType = 1 ObjectTypeMsg ObjectType = 2 ObjectTypeBroadcast ObjectType = 3 )
There are five types of objects in bitmessage.
- GetPubKey: requests for public keys.
- PubKey: public keys sent in response.
- Msg: bitmessage messages.
- Broadcast: broadcast messages.
An ObjectType can also take on other values representing unknown message types.
func DecodeMsgObjectHeader ¶
func DecodeMsgObjectHeader(r io.Reader) (nonce uint64, expiresTime time.Time, objectType ObjectType, version uint64, streamNumber uint64, err error)
DecodeMsgObjectHeader decodes the object header from given reader. Object header consists of Nonce, ExpiresTime, ObjectType, Version and Stream, in that order. Read Protocol Specifications for more information.
func (ObjectType) String ¶
func (t ObjectType) String() string
type PubKey ¶
type PubKey [PubKeySize]byte
PubKey is used in several of the bitmessage messages and common structures. The first 32 bytes contain the X value and the other 32 contain the Y value.
func NewPubKey ¶
NewPubKey returns a new PubKey from a byte slice. An error is returned if the number of bytes passed in is not PubKeySize.
func NewPubKeyFromStr ¶
NewPubKeyFromStr creates a PubKey from a hash string. The string should be the hexadecimal string of the PubKey.
func (*PubKey) SetBytes ¶
SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not PubKeySize.
type RipeHash ¶
type RipeHash [RipeHashSize]byte
RipeHash is used in several of the bitmessage messages and common structures. It typically represents the double sha512 of ripemd160 of data.
func NewRipeHash ¶
NewRipeHash returns a new RipeHash from a byte slice. An error is returned if the number of bytes passed in is not RipeHashSize.
func NewRipeHashFromStr ¶
NewRipeHashFromStr creates a RipeHash from a hash string. The string should be the hexadecimal string of a byte hash.
type ServiceFlag ¶
type ServiceFlag uint64
ServiceFlag identifies services supported by a bitmessage 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 ¶
ShaHash is used in several of the bitmessage messages and common structures. It typically represents a half of the double SHA512 of data.
func MessageHash ¶
MessageHash takes a message and returns its hash (double sha512, as per the bitmessage protocol) as it would be indexed in the database.
func NewShaHash ¶
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 ¶
NewShaHashFromStr creates a ShaHash from a hash string. The string should be the hexadecimal string of a hash.