proto

package
v0.0.0-...-745f595 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package proto provides an implementation of the Nano network protocol.

Index

Constants

View Source
const (
	NetworkTest = 'Y'
	NetworkBeta = 'Z'
	NetworkLive = 'X'
)
View Source
const (
	HeaderSize = 8
)

Variables

View Source
var (
	ErrBadMagic  = errors.New("bad magic")
	ErrBadType   = errors.New("bad packet type")
	ErrBadLength = errors.New("bad packet length")
)

Functions

func Name

func Name(id byte) string

Types

type BlockPacket

type BlockPacket struct {
	Type  byte
	Block block.Block
}

func (BlockPacket) MarshalBinary

func (s BlockPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*BlockPacket) UnmarshalBinary

func (s *BlockPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type BulkPullBlocksPacket

type BulkPullBlocksPacket struct {
	Min   block.Hash
	Max   block.Hash
	Mode  BulkPullMode
	Count uint32
}

func (*BulkPullBlocksPacket) ID

func (s *BulkPullBlocksPacket) ID() byte

func (*BulkPullBlocksPacket) MarshalBinary

func (s *BulkPullBlocksPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*BulkPullBlocksPacket) UnmarshalBinary

func (s *BulkPullBlocksPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type BulkPullMode

type BulkPullMode byte
const (
	BulkPullModeList BulkPullMode = iota
	BulkPullModeChecksum
)

type BulkPullPacket

type BulkPullPacket struct {
	Address nano.Address
	Hash    block.Hash
}

func (*BulkPullPacket) ID

func (s *BulkPullPacket) ID() byte

func (*BulkPullPacket) MarshalBinary

func (s *BulkPullPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*BulkPullPacket) UnmarshalBinary

func (s *BulkPullPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type ConfirmAckPacket

type ConfirmAckPacket VotePacket

func (*ConfirmAckPacket) ID

func (s *ConfirmAckPacket) ID() byte

func (ConfirmAckPacket) MarshalBinary

func (s ConfirmAckPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*ConfirmAckPacket) UnmarshalBinary

func (s *ConfirmAckPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type ConfirmReqPacket

type ConfirmReqPacket BlockPacket

func (*ConfirmReqPacket) ID

func (s *ConfirmReqPacket) ID() byte

func (ConfirmReqPacket) MarshalBinary

func (s ConfirmReqPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*ConfirmReqPacket) UnmarshalBinary

func (s *ConfirmReqPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type FrontierReqPacket

type FrontierReqPacket struct {
	StartAddress nano.Address
	Age          uint32
	Count        uint32
}

func (*FrontierReqPacket) ID

func (s *FrontierReqPacket) ID() byte

func (*FrontierReqPacket) MarshalBinary

func (s *FrontierReqPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*FrontierReqPacket) UnmarshalBinary

func (s *FrontierReqPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type HandshakePacket

type HandshakePacket struct {
}

func (*HandshakePacket) ID

func (s *HandshakePacket) ID() byte

func (*HandshakePacket) MarshalBinary

func (s *HandshakePacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*HandshakePacket) UnmarshalBinary

func (s *HandshakePacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Header struct {
	Magic        [2]byte
	VersionMax   byte
	VersionUsing byte
	VersionMin   byte
	MessageType  byte
	Extensions   uint16
}

func (*Header) BlockType

func (s *Header) BlockType() byte

func (*Header) MarshalBinary

func (s *Header) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Header) SetBlockType

func (s *Header) SetBlockType(b byte)

func (*Header) UnmarshalBinary

func (s *Header) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type KeepAlivePacket

type KeepAlivePacket struct {
	Peers []*net.UDPAddr
}

func (*KeepAlivePacket) ID

func (s *KeepAlivePacket) ID() byte

func (*KeepAlivePacket) MarshalBinary

func (s *KeepAlivePacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*KeepAlivePacket) UnmarshalBinary

func (s *KeepAlivePacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Network

type Network rune

func (Network) MarshalText

func (n Network) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Network) String

func (n Network) String() string

String implements the fmt.Stringer interface.

func (*Network) UnmarshalText

func (n *Network) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Packet

type Packet interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	ID() byte
}

type Proto

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

func New

func New(net Network) *Proto

func (*Proto) MarshalPacket

func (p *Proto) MarshalPacket(packet Packet) ([]byte, error)

func (*Proto) NewHeader

func (p *Proto) NewHeader(packetType byte) *Header

func (*Proto) NewKeepAlivePacket

func (p *Proto) NewKeepAlivePacket(peers []*net.UDPAddr) *KeepAlivePacket

func (*Proto) UnmarshalPacket

func (p *Proto) UnmarshalPacket(data []byte) (Packet, error)

type PublishPacket

type PublishPacket BlockPacket

func (*PublishPacket) ID

func (s *PublishPacket) ID() byte

func (PublishPacket) MarshalBinary

func (s PublishPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*PublishPacket) UnmarshalBinary

func (s *PublishPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Versions

type Versions struct {
	Max   byte
	Using byte
	Min   byte
}

type VotePacket

type VotePacket struct {
	Type byte
	Vote block.Vote
}

func (VotePacket) MarshalBinary

func (s VotePacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*VotePacket) UnmarshalBinary

func (s *VotePacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

Jump to

Keyboard shortcuts

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