protocol

package
v0.0.0-...-10088a8 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2015 License: MIT Imports: 16 Imported by: 0

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

View Source
const (
	GetpubkeyObject = ObjectType(iota)
	PubkeyObject
	MsgObject
	BroadcastObject
)

Variables

This section is empty.

Functions

func CreateMessage

func CreateMessage(command string, payload []byte) []byte

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 DeserializeTo

func DeserializeTo(to Serializer, raw []byte) error

A common function for deserializing a byte array into an instance of the object using the defined DeserializeReader method.

func MessageHeaderSize

func MessageHeaderSize() int

Return the size of the message header

func UnpackMessageHeader

func UnpackMessageHeader(raw []byte) (command string, payloadLength uint32,
	checksum [4]byte, err error)

Unpack the header of the received message.

func VerifyMessageChecksum

func VerifyMessageChecksum(payload []byte, checksum [4]byte) bool

Verify 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 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) (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

func CalculateInvVector(message []byte) InvVector

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

type NetworkAddressShort struct {
	Services uint64
	IP       net.IP
	Port     uint16
}

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    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) 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

func (msg *ObjectMessage) Preserialize(id *identity.Own,
	target *identity.Foreign) error

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.

func (*ObjectMessage) Serialize

func (msg *ObjectMessage) Serialize() []byte

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 Serializer

type Serializer interface {
	// Serialize the object into bytes
	Serialize() []byte
	// Deserialize the object from io.Reader
	DeserializeReader(io.Reader) error
}

Interface defined for every message and serializable type.

type SignablePayload

type SignablePayload interface {
	Serializer
	// 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.

Jump to

Keyboard shortcuts

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