Documentation ¶
Overview ¶
Contains functions used for encryption and decryption and serialization and deserialization to/from protocol structures. For more details, refer to: https://bitmessage.org/wiki/Protocol_specification
Index ¶
- Constants
- Variables
- func CreateMessage(command string, payload []byte) []byte
- func CreateVerackMessage() []byte
- func MessageHeaderSize() int
- func UnpackMessageHeader(raw []byte) (command string, payloadLength uint32, checksum [4]byte, err error)
- func VerifyMessageChecksum(payload []byte, checksum [4]byte) bool
- type AddrMessage
- type DecryptablePayload
- type EncryptablePayload
- type GetdataMessage
- type InvMessage
- type InvVector
- type NetworkAddress
- type NetworkAddressShort
- type ObjectMessage
- func (msg *ObjectMessage) DeserializeReader(b io.Reader) error
- func (msg *ObjectMessage) GenerateForeignIdentity() (*identity.Foreign, error)
- func (msg *ObjectMessage) HeaderSerialize() []byte
- func (msg *ObjectMessage) Preserialize(id *identity.Own, target *identity.Foreign) error
- func (msg *ObjectMessage) Serialize() []byte
- func (msg *ObjectMessage) TryDecrypt(ownId *identity.Own, address *identity.Address) (bool, error)
- type ObjectType
- type PublicKeysAddablePayload
- type SignablePayload
- type TaggableEncryptedPayload
- type VersionMessage
Constants ¶
const ( GetpubkeyObject = ObjectType(iota) PubkeyObject MsgObject BroadcastObject )
Variables ¶
var InvalidPayloadOperationError = errors.New("intended operation not defined" +
" for this payload")
Functions ¶
func CreateMessage ¶
CreateMessage create a message in the format required by the protocol specification. https://bitmessage.org/wiki/Protocol_specification#Message_structure
func CreateVerackMessage ¶
func CreateVerackMessage() []byte
Create a response to the version message (verack)
func MessageHeaderSize ¶
func MessageHeaderSize() int
MessageHeaderSize returns the size of the message header
func UnpackMessageHeader ¶
func UnpackMessageHeader(raw []byte) (command string, payloadLength uint32, checksum [4]byte, err error)
UnpackMessageHeader unpacks the header of the received message.
func VerifyMessageChecksum ¶
VerifyMessageChecksum verifies the checksum on the payload of a message to see if it has been correctly received.
Types ¶
type AddrMessage ¶
type AddrMessage struct {
Addresses []NetworkAddress
}
Provide information on known nodes of the network. Non-advertised nodes should be forgotten after typically 3 hours. (max 1000 items)
func (*AddrMessage) DeserializeReader ¶
func (msg *AddrMessage) DeserializeReader(b io.Reader) error
func (*AddrMessage) Serialize ¶
func (msg *AddrMessage) Serialize() []byte
type DecryptablePayload ¶
type DecryptablePayload interface { // Decrypt reverses the operation performed by Encrypt and transforms the // payload back to its unencrypted form. Decrypt(*elliptic.PrivateKey) (types.Serializer, error) }
DecryptablePayload represents payloads that was originally in the encrypted form while being transfered on network.
type EncryptablePayload ¶
type EncryptablePayload interface { // Encrypt makes the payload encrypt itself for the target public key and // return a transformed payload (the encrypted form of itself). Encrypt(*elliptic.PublicKey) (types.Serializer, error) }
EncryptablePayload represents payloads that need to be encrypted before being sent on the network.
type GetdataMessage ¶
type GetdataMessage struct {
Items []InvVector
}
getdata is used in response to an inv message to retrieve the content of a specific object after filtering known elements. (maximum 50000 items)
func (*GetdataMessage) DeserializeReader ¶
func (msg *GetdataMessage) DeserializeReader(b io.Reader) error
func (*GetdataMessage) Serialize ¶
func (msg *GetdataMessage) Serialize() []byte
type InvMessage ¶
type InvMessage struct {
Items []InvVector
}
Allows a node to advertise its knowledge of one or more objects. (maximum 50000 items)
func (*InvMessage) DeserializeReader ¶
func (msg *InvMessage) DeserializeReader(b io.Reader) error
func (*InvMessage) Serialize ¶
func (msg *InvMessage) Serialize() []byte
type InvVector ¶
type InvVector [32]byte
Inventory vectors are used for notifying other nodes about objects they have or data which is being requested. Two rounds of SHA-512 are used, resulting in a 64 byte hash. Only the first 32 bytes are used; the later 32 bytes are ignored.
func CalculateInvVector ¶
CalculateInvVector returns an InvVector for the corresponding message.
type NetworkAddress ¶
type NetworkAddress struct { Time int64 // 8 byte UNIX time Stream uint32 Services uint64 IP net.IP Port uint16 }
When a network address is needed somewhere, this structure is used.
func (*NetworkAddress) DeserializeReader ¶
func (addr *NetworkAddress) DeserializeReader(b io.Reader) error
func (*NetworkAddress) Serialize ¶
func (addr *NetworkAddress) Serialize() []byte
type NetworkAddressShort ¶
Network address structure used for VersionMessage. Addresses are not prefixed with a timestamp or stream in the version message.
func (*NetworkAddressShort) DeserializeReader ¶
func (addr *NetworkAddressShort) DeserializeReader(b io.Reader) error
func (*NetworkAddressShort) Serialize ¶
func (addr *NetworkAddressShort) Serialize() []byte
type ObjectMessage ¶
type ObjectMessage struct { Nonce uint64 // TTL tells how long the object message should be valid from the time of // PoW. It is not serialized but is used, along with a random interval of // time defined in constants (ObjectTTLRandRange), to calculate expiresTime. // Has to be greater than the duration specified in ObjectTTLRandRange or // the result might turn out to be negative. TTL time.Duration ObjectType ObjectType Version types.Varint Stream types.Varint Payload types.Serializer // contains filtered or unexported fields }
An object is a message which is shared throughout a stream. It is the only message which propagates; all others are only between two nodes. Objects have a type, like 'msg', or 'broadcast'. To be a valid object, the Proof Of Work must be done (which is stored in Nonce).
func (*ObjectMessage) DeserializeReader ¶
func (msg *ObjectMessage) DeserializeReader(b io.Reader) error
func (*ObjectMessage) GenerateForeignIdentity ¶
func (msg *ObjectMessage) GenerateForeignIdentity() (*identity.Foreign, error)
GenerateForeignIdentity generates an identity.Foreign object based on the type of public key that we have (if it is a public key).
func (*ObjectMessage) HeaderSerialize ¶
func (msg *ObjectMessage) HeaderSerialize() []byte
HeaderSerialize is responsible for serializing the object message header (excluding the nonce) for use in signing of the payload.
func (*ObjectMessage) Preserialize ¶
Preserialize is responsible for embedding the public signing and encryption keys, setting the POW parameters like nonce trials per byte and extra bytes, signing the unencrypted message, encrypting the object, setting the tags, calculating and setting the expiration time and then doing POW. The function is meant to be used only when the object is created from scratch, not when it is being propogated.
func (*ObjectMessage) Serialize ¶
func (msg *ObjectMessage) Serialize() []byte
func (*ObjectMessage) TryDecrypt ¶
TryDecrypt tries to decrypt the payload, which could be a message, broadcast, or v4 pubkey, and returns whether it was successful or not, along with any error. It changes the payload to its unencrypted form in the process. Error is only returned if decryption didn't fail due to invalid key.
type ObjectType ¶
type ObjectType uint32
ObjectType tells the type of payload that the object message contains.
type PublicKeysAddablePayload ¶
type PublicKeysAddablePayload interface { // SetSigningAndEncryptionKeys sets the PubSigningKey and PubEncryptionKey // fields of the payload. SetSigningAndEncryptionKeys([]byte, []byte) }
PublicKeysAddablePayload represents payload that requires addition of signing and encryption public keys to it.
type SignablePayload ¶
type SignablePayload interface { // SignatureSerialize gets the part of the payload that has to be appended // to object message header for signing. SignatureSerialize() []byte // SetSignature sets the value of the Signature field of the payload. SetSignature([]byte) }
SignablePayload represents payload which can have a signature added to it.
type TaggableEncryptedPayload ¶
type TaggableEncryptedPayload interface { // SetTag is used to set the tag of the encrypted payload. SetTag([]byte) }
TaggableEncryptedPayload represents encrypted payloads that have a tag.
type VersionMessage ¶
type VersionMessage struct { Version uint32 Services int64 Timestamp int64 // UNIX time AddrRecv NetworkAddressShort AddrFrom NetworkAddressShort Nonce uint64 // Random nonce UserAgent types.Varstring Streams types.VarintList }
When a node creates an outgoing connection, it will immediately advertise its version. The remote node will respond with its version. No futher communication is possible until both peers have exchanged their version.
func (*VersionMessage) DeserializeReader ¶
func (msg *VersionMessage) DeserializeReader(b io.Reader) error
func (*VersionMessage) Serialize ¶
func (msg *VersionMessage) Serialize() []byte
Directories ¶
Path | Synopsis |
---|---|
Objects package contains all the object types as defined in v3 of the protocol specifications.
|
Objects package contains all the object types as defined in v3 of the protocol specifications. |
Package containing the types and errors used by all other packages.
|
Package containing the types and errors used by all other packages. |