levin

package
v0.0.0-...-910450c Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BoostSerializeTypeInt64 byte = 0x1
	BoostSerializeTypeInt32 byte = 0x2
	BoostSerializeTypeInt16 byte = 0x3
	BoostSerializeTypeInt8  byte = 0x4

	BoostSerializeTypeUint64 byte = 0x5
	BoostSerializeTypeUint32 byte = 0x6
	BoostSerializeTypeUint16 byte = 0x7
	BoostSerializeTypeUint8  byte = 0x8

	BoostSerializeTypeDouble byte = 0x9

	BoostSerializeTypeString byte = 0x0a
	BoostSerializeTypeBool   byte = 0x0b
	BoostSerializeTypeObject byte = 0x0c
	BoostSerializeTypeArray  byte = 0xd

	BoostSerializeFlagArray byte = 0x80
)
View Source
const (
	LevinSignature uint64 = 0x0101010101012101 // Dander's Nightmare

	LevinProtocolVersion uint32 = 1

	LevinPacketRequest        uint32 = 0x00000001 // Q flag
	LevinPacketReponse        uint32 = 0x00000002 // S flag
	LevinPacketMaxDefaultSize uint64 = 100000000  // 100MB _after_ handshake
	LevinPacketMaxInitialSize uint64 = 256 * 1024 // 256KiB _before_ handshake

	LevinHeaderSizeBytes = 33
)
View Source
const (
	// Return Codes.
	LevinOk                               int32 = 0
	LevinErrorConnection                  int32 = -1
	LevinErrorConnectionNotFound          int32 = -2
	LevinErrorConnectionDestroyed         int32 = -3
	LevinErrorConnectionTimedout          int32 = -4
	LevinErrorConnectionNoDuplexProtocol  int32 = -5
	LevinErrorConnectionHandlerNotDefined int32 = -6
	LevinErrorFormat                      int32 = -7
)
View Source
const (
	// p2p admin commands.
	CommandHandshake    uint32 = 1001
	CommandTimedSync    uint32 = 1002
	CommandPing         uint32 = 1003
	CommandStat         uint32 = 1004
	CommandNetworkState uint32 = 1005
	CommandPeerID       uint32 = 1006
	CommandSupportFlags uint32 = 1007
)
View Source
const (
	PortableStorageSignatureA    uint32 = 0x01011101
	PortableStorageSignatureB    uint32 = 0x01020101
	PortableStorageFormatVersion byte   = 0x01

	PortableRawSizeMarkMask  byte   = 0x03
	PortableRawSizeMarkByte  byte   = 0x00
	PortableRawSizeMarkWord  uint16 = 0x01
	PortableRawSizeMarkDword uint32 = 0x02
	PortableRawSizeMarkInt64 uint64 = 0x03
)
View Source
const DialTimeout = 15 * time.Second

Variables

View Source
var (
	MainnetNetworkId = []byte{
		0x12, 0x30, 0xf1, 0x71,
		0x61, 0x04, 0x41, 0x61,
		0x17, 0x31, 0x00, 0x82,
		0x16, 0xa1, 0xa1, 0x10,
	}

	MainnetGenesisTx = "418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3"
)

Functions

func IsValidCommand

func IsValidCommand(c uint32) bool

func IsValidReturnCode

func IsValidReturnCode(c int32) bool

func ParsePeerList

func ParsePeerList(entry Entry) map[string]*Peer

func ReadAny

func ReadAny(bytes []byte, ttype byte) (int, interface{})

func ReadString

func ReadString(bytes []byte) (int, string)

func ReadVarInt

func ReadVarInt(b []byte) (int, int)

reads var int, returning number of bytes read and the integer in that byte sequence.

func VarIn

func VarIn(i int) ([]byte, error)

func WithContextDialer

func WithContextDialer(v ContextDialer) func(*ClientConfig)

Types

type BoostByte

type BoostByte byte

func (BoostByte) Bytes

func (v BoostByte) Bytes() []byte

type BoostString

type BoostString string

func (BoostString) Bytes

func (v BoostString) Bytes() []byte

type BoostUint32

type BoostUint32 uint32

func (BoostUint32) Bytes

func (v BoostUint32) Bytes() []byte

type BoostUint64

type BoostUint64 uint64

func (BoostUint64) Bytes

func (v BoostUint64) Bytes() []byte

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, addr string, opts ...ClientOption) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Handshake

func (c *Client) Handshake(ctx context.Context) (*Node, error)

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

type ClientConfig

type ClientConfig struct {
	ContextDialer ContextDialer
}

type ClientOption

type ClientOption func(*ClientConfig)

type ContextDialer

type ContextDialer interface {
	DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}

type Entries

type Entries []Entry

func ReadArray

func ReadArray(ttype byte, bytes []byte) (int, Entries)

func ReadObject

func ReadObject(bytes []byte) (int, Entries)

func (Entries) Bytes

func (e Entries) Bytes() []byte

type Entry

type Entry struct {
	Name         string
	Serializable Serializable `json:"-,omitempty"`
	Value        interface{}
}

func (Entry) Bytes

func (e Entry) Bytes() []byte

func (Entry) Entries

func (e Entry) Entries() Entries

func (Entry) String

func (e Entry) String() string

func (Entry) Uint16

func (e Entry) Uint16() uint16

func (Entry) Uint32

func (e Entry) Uint32() uint32

func (Entry) Uint64

func (e Entry) Uint64() uint64

func (Entry) Uint8

func (e Entry) Uint8() uint8
type Header struct {
	Signature       uint64
	Length          uint64
	ExpectsResponse bool
	Command         uint32
	ReturnCode      int32
	Flags           uint32 // only 4 most significant bits matter (Q|S|B|E)
	Version         uint32
}

Header

 0               1               2               3
 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      0x01     |      0x21     |      0x01     |      0x01     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      0x01     |      0x01     |      0x01     |      0x01     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             Length                            |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  E. Response  |               _   Command     _
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
		|               _ Return Code   _
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
		|Q|S|B|E|       _       Reserved_
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
		|      0x01     |      0x00     |      0x00     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     0x00      |
+-+-+-+-+-+-+-+-+

i.e.,

	BYTE(0X01) BYTE(0X21) BYTE(0X01) BYTE(0X01)  ---.
							+--> protocol identification
	BYTE(0X01) BYTE(0X01) BYTE(0X01) BYTE(0X01)  ---'

	UINT64(LENGTH)	-----------------------------------> unsigned little-endian 64bit integer
							     length of the payload _not including_
							     the header. messages >100MB are rejected.

	BYTE(E.RESPONSE) 4BYTE(COMMAND) 4BYTE(RET CODE)
        |               |		  |
        |               |		  |
        |               |	          '->  signed 32-bit little endian integer representing the response
        |               |		       from the peer from the last command invoked. `0` for request msgs.
        |               |
        |               '-> unsigned 32-bit little endian integer
        |                   representing the monero specific cmd
        |
        '-> zero-byte if no response is expected from the peer, non-zero if response is expected.
	       peers must respond to requests w/ this flag in the same order as received.

	BIT(Q) BIT(S) BIT(B) BIT(E) 3BYTE+4BIT(RESERVED)
        |    |      |      |
        |    |      |      |
        |    |      |      '-> set if this is the end of a frag msg
        |    |      |
        |    |      '-> set if this is the beginning of a frag msg
        |    |
        |    '-> set if the message is a response
        |
        '-> set if the message is a request

	BYTE(0X01) BYTE(0X00) BYTE(0X00) BYTE(0X00)
        |
        '--> version

func NewHeaderFromBytesBytes

func NewHeaderFromBytesBytes(bytes []byte) (*Header, error)

func NewRequestHeader

func NewRequestHeader(command uint32, length uint64) *Header

func (*Header) Bytes

func (h *Header) Bytes() []byte

type Node

type Node struct {
	Peers map[string]*Peer

	Id      uint64
	RPCPort uint16

	CurrentHeight uint64
	TopVersion    uint8
}

func NewNodeFromEntries

func NewNodeFromEntries(entries Entries) Node

TODO less panic'ing.

func (*Node) GetPeers

func (l *Node) GetPeers() map[string]*Peer

type Peer

type Peer struct {
	Ip   string
	Port uint16
}

func (Peer) Addr

func (p Peer) Addr() string

func (Peer) String

func (p Peer) String() string

type PortableStorage

type PortableStorage struct {
	Entries Entries
}

func NewPortableStorageFromBytes

func NewPortableStorageFromBytes(bytes []byte) (*PortableStorage, error)

func (*PortableStorage) Bytes

func (s *PortableStorage) Bytes() []byte

type Section

type Section struct {
	Entries []Entry
}

func (Section) Bytes

func (s Section) Bytes() []byte

type Serializable

type Serializable interface {
	Bytes() []byte
}

Jump to

Keyboard shortcuts

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