rpc

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlowTracingIdLength   = 32
	TrackSequenceLength   = 4
	InitiatedTimeLength   = 8
	RemainingTimeLength   = 2
	DirectiveNotesLength  = 2
	DataRepFormatLength   = 1
	DataLengthLength      = 3
	ExtensionNotesLength  = 2
	RoutingStrategyLength = 1
	ReservedLength        = 1
	StateCodeLength       = 4
	PackSignatureLength   = 32

	PackHeaderLength = FlowTracingIdLength +
		TrackSequenceLength + InitiatedTimeLength +
		RemainingTimeLength + DirectiveNotesLength +
		DataRepFormatLength + DataLengthLength +
		ExtensionNotesLength + RoutingStrategyLength +
		ReservedLength + StateCodeLength + PackSignatureLength
)
View Source
const (
	StrategyMin  = 0
	StrategyHash = 11
)

Variables

View Source
var (
	StartID [4]uint8
)

Functions

func ConfigTrack

func ConfigTrack()

func GenDirective

func GenDirective(method string, location []byte) string

func GenTrackID

func GenTrackID(trackID uint32, spanID uint8) uint32

func Init

func Init(fatal LogFunc, vital LogFunc, alert LogFunc, error LogFunc, debug LogFunc)

func InitJaeger

func InitJaeger(service string) (int, io.Closer)

func NewPack

func NewPack(fCtx *FlowContext, directive string, stateCode uint32, data []byte, extension []byte) (*_pack, fsc.FlowStateCode)

func ParseHeader

func ParseHeader(buf [PackHeaderLength]byte) (*_pack, fsc.FlowStateCode)

Types

type Annotation

type Annotation struct {
	Serialized []byte
}

type FlowContext

type FlowContext struct {
	Ctx           context.Context
	InitiateTime  time.Time
	FlowTracingId [FlowTracingIdLength]byte
	RemainingTime uint16
}

func (FlowContext) Deadline

func (fc FlowContext) Deadline() (time.Time, bool)

func (FlowContext) Done

func (fc FlowContext) Done() <-chan struct{}

func (FlowContext) Err

func (fc FlowContext) Err() error

func (*FlowContext) Reply

func (ctx *FlowContext) Reply(pk FlowPack, data []byte) (FlowPack, fsc.FlowStateCode)

func (FlowContext) Value

func (fc FlowContext) Value(key interface{}) interface{}

type FlowPack

type FlowPack interface {
	GetExtension() http.Header
	GetFlowTracingId() string
	GetTrackSequence() uint32
	CalRemainingTime(nowMs uint64) (uint16, bool)
	GetRemainingTime() uint16
	GetInitiatedTime() uint64
	GetData() []byte
	GetDirective() string
	GetDstAddr() string
	GetSrcAddr() string
	GetSha1Padding() []byte
	Serialize() ([]byte, fsc.FlowStateCode)
	GenReply(directive []byte, initiatedTime uint64, remainingTime uint16, stateCode uint32, data []byte, extension []byte) ([]byte, fsc.FlowStateCode)
}
type Header struct {
	FlowTracingId   [FlowTracingIdLength]uint8 //7 bytes run-id + 13-bytes timestamp + 4 bytes rand
	TrackSequence   uint32                     //2bits(reserved) + 5bits + 5bits + 5bits + 5bits + 5bits + 5bits
	InitiatedTime   uint64                     //unix timestamp, ms
	RemainingTime   uint16                     //measured in ms
	DirectiveNotes  uint16                     //the MOST significant 5 bits for Method=POST/DELETE/PATCH/PUT/GET, and the remaining for Location Length
	DataRepFormat   uint8                      //Data Representation Format:=Url/Proto/Json/Raw
	DataLength      [3]uint8                   //big-endian
	ExtensionNotes  uint16                     //the MOST significant 5 bits for Extension
	RoutingStrategy byte                       //'H':=hash, 'Q':=最快响应, 'R':=round-robin
	Reserved        uint8
	StateCode       uint32
	PackSignature   [PackSignatureLength]uint8
}

func GenTrackHeader

func GenTrackHeader(traceID [FlowTracingIdLength]byte, strategy Strategy) *Header

type IslandSession

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

func Connect

func Connect(remainedTime time.Duration, address string) (*IslandSession, fsc.FlowStateCode)

func GetSession

func GetSession(remainedTime time.Duration, address string) (*IslandSession, fsc.FlowStateCode)

func NewNetConn

func NewNetConn(conn net.Conn) *IslandSession

func (*IslandSession) Close

func (session *IslandSession) Close()

func (*IslandSession) Dispatch

func (session *IslandSession) Dispatch(fCtx *FlowContext, method string, location []byte, msg []byte, ext []byte) ([]byte, fsc.FlowStateCode)

func (*IslandSession) Dispose

func (session *IslandSession) Dispose()

func (*IslandSession) RecvPack

func (session *IslandSession) RecvPack(deadline time.Time) (FlowPack, fsc.FlowStateCode)

func (*IslandSession) ReplyFlow

func (session *IslandSession) ReplyFlow(reply []byte) fsc.FlowStateCode

func (*IslandSession) SendPack

func (session *IslandSession) SendPack(pack []byte) fsc.FlowStateCode

type LogFunc

type LogFunc func(format string, argv ...interface{})

type SessionPool

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

func NewSessionPool

func NewSessionPool(capacity uint16) *SessionPool

func (*SessionPool) GetSession

func (pl *SessionPool) GetSession(remainedTime time.Duration, addr string) (*IslandSession, fsc.FlowStateCode)

type Strategy

type Strategy uint16

Jump to

Keyboard shortcuts

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