sttypes

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtoIDCommonPrefix is the common prefix for stream protocol
	ProtoIDCommonPrefix = "harmony"

	// ProtoIDFormat is the format of stream protocol ID
	ProtoIDFormat = "%s/%s/%s/%d/%s"
)

Variables

This section is empty.

Functions

func GenReqID

func GenReqID() uint64

GenReqID generates a random ReqID

Types

type BaseStream

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

BaseStream is the wrapper around

func NewBaseStream

func NewBaseStream(st libp2p_network.Stream) *BaseStream

NewBaseStream creates BaseStream as the wrapper of libp2p Stream

func (*BaseStream) Close

func (st *BaseStream) Close() error

Close reset the stream, and close the connection for both sides.

func (*BaseStream) CloseOnExit

func (st *BaseStream) CloseOnExit() error

CloseOnExit reset the stream during the shutdown of the node

func (*BaseStream) ID

func (st *BaseStream) ID() StreamID

ID return the StreamID of the stream

func (*BaseStream) ProtoID

func (st *BaseStream) ProtoID() ProtoID

ProtoID return the remote protocol ID of the stream

func (*BaseStream) ProtoSpec

func (st *BaseStream) ProtoSpec() (ProtoSpec, error)

ProtoSpec get the parsed protocol Specifier of the stream

func (*BaseStream) ReadBytes

func (st *BaseStream) ReadBytes() (cb []byte, err error)

ReadBytes read the bytes from the stream.

func (*BaseStream) WriteBytes

func (st *BaseStream) WriteBytes(b []byte) (err error)

WriteBytes write the bytes to the stream. First 4 bytes is used as the size bytes, and the rest is the content

type ProtoID

type ProtoID libp2p_proto.ID

ProtoID is the protocol id for streaming, an alias of libp2p stream protocol ID。 The stream protocol ID is composed of following components: 1. Service - Currently, only sync service is supported. 2. NetworkType - mainnet, testnet, stn, e.t.c. 3. ShardID - shard ID of the current protocol. 4. Version - Stream protocol version for backward compatibility.

type ProtoSpec

type ProtoSpec struct {
	Service     string
	NetworkType nodeconfig.NetworkType
	ShardID     nodeconfig.ShardID
	Version     *version.Version
}

ProtoSpec is the un-serialized stream proto id specification TODO: move this to service wise module since different protocol might have different

protoID information

func ProtoIDToProtoSpec

func ProtoIDToProtoSpec(id ProtoID) (ProtoSpec, error)

ProtoIDToProtoSpec converts a ProtoID to ProtoSpec

func (ProtoSpec) ToProtoID

func (spec ProtoSpec) ToProtoID() ProtoID

ToProtoID convert a ProtoSpec to ProtoID.

type Protocol

type Protocol interface {
	p2ptypes.LifeCycle

	Specifier() string
	Version() *version.Version
	ProtoID() ProtoID
	Match(string) bool
	HandleStream(st libp2p_network.Stream)
}

Protocol is the interface of protocol to be registered to libp2p.

type Request

type Request interface {
	ReqID() uint64
	SetReqID(rid uint64)
	String() string
	IsSupportedByProto(ProtoSpec) bool
	Encode() ([]byte, error)
}

Request is the interface of a stream request used for common stream utils.

type Response

type Response interface {
	ReqID() uint64
	String() string
}

Response is the interface of a stream response used for common stream utils

type Stream

type Stream interface {
	ID() StreamID
	ProtoID() ProtoID
	ProtoSpec() (ProtoSpec, error)
	WriteBytes([]byte) error
	ReadBytes() ([]byte, error)
	Close() error
	CloseOnExit() error
}

Stream is the interface for streams implemented in each service. The stream interface is used for stream management as well as rate limiters

type StreamID

type StreamID string

StreamID is the unique identifier for the stream. It has the value of libp2p_network_peer.ID

Jump to

Keyboard shortcuts

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