Documentation ¶
Index ¶
- Constants
- func ConcurrentClient(n int, bufferSize int, client ClientConstructor, config *Config, ...) (*concurrentClient, error)
- func CreateBuffer(height, weight int) *buffer
- func NewConnection(conn net.Conn, buf *bytes.Buffer, index uint16) *connection
- type Client
- func (c *Client) Ask(route string, v any) porterr.IError
- func (c *Client) AskBytes(route string, b []byte) porterr.IError
- func (c *Client) Ctx() context.Context
- func (c *Client) Dial() (net.Conn, porterr.IError)
- func (c *Client) Logger() gocli.Logger
- func (c *Client) Parse(v any) porterr.IError
- func (c *Client) Read() (ISignature, porterr.IError)
- func (c *Client) SetStream(stream Streamer)
- func (c *Client) Signature() ISignature
- func (c *Client) Stream() Streamer
- func (c *Client) WithContext(ctx context.Context)
- type ClientConstructor
- type Config
- type ConnectionLimit
- type DataEncryptor
- type DataEncryptorConstructor
- type Decoder
- type EmptyDataEncryptor
- type EmptyDecoder
- type EmptyEncoder
- type Encoder
- type GobClient
- type GobDataEncryptor
- type Handler
- type IClient
- type ISignature
- type JsonDataEncryptor
- type PermanentBuffer
- func (b *PermanentBuffer) Bytes() []byte
- func (b *PermanentBuffer) Cap() int
- func (b *PermanentBuffer) Next(n int) []byte
- func (b *PermanentBuffer) Read(p []byte) (n int, err error)
- func (b *PermanentBuffer) Reset()
- func (b *PermanentBuffer) Seek(offset int64, whence int) (int64, error)
- func (b *PermanentBuffer) Write(data []byte) (n int, err error)
- type Route
- type Server
- type Signature
- func (h *Signature) Data() []byte
- func (h *Signature) Decode(r io.Reader, buf *bytes.Buffer) error
- func (h *Signature) Encode(buf *bytes.Buffer) []byte
- func (h *Signature) Encryptor() DataEncryptor
- func (h *Signature) InitEncryptor(buf *bytes.Buffer)
- func (h *Signature) Len() uint64
- func (h *Signature) Read(p []byte) (n int, err error)
- func (h *Signature) Reset()
- func (h *Signature) Route() string
- func (h *Signature) Write(p []byte) (n int, err error)
- type Streamer
- type TLSConfig
Constants ¶
const ( // 4 MB MinimumSharedBufferSize = 1024 * 2 // 2 KB // ClientModeResponder Client can't ask ClientModeResponder = 0 // ClientModeAsker client can't respond ClientModeAsker = 1 )DefaultSharedBufferSize = 1024 * 1024 * 4
Variables ¶
This section is empty.
Functions ¶
func ConcurrentClient ¶
func ConcurrentClient(n int, bufferSize int, client ClientConstructor, config *Config, logger gocli.Logger) (*concurrentClient, error)
ConcurrentClient create concurrent GetFreeClient with n, n <= 0 ignores bufferSize - shared buffer size
func CreateBuffer ¶
func CreateBuffer(height, weight int) *buffer
CreateBuffer create buffer for data height - how many connection weight - how many bytes required one connection
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client structure
func CreateClient ¶
func CreateClient(config *Config, sig ISignature, logger gocli.Logger) Client
CreateClient create base client
func (*Client) Read ¶
func (c *Client) Read() (ISignature, porterr.IError)
Read get signature from stream
func (*Client) WithContext ¶
WithContext with context
type ClientConstructor ¶
ClientConstructor func for specific GetFreeClient init
type Config ¶
type Config struct { // tcp address Address *net.TCPAddr // connection limits Limits ConnectionLimit // TLS configuration TLS TLSConfig // Mode client mode. 0 - Responder, - 1 Asker Mode uint8 }
Config server configuration
type ConnectionLimit ¶
type ConnectionLimit struct { // Maximum number of connection MaxConnections uint16 `yaml:"maxConnections"` // Max idle time before connection will be closed MaxIdle time.Duration `yaml:"maxIdle"` SharedBufferSize int32 `yaml:"sharedBufferSize"` // RedialTimeout timeout for redial. Specify in second RedialTimeout time.Duration `yaml:"redialTimeout"` }
ConnectionLimit limits for connection
type DataEncryptor ¶
type DataEncryptor interface { // Encode message Encode(v any) error // Decode message Decode(v any) error // RegisterType register custom type RegisterType(v any) }
DataEncryptor provide encoding and decoding and register type
func NewEmptyDataEncryptor ¶
func NewEmptyDataEncryptor(buf *bytes.Buffer) DataEncryptor
NewEmptyDataEncryptor init empty data encryptor
func NewGobDataEncryptor ¶
func NewGobDataEncryptor(buf *bytes.Buffer) DataEncryptor
NewGobDataEncryptor init gob data encryptor
func NewJSONDataEncryptor ¶
func NewJSONDataEncryptor(buf *bytes.Buffer) DataEncryptor
NewJSONDataEncryptor init json data encryptor
type DataEncryptorConstructor ¶
type DataEncryptorConstructor func(buf *bytes.Buffer) DataEncryptor
DataEncryptorConstructor apply constructor in set stream method
type EmptyDataEncryptor ¶
type EmptyDataEncryptor struct {
// contains filtered or unexported fields
}
EmptyDataEncryptor empty data encryptor
func (*EmptyDataEncryptor) RegisterType ¶
func (d *EmptyDataEncryptor) RegisterType(v any)
RegisterType register custom type
type EmptyDecoder ¶
type EmptyDecoder struct {
// contains filtered or unexported fields
}
EmptyDecoder decoder do nothing
type EmptyEncoder ¶
type EmptyEncoder struct {
// contains filtered or unexported fields
}
EmptyEncoder encoder do nothing
type GobClient ¶
type GobClient struct { // Common GetFreeClient Client }
GobClient GetFreeClient for gob serialization
type GobDataEncryptor ¶
type GobDataEncryptor struct {
// contains filtered or unexported fields
}
GobDataEncryptor encode decode via gob serialisation
func (*GobDataEncryptor) RegisterType ¶
func (d *GobDataEncryptor) RegisterType(v any)
RegisterType register custom type
type Handler ¶
type Handler func(client IClient)
Handler Procedure handler
type IClient ¶
type IClient interface { // Ask custom type message Ask(route string, v any) porterr.IError // AskBytes send bytes AskBytes(route string, b []byte) porterr.IError // Ctx get context Ctx() context.Context // Dial to server Dial() (net.Conn, porterr.IError) // Logger get logger Logger() gocli.Logger // Parse current message Parse(v any) porterr.IError // Read get signature from stream Read() (ISignature, porterr.IError) // SetStream set stream io SetStream(stream Streamer) // Signature return signature Signature() ISignature // Stream Get stream Stream() Streamer // WithContext With context WithContext(ctx context.Context) }
IClient interface for communication
type ISignature ¶
type ISignature interface { // Data useful message Data() []byte // Decode byte message Decode(r io.Reader, buf *bytes.Buffer) error // Encode byte message Encode(buf *bytes.Buffer) []byte // Encryptor get data encryptor Encryptor() DataEncryptor // InitEncryptor return init data encryptor constructor InitEncryptor(buf *bytes.Buffer) // Len of data Len() uint64 // Read implements reader interface Read(p []byte) (n int, err error) // Reset signature Reset() // Route get message route Route() string // Write implements writer interface Write(p []byte) (n int, err error) }
ISignature common interface
type JsonDataEncryptor ¶
type JsonDataEncryptor struct {
// contains filtered or unexported fields
}
JsonDataEncryptor encode decode via json serialisation
func (*JsonDataEncryptor) RegisterType ¶
func (d *JsonDataEncryptor) RegisterType(v any)
RegisterType register custom type
type PermanentBuffer ¶
type PermanentBuffer struct {
// contains filtered or unexported fields
}
PermanentBuffer local buffer
func NewPermanentBuffer ¶
func NewPermanentBuffer(data []byte) *PermanentBuffer
NewPermanentBuffer init buffer
func (*PermanentBuffer) Read ¶
func (b *PermanentBuffer) Read(p []byte) (n int, err error)
Read bytes
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server server main struct
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
Signature standard handler signature
func CreateSignature ¶
func CreateSignature(route []byte, data []byte, initEncryptor DataEncryptorConstructor) Signature
CreateSignature prepare Signature struct
func (*Signature) Encryptor ¶
func (h *Signature) Encryptor() DataEncryptor
Encryptor get data encryptor
func (*Signature) InitEncryptor ¶
InitEncryptor init encryptor
type Streamer ¶
type Streamer interface { // Buffer get buffer Buffer() *bytes.Buffer // Connection get connection Connection() net.Conn // Exit chan for exit Exit() <-chan struct{} // Index get index Index() uint16 // Release connection Release() error }
Streamer interface