network

package
v0.0.0-...-509fca3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadHash

func ReadHash(reader io.Reader) (*utils.Hash, error)

func ReadString

func ReadString(reader io.Reader, size uint64) (string, error)

func ReadUint16

func ReadUint16(reader io.Reader) (uint16, error)

func ReadUint32

func ReadUint32(reader io.Reader) (uint32, error)

func ReadUint64

func ReadUint64(reader io.Reader) (uint64, error)

func ReadUint8

func ReadUint8(reader io.Reader) (uint8, error)

func ReadVarString

func ReadVarString(reader io.Reader) (string, error)

func ReadVarUint

func ReadVarUint(reader io.Reader) (uint64, error)

func WriteAddress

func WriteAddress(writer io.Writer, address *Address) error

func WriteHash

func WriteHash(writer io.Writer, hash *utils.Hash) error

func WriteMessage

func WriteMessage(writer io.Writer, msg Message) error

WriteMessage encodes a message and writes it in a io.Writer. It generates the header of the message.

func WriteString

func WriteString(writer io.Writer, value string) error

func WriteUint16

func WriteUint16(writer io.Writer, value uint16) error

func WriteUint32

func WriteUint32(writer io.Writer, value uint32) error

func WriteUint64

func WriteUint64(writer io.Writer, value uint64) error

func WriteUint8

func WriteUint8(writer io.Writer, value uint8) error

func WriteVarString

func WriteVarString(writer io.Writer, value string) error

func WriteVarUint

func WriteVarUint(writer io.Writer, value uint64) error

Types

type AddrMessage

type AddrMessage struct {
	Addresses []*Address
}

func NewAddrMessage

func NewAddrMessage() *AddrMessage

func (*AddrMessage) Decode

func (msg *AddrMessage) Decode(reader io.Reader) error

func (*AddrMessage) Encode

func (msg *AddrMessage) Encode(writer io.Writer) error

func (*AddrMessage) MsgType

func (msg *AddrMessage) MsgType() string

func (AddrMessage) String

func (msg AddrMessage) String() string

type Address

type Address struct {
	Timestamp time.Time
	IP        net.IP
	Port      uint16
}

Address represents the message addr.

func ReadAddress

func ReadAddress(reader io.Reader) (*Address, error)

type BlockHeader

type BlockHeader struct {
	Version        uint32
	Flags          []string
	HashPrevBlock  *utils.Hash
	HashMerkleRoot *utils.Hash
	Timestamp      time.Time
	Height         uint32
	Target         *big.Int
	Nonce          uint64
}

func (*BlockHeader) Hash

func (header *BlockHeader) Hash() *utils.Hash

func (*BlockHeader) HashString

func (header *BlockHeader) HashString() string

type BlockMessage

type BlockMessage struct {
	Header *BlockHeader
	Txs    []*TxMessage
}

func NewBlockMessage

func NewBlockMessage() *BlockMessage

func (*BlockMessage) Decode

func (msg *BlockMessage) Decode(reader io.Reader) error

func (*BlockMessage) Encode

func (msg *BlockMessage) Encode(writer io.Writer) error

func (*BlockMessage) MsgType

func (msg *BlockMessage) MsgType() string

func (BlockMessage) String

func (msg BlockMessage) String() string

type GetAddrMessage

type GetAddrMessage struct {
}

func NewGetAddrMessage

func NewGetAddrMessage() *GetAddrMessage

func (*GetAddrMessage) Decode

func (msg *GetAddrMessage) Decode(reader io.Reader) error

func (*GetAddrMessage) Encode

func (msg *GetAddrMessage) Encode(writer io.Writer) error

func (*GetAddrMessage) MsgType

func (msg *GetAddrMessage) MsgType() string

func (GetAddrMessage) String

func (msg GetAddrMessage) String() string

type GetBlocksMessage

type GetBlocksMessage struct {
	BlockLocator []*utils.Hash
	HashStop     *utils.Hash
}

func NewGetBlocksMessage

func NewGetBlocksMessage() *GetBlocksMessage

func (*GetBlocksMessage) Decode

func (msg *GetBlocksMessage) Decode(reader io.Reader) error

func (*GetBlocksMessage) Encode

func (msg *GetBlocksMessage) Encode(writer io.Writer) error

func (*GetBlocksMessage) MsgType

func (msg *GetBlocksMessage) MsgType() string

func (GetBlocksMessage) String

func (msg GetBlocksMessage) String() string

type GetDataMessage

type GetDataMessage struct {
	Inventory []*InvVect
}

func NewGetDataMessage

func NewGetDataMessage() *GetDataMessage

func (*GetDataMessage) Decode

func (msg *GetDataMessage) Decode(reader io.Reader) error

func (*GetDataMessage) Encode

func (msg *GetDataMessage) Encode(writer io.Writer) error

func (*GetDataMessage) MsgType

func (msg *GetDataMessage) MsgType() string

func (GetDataMessage) String

func (msg GetDataMessage) String() string

type GetMempoolMessage

type GetMempoolMessage struct {
}

func NewGetMempoolMessage

func NewGetMempoolMessage() *GetMempoolMessage

func (*GetMempoolMessage) Decode

func (msg *GetMempoolMessage) Decode(reader io.Reader) error

func (*GetMempoolMessage) Encode

func (msg *GetMempoolMessage) Encode(writer io.Writer) error

func (*GetMempoolMessage) MsgType

func (msg *GetMempoolMessage) MsgType() string

func (GetMempoolMessage) String

func (msg GetMempoolMessage) String() string

type InvMessage

type InvMessage struct {
	Inventory []*InvVect
}

func NewInvMessage

func NewInvMessage() *InvMessage

func (*InvMessage) Decode

func (msg *InvMessage) Decode(reader io.Reader) error

func (*InvMessage) Encode

func (msg *InvMessage) Encode(writer io.Writer) error

func (*InvMessage) MsgType

func (msg *InvMessage) MsgType() string

func (InvMessage) String

func (msg InvMessage) String() string

type InvVect

type InvVect struct {
	InvType InvVectType
	Hash    *utils.Hash
}

type InvVectType

type InvVectType uint32
const (
	INV_VECT_TX    InvVectType = 0
	INV_VECT_BLOCK InvVectType = 1
)

type Message

type Message interface {
	Decode(io.Reader) error
	Encode(io.Writer) error
	MsgType() string
}

Message represents a message following the Ensicoin protocol.

func ReadMessage

func ReadMessage(reader io.Reader) (Message, error)

ReadMessage decodes a raw message from a io.Reader.

type MinusOneThatsThreeMessage

type MinusOneThatsThreeMessage struct {
}

func NewMinusOneThatsThreeMessage

func NewMinusOneThatsThreeMessage() *MinusOneThatsThreeMessage

func (*MinusOneThatsThreeMessage) Decode

func (msg *MinusOneThatsThreeMessage) Decode(reader io.Reader) error

func (*MinusOneThatsThreeMessage) Encode

func (msg *MinusOneThatsThreeMessage) Encode(writer io.Writer) error

func (*MinusOneThatsThreeMessage) MsgType

func (msg *MinusOneThatsThreeMessage) MsgType() string

func (MinusOneThatsThreeMessage) String

func (msg MinusOneThatsThreeMessage) String() string

type NotFoundMessage

type NotFoundMessage struct {
	Inventory []*InvVect
}

func NewNotFoundMessage

func NewNotFoundMessage() *NotFoundMessage

func (*NotFoundMessage) Decode

func (msg *NotFoundMessage) Decode(reader io.Reader) error

func (*NotFoundMessage) Encode

func (msg *NotFoundMessage) Encode(writer io.Writer) error

func (*NotFoundMessage) MsgType

func (msg *NotFoundMessage) MsgType() string

func (NotFoundMessage) String

func (msg NotFoundMessage) String() string

type Outpoint

type Outpoint struct {
	Hash  utils.Hash
	Index uint32
}

func (*Outpoint) MarshalBinary

func (outpoint *Outpoint) MarshalBinary() ([]byte, error)

func (*Outpoint) UnmarshalBinary

func (outpoint *Outpoint) UnmarshalBinary(data []byte) error

type TwoPlusTwoIsFourMessage

type TwoPlusTwoIsFourMessage struct {
}

TwoPlusTwoIsFourMessage represents the message 2plus2is4.

func NewTwoPlusTwoIsFourMessage

func NewTwoPlusTwoIsFourMessage() *TwoPlusTwoIsFourMessage

NewTwoPlusTwoIsFourMessage returns a TwoPlusTwoIsFourMessage instance.

func (*TwoPlusTwoIsFourMessage) Decode

func (msg *TwoPlusTwoIsFourMessage) Decode(reader io.Reader) error

Decode implements the Message interface.

func (*TwoPlusTwoIsFourMessage) Encode

func (msg *TwoPlusTwoIsFourMessage) Encode(writer io.Writer) error

Encode implements the Message interface.

func (*TwoPlusTwoIsFourMessage) MsgType

func (msg *TwoPlusTwoIsFourMessage) MsgType() string

MsgType implements the Message interface.

func (TwoPlusTwoIsFourMessage) String

func (msg TwoPlusTwoIsFourMessage) String() string

type TxIn

type TxIn struct {
	PreviousOutput *Outpoint
	Script         []byte
}

type TxMessage

type TxMessage struct {
	Version uint32
	Flags   []string
	Inputs  []*TxIn
	Outputs []*TxOut
}

func NewTxMessage

func NewTxMessage() *TxMessage

func (*TxMessage) Decode

func (msg *TxMessage) Decode(reader io.Reader) error

func (*TxMessage) Encode

func (msg *TxMessage) Encode(writer io.Writer) error

func (*TxMessage) Hash

func (msg *TxMessage) Hash() *utils.Hash

func (*TxMessage) MsgType

func (msg *TxMessage) MsgType() string

func (*TxMessage) SHash

func (msg *TxMessage) SHash(input *TxIn, value uint64) *utils.Hash

func (TxMessage) String

func (msg TxMessage) String() string

type TxOut

type TxOut struct {
	Value  uint64
	Script []byte
}

func (*TxOut) String

func (txOut *TxOut) String() string

type WhoamiAckMessage

type WhoamiAckMessage struct {
}

func NewWhoamiAckMessage

func NewWhoamiAckMessage() *WhoamiAckMessage

func (*WhoamiAckMessage) Decode

func (msg *WhoamiAckMessage) Decode(reader io.Reader) error

func (*WhoamiAckMessage) Encode

func (msg *WhoamiAckMessage) Encode(writer io.Writer) error

func (*WhoamiAckMessage) MsgType

func (msg *WhoamiAckMessage) MsgType() string

func (WhoamiAckMessage) String

func (msg WhoamiAckMessage) String() string

type WhoamiMessage

type WhoamiMessage struct {
	Version  uint32
	From     *Address
	Services []string
}

func NewWhoamiMessage

func NewWhoamiMessage() *WhoamiMessage

func (*WhoamiMessage) Decode

func (msg *WhoamiMessage) Decode(reader io.Reader) error

func (*WhoamiMessage) Encode

func (msg *WhoamiMessage) Encode(writer io.Writer) error

func (*WhoamiMessage) MsgType

func (msg *WhoamiMessage) MsgType() string

func (WhoamiMessage) String

func (msg WhoamiMessage) String() string

Jump to

Keyboard shortcuts

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