Documentation ¶
Index ¶
- Constants
- func GenReqID() uint64
- type BaseStream
- func (st *BaseStream) Close() error
- func (st *BaseStream) CloseOnExit() error
- func (st *BaseStream) ID() StreamID
- func (st *BaseStream) ProtoID() ProtoID
- func (st *BaseStream) ProtoSpec() (ProtoSpec, error)
- func (st *BaseStream) ReadBytes() (cb []byte, err error)
- func (st *BaseStream) WriteBytes(b []byte) (err error)
- type ProtoID
- type ProtoSpec
- type Protocol
- type Request
- type Response
- type Stream
- type StreamID
Constants ¶
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 ¶
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) 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)
ReadMsg 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 ¶
ProtoIDToProtoSpec converts a ProtoID to ProtoSpec
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 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