wire

package
Version: v0.0.0-...-4071b33 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MainNet uint32 = 0xbd6b0cbf
	TestNet uint32 = 0xffcae2ce
)

Constants for magic network version number.

View Source
const (
	MessageTypeVersion = "version"
	MessageTypeVerAck  = "verack"
)

Constants for all known Dash protocol message types.

View Source
const (
	// MaxUserAgentLength specifies the maximum size of a user agent string.
	MaxUserAgentLength = 256

	// VersionNetAddressLength specifies the length of a NetAddress included in a
	// version message.
	VersionNetAddressLength = 26

	// BaseVersionPayloadLength specifies the length of the non-variable parts of
	// a version message.
	BaseVersionPayloadLength = 33 + (VersionNetAddressLength * 2)
)
View Source
const (
	NetAddressWithTimestampSize = 30
	NetAddressSize              = 26
)

Constants for the expected size of a network address.

View Source
const MaxMessagePayloadLength = (1024 * 1024 * 32)

MaxMessagePayloadLength is the maximum bytes a message payload can be.

View Source
const MaxVarIntLength = 9

MaxVarIntLength is the maximum size of a var int.

View Source
const MessageHeaderSize = 24

MessageHeaderSize is the expected size of a message header.

View Source
const MinimumSupportedProtocol = Proto70208

MinimumSupportedProtocol is the current minimum protocol version supported.

View Source
const VerAckPayloadLength = 0

VerAckPayloadLength specifies the length of the verack payload.

Variables

This section is empty.

Functions

func Network

func Network() uint32

Network returns the configured Dash network.

func WriteMessage

func WriteMessage(w io.Writer, msg Message) (int, error)

WriteMessage writes a message to the wire.

func WriteVerAckMessage

func WriteVerAckMessage(w io.Writer) (int, error)

WriteVerAckMessage writes a verack message to the writer.

func WriteVersionMessage

func WriteVersionMessage(w io.Writer, ip string, port uint16) (int, error)

WriteVersionMessage writes a version message to the writer.

Types

type Message

type Message interface {
	Type() string
	Marshal() ([]byte, error)
	Unmarshal([]byte) (int, error)
	MaxPayloadLength(proto ProtocolVersion) int
}

Message can be encoded and decoded to be send on the wire.

func ReadMessage

func ReadMessage(r io.Reader, network uint32) (int, Message, error)

ReadMessage reads a single message from the wire.

type MessageHeader

type MessageHeader struct {
	Network  uint32
	MsgType  string
	Length   int
	Checksum [4]byte
}

MessageHeader holds data about any kind of network message.

func NewMessageHeader

func NewMessageHeader(network uint32, msgtype string, payload []byte) *MessageHeader

NewMessageHeader returns an initialised network header message.

func (*MessageHeader) Marshal

func (mh *MessageHeader) Marshal() []byte

Marshal marshalls the MessageHeader to a []byte.

func (*MessageHeader) Unmarshal

func (mh *MessageHeader) Unmarshal(buf []byte) error

Unmarshal unmarshalls a []byte.

type NetAddress

type NetAddress struct {
	Timestamp time.Time
	Services  ServiceFlag
	IP        net.IP
	Port      uint16
}

NetAddress defines information about a peer on the network.

func (*NetAddress) Marshal

func (na *NetAddress) Marshal(timestamp bool) []byte

Marshal marshalls the NetAddress to a []byte.

func (*NetAddress) Unmarshal

func (na *NetAddress) Unmarshal(buf []byte, timestamp bool) (int, error)

Unmarshal unmarshalls a []byte.

type ProtocolVersion

type ProtocolVersion int32

ProtocolVersion identifies Dash protocol versions supported by a Dash peer.

const (
	Proto70208 ProtocolVersion = 70208
	Proto70206 ProtocolVersion = 70206
	Proto70103 ProtocolVersion = 70103
	Proto70076 ProtocolVersion = 70076
	Proto70066 ProtocolVersion = 70066
	Proto70052 ProtocolVersion = 70052
	Proto70002 ProtocolVersion = 70002
)

All known Dash protocol versions.

type ServiceFlag

type ServiceFlag uint64

ServiceFlag identifies services supported by a Dash peer.

const (
	SFNodeNetwork ServiceFlag = 1 << iota
	SFNodeGetUTXO
	SFNodeBloom
)

All known service identifiers.

type VarInt

type VarInt uint64

VarInt represents a positive integer that can be written on the Dash protocol.

func (VarInt) Marshal

func (vi VarInt) Marshal() ([]byte, error)

Marshal marshalls the VarString to a []byte.

func (*VarInt) Unmarshal

func (vi *VarInt) Unmarshal(buf []byte) (int, error)

Unmarshal unmarshalls a []byte.

type VarString

type VarString string

VarString represents a string that can be written on the Dash protocol.

func (VarString) Marshal

func (vs VarString) Marshal() ([]byte, error)

Marshal marshalls the VarString to a []bytes.

func (VarString) String

func (vs VarString) String() string

func (*VarString) Unmarshal

func (vs *VarString) Unmarshal(buf []byte) (int, error)

Unmarshal unmarshalls a []byte.

type VerAck

type VerAck struct{}

VerAck defines the structure of a Dash protocol verack message.

func (*VerAck) Marshal

func (va *VerAck) Marshal() ([]byte, error)

Marshal marshalls the VerAck to a []byte.

func (*VerAck) MaxPayloadLength

func (va *VerAck) MaxPayloadLength(proto ProtocolVersion) int

MaxPayloadLength returns the maximum allowed length of a verack message.

func (*VerAck) Type

func (va *VerAck) Type() string

Type returns the message type.

func (*VerAck) Unmarshal

func (va *VerAck) Unmarshal([]byte) (int, error)

Unmarshal unmarshalls a []byte.

type Version

type Version struct {
	Version     ProtocolVersion
	Services    ServiceFlag
	Timestamp   time.Time
	AddrRecv    NetAddress
	AddrFrom    NetAddress
	Nonce       uint64
	UserAgent   VarString
	StartHeight int32
	Relay       bool
}

Version defines the structure of a Dash protocol version message.

func (*Version) Marshal

func (v *Version) Marshal() ([]byte, error)

Marshal marshalls the Version to a []byte.

func (*Version) MaxPayloadLength

func (v *Version) MaxPayloadLength(proto ProtocolVersion) int

MaxPayloadLength returns the maximum allowed length of a Version message.

func (*Version) Type

func (v *Version) Type() string

Type returns the message type.

func (*Version) Unmarshal

func (v *Version) Unmarshal(buf []byte) (int, error)

Unmarshal unmarshalls a []byte.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL