remote

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0 Imports: 14 Imported by: 44

Documentation

Overview

Package remote defines all interfaces that are used to do transport with peer side and contains default extension implementations.

Index

Constants

View Source
const (
	BitReadable = 1 << iota
	BitWritable
)

Mask bits.

View Source
const (
	// TransInfoRecv2Send load by message tag,
	// it is recorded during receive phase but will be the part of trans info to send out
	TransInfoRecv2Send string = "transInfoRecv2Send"

	ReadFailed string = "RFailed"

	// MeshHeader use in message.Tag to check MeshHeader
	MeshHeader string = "mHeader"
)
View Source
const (
	UnknownApplicationException = 0
	UnknownMethod               = 1
	InvalidMessageTypeException = 2
	WrongMethodName             = 3
	BadSequenceID               = 4
	MissingResult               = 5
	InternalError               = 6
	ProtocolError               = 7
	InvalidTransform            = 8
	InvalidProtocol             = 9
	UnsupportedClientType       = 10
)

corresponding with thrift TApplicationException, cannot change it

Variables

This section is empty.

Functions

func FillSendMsgFromRecvMsg

func FillSendMsgFromRecvMsg(recvMsg Message, sendMsg Message)

FillSendMsgFromRecvMsg is used to fill the transport information to the message to be sent.

func NewByteBufferIO

func NewByteBufferIO(buffer ByteBuffer) io.ReadWriter

NewByteBufferIO wraps ByBuffer to io.ReadWriter

func PutPayloadCode

func PutPayloadCode(name serviceinfo.PayloadCodec, v PayloadCodec)

PutPayloadCode puts the desired payload codec to message.

func RecycleMessage

func RecycleMessage(msg Message)

RecycleMessage is used to recycle message.

Types

type BoundHandler

type BoundHandler interface {
}

BoundHandler is used to abstract the bound handler.

type ByteBuffer

type ByteBuffer interface {
	io.ReadWriter

	// Next reads the next n bytes sequentially and returns the original buffer.
	Next(n int) (p []byte, err error)

	// Peek returns the next n bytes without advancing the reader.
	Peek(n int) (buf []byte, err error)

	// Skip is used to skip the next few bytes quickly. It's faster than Next and doesn't cause release.
	Skip(n int) (err error)

	// Release will free the buffer. After release, buffer read by Next/Skip/Peek is invalid.
	// Param e is used when the buffer release depend on error.
	// For example, usually the write buffer will be released inside flush,
	// but if flush error happen, write buffer may need to be released explicitly.
	Release(e error) (err error)

	// ReadableLen returns the total length of readable buffer.
	// Return: -1 means unreadable.
	ReadableLen() (n int)

	// ReadLen returns the size already read.
	ReadLen() (n int)

	// ReadString is a more efficient way to read string than Next.
	ReadString(n int) (s string, err error)

	// ReadBinary like ReadString.
	// Returns a copy of original buffer.
	ReadBinary(n int) (p []byte, err error)

	// Malloc n bytes sequentially in the writer buffer.
	Malloc(n int) (buf []byte, err error)

	// MallocLen returns the total length of the buffer malloced.
	MallocLen() (length int)

	// WriteString is a more efficient way to write string, using the unsafe method to convert the string to []byte.
	WriteString(s string) (n int, err error)

	// WriteBinary writes the []byte directly. Callers must guarantee that the []byte doesn't change.
	WriteBinary(b []byte) (n int, err error)

	// Flush writes any malloc data to the underlying io.Writer.
	// The malloced buffer must be set correctly.
	Flush() (err error)

	// NewBuffer returns a new writable remote.ByteBuffer.
	NewBuffer() ByteBuffer
	// AppendBuffer appends buf to the original buffer.
	AppendBuffer(buf ByteBuffer) (n int, err error)

	// Bytes return the backing bytes slice of this buffer
	Bytes() (buf []byte, err error)
}

ByteBuffer is the core abstraction of buffer in Kitex.

func NewReaderBuffer

func NewReaderBuffer(buf []byte) ByteBuffer

NewReaderBuffer is used to create a defaultByteBuffer using the given buf.

func NewReaderWriterBuffer

func NewReaderWriterBuffer(size int) ByteBuffer

NewReaderWriterBuffer is used to create a defaultByteBuffer using the given size.

func NewWriterBuffer

func NewWriterBuffer(size int) ByteBuffer

NewWriterBuffer is used to create a defaultByteBuffer using the given size. NOTICE: defaultByteBuffer is only used for testing.

type ByteBufferFactory

type ByteBufferFactory interface {
	NewByteBuffer(conn net.Conn) (ByteBuffer, error)
}

ByteBufferFactory is used to create ByteBuffer.

type ByteBufferIO

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

ByteBufferIO wrap ByteBuffer to implement io.ReadWriter

func (*ByteBufferIO) Read

func (p *ByteBufferIO) Read(b []byte) (n int, err error)

Read implements the io.ReadWriter interface.

func (*ByteBufferIO) Write

func (p *ByteBufferIO) Write(b []byte) (int, error)

Write implements the io.ReadWriter interface.

type ClientOption

type ClientOption struct {
	SvcInfo *serviceinfo.ServiceInfo

	CliHandlerFactory ClientTransHandlerFactory

	Codec Codec

	PayloadCodec PayloadCodec

	ConnPool ConnPool

	Dialer Dialer

	Logger klog.FormatLogger

	Option

	EnableConnPoolReporter bool
}

ClientOption is used to init the remote client.

type ClientTransHandler

type ClientTransHandler interface {
	TransHandler
}

ClientTransHandler is just TransHandler.

type ClientTransHandlerFactory

type ClientTransHandlerFactory interface {
	NewTransHandler(opt *ClientOption) (ClientTransHandler, error)
}

ClientTransHandlerFactory to new TransHandler for client

type Codec

type Codec interface {
	Encode(ctx context.Context, msg Message, out ByteBuffer) error

	Decode(ctx context.Context, msg Message, in ByteBuffer) error

	Name() string
}

Codec is the abstraction of the codec layer of Kitex.

type CompressType

type CompressType int32

CompressType tells compression type for a message.

const (
	NoCompress CompressType = iota
	GZip
)

Compression types. Not support now, compression will be supported at later version

type ConnOption

type ConnOption struct {
	Dialer         Dialer
	ConnectTimeout time.Duration
}

ConnOption contains configurations for connection pool.

type ConnPool

type ConnPool interface {
	// Get returns a connection to the given address.
	Get(ctx context.Context, network, address string, opt *ConnOption) (net.Conn, error)

	// Put puts the connection back to pool.
	// Note that the Close method of conn may already be invoked.
	Put(conn net.Conn) error

	// Discard discards the connection rather than putting it to the pool.
	Discard(conn net.Conn) error

	// Close is to release resource of ConnPool, it is executed when client is closed.
	Close() error
}

ConnPool is used to get connections.

type ConnPoolReporter

type ConnPoolReporter interface {
	EnableReporter()
}

ConnPoolReporter is used to enable reporter.

type Dialer

type Dialer interface {
	DialTimeout(network, address string, timeout time.Duration) (net.Conn, error)
}

Dialer is used to dial and get a connection.

func NewDefaultDialer

func NewDefaultDialer() Dialer

NewDefaultDialer is used to create a default dialer.

type DuplexBoundHandler

type DuplexBoundHandler interface {
	OutboundHandler
	InboundHandler
}

DuplexBoundHandler can process both inbound and outbound connections.

type InboundHandler

type InboundHandler interface {
	BoundHandler

	OnActive(ctx context.Context, conn net.Conn) (context.Context, error)

	OnInactive(ctx context.Context, conn net.Conn) context.Context

	OnRead(ctx context.Context, conn net.Conn) (context.Context, error)

	OnMessage(ctx context.Context, args, result Message) (context.Context, error)
}

InboundHandler is used to process read event.

type InvokeHandleFuncSetter

type InvokeHandleFuncSetter interface {
	SetInvokeHandleFunc(inkHdlFunc endpoint.Endpoint)
}

InvokeHandleFuncSetter is used to set invoke handle func.

type IsActive

type IsActive interface {
	IsActive() bool
}

IsActive is used to check if the connection is active.

type LongConnPool

type LongConnPool interface {
	ConnPool

	// Clean the state maintained in the poor for this address
	Clean(network, address string)
}

LongConnPool supports Clean connections to a desired address.

type Message

type Message interface {
	RPCInfo() rpcinfo.RPCInfo

	ServiceInfo() *serviceinfo.ServiceInfo

	Data() interface{}

	NewData(method string) (ok bool)

	MessageType() MessageType

	SetMessageType(MessageType)

	RPCRole() RPCRole

	PayloadLen() int

	SetPayloadLen(size int)

	TransInfo() TransInfo

	Tags() map[string]interface{}

	ProtocolInfo() ProtocolInfo

	SetProtocolInfo(ProtocolInfo)

	PayloadCodec() PayloadCodec

	SetPayloadCodec(pc PayloadCodec)

	Recycle()
}

Message is the core abstraction for Kitex message.

func NewMessage

func NewMessage(data interface{}, svcInfo *serviceinfo.ServiceInfo, ri rpcinfo.RPCInfo, msgType MessageType, rpcRole RPCRole) Message

NewMessage creates a new Message using the given info.

func NewMessageWithNewer

func NewMessageWithNewer(svcInfo *serviceinfo.ServiceInfo, ri rpcinfo.RPCInfo, msgType MessageType, rpcRole RPCRole) Message

NewMessageWithNewer creates a new Message and set data later.

type MessageType

type MessageType int32

MessageType indicates the type of message.

const (
	// 0-4 corresponding to thrift.TMessageType
	InvalidMessageType MessageType = 0
	Call               MessageType = 1
	Reply              MessageType = 2
	Exception          MessageType = 3
	// Oneway means there's no need to wait for the response.
	// When the actual message is transmitted, Oneway writes a Call to avoid compatibility issues
	// and to maintain consistency with the original logic.
	Oneway MessageType = 4

	Stream MessageType = 5
)

MessageTypes.

type MetaHandler

type MetaHandler interface {
	WriteMeta(ctx context.Context, msg Message) (context.Context, error)
	ReadMeta(ctx context.Context, msg Message) (context.Context, error)
}

MetaHandler reads or writes metadata through certain protocol. The protocol will be a thrift.TProtocol usually.

type NocopyWrite

type NocopyWrite interface {
	// the buf will be wrapped as a new data node no copy, then insert into the linked buffer.
	// remainCap is the remain capacity of origin buff.
	WriteDirect(buf []byte, remainCap int) error
}

NocopyWrite is to write []byte without copying, and splits the original buffer. It is used with linked buffer implement.

type Option

type Option struct {
	Outbounds []OutboundHandler

	Inbounds []InboundHandler

	StreamingMetaHandlers []StreamingMetaHandler
}

Option is used to pack the inbound and outbound handlers.

type OutboundHandler

type OutboundHandler interface {
	BoundHandler

	Write(ctx context.Context, conn net.Conn, send Message) (context.Context, error)
}

OutboundHandler is used to process write event.

type PayloadCodec

type PayloadCodec interface {
	Marshal(ctx context.Context, message Message, out ByteBuffer) error

	Unmarshal(ctx context.Context, message Message, in ByteBuffer) error

	Name() string
}

PayloadCodec is used to marshal and unmarshal payload.

func GetPayloadCodec

func GetPayloadCodec(message Message) (PayloadCodec, error)

GetPayloadCodec gets desired payload codec from message.

type ProtocolInfo

type ProtocolInfo struct {
	TransProto transport.Protocol
	CodecType  serviceinfo.PayloadCodec
}

ProtocolInfo is used to indicate the transport protocol and payload codec information.

func NewProtocolInfo

func NewProtocolInfo(tp transport.Protocol, ct serviceinfo.PayloadCodec) ProtocolInfo

NewProtocolInfo creates a new ProtocolInfo using the given tp and ct.

type RPCRole

type RPCRole int

RPCRole is to distinguished client or server

const (
	Client RPCRole = iota
	Server
)

RPC role

type RawConn

type RawConn interface {
	RawConn() net.Conn
}

RawConn is used to get the raw connection.

type ServerOption

type ServerOption struct {
	SvcInfo *serviceinfo.ServiceInfo

	TransServerFactory TransServerFactory

	SvrHandlerFactory ServerTransHandlerFactory

	Codec Codec

	PayloadCodec PayloadCodec

	Address net.Addr

	// Duration that server waits for to allow any existing connection to be closed gracefully.
	ExitWaitTime time.Duration

	// Duration that server waits for after error occurs during connection accepting.
	AcceptFailedDelayTime time.Duration

	// Duration that the accepted connection waits for to read or write data.
	MaxConnectionIdleTime time.Duration

	ReadWriteTimeout time.Duration

	InitRPCInfoFunc func(context.Context, net.Addr) (rpcinfo.RPCInfo, context.Context)

	TracerCtl *internal_stats.Controller

	Logger klog.FormatLogger

	Option
}

ServerOption contains option that is used to init the remote server.

type ServerTransHandler

type ServerTransHandler interface {
	TransHandler

	OnActive(ctx context.Context, conn net.Conn) (context.Context, error)

	OnRead(ctx context.Context, conn net.Conn) error
}

ServerTransHandler have some new functions.

type ServerTransHandlerFactory

type ServerTransHandlerFactory interface {
	NewTransHandler(opt *ServerOption) (ServerTransHandler, error)
}

ServerTransHandlerFactory to new TransHandler for server

type StreamingMetaHandler

type StreamingMetaHandler interface {
	// writes metadata before create a stream
	OnConnectStream(ctx context.Context) (context.Context, error)
	// reads metadata before read first message from stream
	OnReadStream(ctx context.Context) (context.Context, error)
}

StreamingMetaHandler reads or writes metadata through streaming header(http2 header)

type SynthesizedDialer

type SynthesizedDialer struct {
	DialFunc func(network, address string, timeout time.Duration) (net.Conn, error)
}

SynthesizedDialer is used to synthesize a DialFunc to implement a Dialer.

func (SynthesizedDialer) DialTimeout

func (sd SynthesizedDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error)

DialTimeout implements the Dialer interface.

type TransError

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

TransError is the error that can be transmitted, it corresponds to TApplicationException in Thrift

func NewTransError

func NewTransError(typeID int32, err error) TransError

NewTransError to build TransError with typeID and rawErr. rawErr can be used by errors.Is(target) to check err type, like read timeout.

func NewTransErrorWithMsg

func NewTransErrorWithMsg(typeID int32, message string) TransError

NewTransErrorWithMsg to build TransError with typeID and errMsg

func (TransError) Error

func (e TransError) Error() string

Error implements the error interface.

func (*TransError) Is

func (e *TransError) Is(target error) bool

Is to check if inner error that transError wrap is target error

func (*TransError) TypeID

func (e *TransError) TypeID() int32

TypeID return err type id

func (*TransError) Unwrap

func (e *TransError) Unwrap() error

Unwrap the transError to expose raw error

type TransHandler

type TransHandler interface {
	TransReadWriter

	OnInactive(ctx context.Context, conn net.Conn)

	OnError(ctx context.Context, err error, conn net.Conn)

	OnMessage(ctx context.Context, args, result Message) error

	SetPipeline(pipeline *TransPipeline)
}

TransHandler is similar to the handler role in netty Transport can be refactored to support pipeline, and then is able to support other extensions at conn level.

type TransInfo

type TransInfo interface {
	TransStrInfo() map[string]string
	TransIntInfo() map[uint16]string
	PutTransIntInfo(map[uint16]string)
	PutTransStrInfo(kvInfo map[string]string)
	Recycle()
}

TransInfo contains transport information.

type TransPipeline

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

TransPipeline contains TransHandlers.

func NewTransPipeline

func NewTransPipeline(netHdlr TransHandler) *TransPipeline

NewTransPipeline is used to create a new TransPipeline.

func (*TransPipeline) AddInboundHandler

func (p *TransPipeline) AddInboundHandler(hdlr InboundHandler) *TransPipeline

AddInboundHandler adds an InboundHandler to the pipeline.

func (*TransPipeline) AddOutboundHandler

func (p *TransPipeline) AddOutboundHandler(hdlr OutboundHandler) *TransPipeline

AddOutboundHandler adds an OutboundHandler to the pipeline.

func (*TransPipeline) OnActive

func (p *TransPipeline) OnActive(ctx context.Context, conn net.Conn) (context.Context, error)

OnActive implements the InboundHandler interface.

func (*TransPipeline) OnError

func (p *TransPipeline) OnError(ctx context.Context, err error, conn net.Conn)

OnError calls

func (*TransPipeline) OnInactive

func (p *TransPipeline) OnInactive(ctx context.Context, conn net.Conn)

OnInactive implements the InboundHandler interface.

func (*TransPipeline) OnMessage

func (p *TransPipeline) OnMessage(ctx context.Context, args, result Message) error

OnMessage implements the InboundHandler interface.

func (*TransPipeline) OnRead

func (p *TransPipeline) OnRead(ctx context.Context, conn net.Conn) error

OnRead implements the InboundHandler interface.

func (*TransPipeline) Read

func (p *TransPipeline) Read(ctx context.Context, conn net.Conn, msg Message) error

Read reads from conn.

func (*TransPipeline) SetPipeline

func (p *TransPipeline) SetPipeline(transPipe *TransPipeline)

SetPipeline does nothing now.

func (*TransPipeline) Write

func (p *TransPipeline) Write(ctx context.Context, conn net.Conn, sendMsg Message) error

Write implements the OutboundHandler interface.

type TransReadWriter

type TransReadWriter interface {
	Write(ctx context.Context, conn net.Conn, send Message) error

	Read(ctx context.Context, conn net.Conn, msg Message) error
}

TransReadWriter .

type TransServer

type TransServer interface {
	CreateListener(net.Addr) (net.Listener, error)

	BootstrapServer() (err error)

	Shutdown() error

	ConnCount() utils.AtomicInt
}

TransServer is the abstraction for remote server.

type TransServerFactory

type TransServerFactory interface {
	NewTransServer(opt *ServerOption, transHdlr ServerTransHandler) TransServer
}

TransServerFactory is used to create TransServer instances.

Directories

Path Synopsis
Package connpool provide short connection and long connection pool.
Package connpool provide short connection and long connection pool.
Package remotecli for remote client
Package remotecli for remote client
detection
Package detection protocol detection
Package detection protocol detection
invoke
Package invoke .
Package invoke .
netpoll
Package netpoll contains server and client implementation for netpoll.
Package netpoll contains server and client implementation for netpoll.
nphttp2
Package nphttp2 transport powered by netpoll
Package nphttp2 transport powered by netpoll
nphttp2/codes
Package codes defines the canonical error codes used by gRPC.
Package codes defines the canonical error codes used by gRPC.
nphttp2/grpc
Package grpc defines and implements message oriented communication channel to complete various transactions (e.g., an RPC).
Package grpc defines and implements message oriented communication channel to complete various transactions (e.g., an RPC).
nphttp2/metadata
Package metadata define the structure of the metadata supported by gRPC library.
Package metadata define the structure of the metadata supported by gRPC library.
nphttp2/status
Package status implements errors returned by gRPC.
Package status implements errors returned by gRPC.
Package transmeta .
Package transmeta .

Jump to

Keyboard shortcuts

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