wired

package
v0.0.0-...-571fd38 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMsgMalformed      = errors.New("malformed message")
	ErrMsgIDInvalid      = errors.New("message id is invalid")
	ErrMsgTypeInvalid    = errors.New("message type is invalid")
	ErrMsgSignInvalid    = errors.New("message sign is invalid")
	ErrMsgPayloadInvalid = errors.New("message payload is invalid")
)

Functions

func Reply

func Reply(stream network.Stream, data interface{}) error

func Send

func Send(host core.Host, protocolID protocol.ID, peerID peer.ID, data interface{}) (network.Stream, error)

Send is a helper method - writes a protobuf go data object to a network stream. then the stream will be returned and caller is able to read the response from it.

func Signature

func Signature(host core.Host, message *Message) ([]byte, error)

Signature an outgoing p2p message payload.

func Verify

func Verify(peerID peer.ID, message *Message) bool

Verify verifies the data and sign in message.

Types

type ChainPayload

type ChainPayload struct {
	Type    ChainType
	Headers []*ngtypes.BlockHeader `rlp:"optional"`
	Blocks  []*ngtypes.Block       `rlp:"optional"`
}

func DecodeChainPayload

func DecodeChainPayload(rawPayload []byte) (*ChainPayload, error)

DecodeChainPayload unmarshal the raw and return the *pb.ChainPayload.

type ChainType

type ChainType uint8
const (
	InvalidChain ChainType = iota
	BlockChain
	HeaderChain
)

type GetChainPayload

type GetChainPayload struct {
	Type ChainType
	From [][]byte
	To   []byte
}

type GetSheetPayload

type GetSheetPayload struct {
	Height uint64
	Hash   []byte
}

GetSheetPayload is the payload for getting a sheet from remote Design: fast-sync for state support checkpoint height only when fast-sync:

  1. sync to latest checkpoint
  2. sync to latest checkpoint state
  3. sync the remaining blocks
  4. update local state

type Message

type Message struct {
	Header  *MsgHeader
	Payload []byte
}

func ReceiveReply

func ReceiveReply(uuid []byte, stream network.Stream) (*Message, error)

ReceiveReply will receive the correct reply message from the stream.

type MsgHeader

type MsgHeader struct {
	Network ngtypes.Network

	ID        []byte
	Type      MsgType
	Timestamp uint64
	PeerKey   []byte
	Sign      []byte
}

func NewHeader

func NewHeader(host core.Host, network ngtypes.Network, msgID []byte, msgType MsgType) *MsgHeader

NewHeader is a helper method: generate message data shared between all node's p2p protocols.

type MsgType

type MsgType uint8
const (
	InvalidMsg MsgType = iota
	PingMsg
	PongMsg
	RejectMsg
)
const (
	GetChainMsg MsgType = iota + 0x10
	ChainMsg
	GetSheetMsg
	SheetMsg
)

func (MsgType) String

func (mt MsgType) String() string

type SheetPayload

type SheetPayload struct {
	Sheet *ngtypes.Sheet
}

func DecodeSheetPayload

func DecodeSheetPayload(rawPayload []byte) (*SheetPayload, error)

DecodeSheetPayload unmarshal the raw and return the *message.PongPayload.

type StatusPayload

type StatusPayload struct {
	Origin         uint64
	Latest         uint64
	CheckpointHash []byte
	CheckpointDiff []byte // actual diff
}

StatusPayload is the payload used when ping pong.

func DecodePongPayload

func DecodePongPayload(rawPayload []byte) (*StatusPayload, error)

DecodePongPayload unmarshal the raw and return the *message.PongPayload.

type Wired

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

Wired type.

func NewWiredProtocol

func NewWiredProtocol(host core.Host, network ngtypes.Network, chain *blockchain.Chain) *Wired

func (*Wired) GetWiredProtocol

func (w *Wired) GetWiredProtocol() protocol.ID

func (*Wired) GoServe

func (w *Wired) GoServe()

func (*Wired) SendGetChain

func (w *Wired) SendGetChain(peerID peer.ID, from [][]byte, to []byte) (id []byte, stream network.Stream, err error)

func (*Wired) SendGetSheet

func (w *Wired) SendGetSheet(peerID peer.ID, checkpointHeight uint64, checkpointHash []byte) (id []byte, stream network.Stream, err error)

func (*Wired) SendPing

func (w *Wired) SendPing(peerID peer.ID, origin, latest uint64, checkpointHash, checkpointActualDiff []byte) (id []byte,
	stream network.Stream)

Jump to

Keyboard shortcuts

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