Documentation
¶
Index ¶
- Constants
- Variables
- func GetConnID(conn quic.Connection) string
- func ParseFrame(stream io.Reader) (frame.Frame, error)
- type AsyncHandler
- type Client
- func (c *Client) ClientID() string
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context, addr string) error
- func (c *Client) Init(opts ...ClientOption) error
- func (c *Client) Logger() log.Logger
- func (c *Client) ServerAddr() string
- func (c *Client) SetBackflowFrameObserver(fn func(*frame.BackflowFrame))
- func (c *Client) SetCloseHandler(fn func())
- func (c *Client) SetDataFrameObserver(fn func(*frame.DataFrame))
- func (c *Client) SetErrorHandler(fn func(err error))
- func (c *Client) SetObserveDataTags(tag ...byte)
- func (c *Client) WriteFrame(frm frame.Frame) error
- type ClientOption
- type ClientOptions
- type ClientType
- type ConnState
- type Connection
- type ConnectionHandler
- type Connector
- type Context
- func (c *Context) Clean()
- func (c *Context) CloseWithError(code yerr.ErrorCode, msg string)
- func (c *Context) ConnID() string
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetDuration(key string) (d time.Duration)
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetStringMap(key string) (sm map[string]interface{})
- func (c *Context) GetStringMapString(key string) (sms map[string]string)
- func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
- func (c *Context) GetStringSlice(key string) (ss []string)
- func (c *Context) GetTime(key string) (t time.Time)
- func (c *Context) GetUint(key string) (ui uint)
- func (c *Context) GetUint64(key string) (ui64 uint64)
- func (c *Context) Set(key string, value interface{})
- func (c *Context) WithFrame(f frame.Frame) *Context
- type FrameHandler
- type FrameStream
- type Listener
- type Metadata
- type MetadataBuilder
- type PipeHandler
- type Route
- type Router
- type Server
- func (s *Server) AddDownstreamServer(addr string, c *Client)
- func (s *Server) Close() error
- func (s *Server) ConfigMetadataBuilder(builder MetadataBuilder)
- func (s *Server) ConfigRouter(router Router)
- func (s *Server) Connector() Connector
- func (s *Server) Downstreams() map[string]*Client
- func (s *Server) Init(opts ...ServerOption) error
- func (s *Server) ListenAndServe(ctx context.Context, addr string) error
- func (s *Server) Options() ServerOptions
- func (s *Server) Serve(ctx context.Context, conn net.PacketConn) error
- func (s *Server) SetAfterHandlers(handlers ...FrameHandler)
- func (s *Server) SetBeforeHandlers(handlers ...FrameHandler)
- func (s *Server) SetConnectionCloseHandlers(handlers ...ConnectionHandler)
- func (s *Server) StatsCounter() int64
- func (s *Server) StatsFunctions() map[string]string
- type ServerOption
- type ServerOptions
- type Workflow
Constants ¶
const ( ClientLogPrefix = "\033[36m[core:client]\033[0m " ServerLogPrefix = "\033[32m[core:server]\033[0m " ParseFrameLogPrefix = "\033[36m[core:stream_parser]\033[0m " )
Prefix is the prefix for logger.
const (
// DefaultListenAddr is the default address to listen.
DefaultListenAddr = "0.0.0.0:9000"
)
Variables ¶
var DefalutQuicConfig = &quic.Config{ Versions: []quic.VersionNumber{quic.Version1, quic.VersionDraft29}, MaxIdleTimeout: time.Second * 5, KeepAlivePeriod: time.Second * 2, MaxIncomingStreams: 1000, MaxIncomingUniStreams: 1000, HandshakeIdleTimeout: time.Second * 3, InitialStreamReceiveWindow: 1024 * 1024 * 2, InitialConnectionReceiveWindow: 1024 * 1024 * 2, }
DefalutQuicConfig be used when `quicConfig` is nil.
Functions ¶
Types ¶
type AsyncHandler ¶
AsyncHandler is the request-response mode (asnyc)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the abstraction of a YoMo-Client. a YoMo-Client can be Source, Upstream Zipper or StreamFunction.
func NewClient ¶
func NewClient(appName string, connType ClientType, opts ...ClientOption) *Client
NewClient creates a new YoMo-Client.
func (*Client) Logger ¶ added in v1.6.0
Logger get client's logger instance, you can customize this using `yomo.WithLogger`
func (*Client) ServerAddr ¶
ServerAddr returns the address of the server.
func (*Client) SetBackflowFrameObserver ¶ added in v1.8.0
func (c *Client) SetBackflowFrameObserver(fn func(*frame.BackflowFrame))
SetBackflowFrameObserver sets the backflow frame handler.
func (*Client) SetCloseHandler ¶ added in v1.9.1
func (c *Client) SetCloseHandler(fn func())
SetCloseHandler set close handler
func (*Client) SetDataFrameObserver ¶
SetDataFrameObserver sets the data frame handler.
func (*Client) SetErrorHandler ¶ added in v1.7.3
SetErrorHandler set error handler
func (*Client) SetObserveDataTags ¶ added in v1.6.0
SetObserveDataTags set the data tag list that will be observed. Deprecated: use yomo.WithObserveDataTags instead
type ClientOption ¶
type ClientOption func(*ClientOptions)
ClientOption YoMo client options
func WithClientQuicConfig ¶
func WithClientQuicConfig(qc *quic.Config) ClientOption
WithClientQuicConfig sets quic config for the client.
func WithClientTLSConfig ¶
func WithClientTLSConfig(tc *tls.Config) ClientOption
WithClientTLSConfig sets tls config for the client.
func WithCredential ¶
func WithCredential(payload string) ClientOption
WithCredential sets the client credential method (used by client).
func WithLogger ¶ added in v1.6.0
func WithLogger(logger log.Logger) ClientOption
WithLogger sets logger for the client.
func WithObserveDataTags ¶ added in v1.6.0
func WithObserveDataTags(tags ...byte) ClientOption
WithObserveDataTags sets data tag list for the client.
type ClientOptions ¶
type ClientOptions struct { ObserveDataTags []byte QuicConfig *quic.Config TLSConfig *tls.Config Credential *auth.Credential Logger log.Logger }
ClientOptions are the options for YoMo client.
type ClientType ¶
type ClientType byte
ClientType represents the connection type.
const ( // ClientTypeNone is connection type "None". ClientTypeNone ClientType = 0xFF // ClientTypeSource is connection type "Source". ClientTypeSource ClientType = 0x5F // ClientTypeUpstreamZipper is connection type "Upstream Zipper". ClientTypeUpstreamZipper ClientType = 0x5E // ClientTypeStreamFunction is connection type "Stream Function". ClientTypeStreamFunction ClientType = 0x5D )
func (ClientType) String ¶
func (c ClientType) String() string
type Connection ¶ added in v1.7.4
type Connection interface { io.Closer // Name returns the name of the connection, which is set by clients Name() string // ClientID connection client ID ClientID() string // ClientType returns the type of the client (Source | SFN | UpstreamZipper) ClientType() ClientType // Metadata returns the extra info of the application Metadata() Metadata // Write should goroutine-safely send y3 frames to peer side Write(f frame.Frame) error // ObserveDataTags observed data tags ObserveDataTags() []byte }
Connection wraps the specific io connections (typically quic.Connection) to transfer y3 frames
type ConnectionHandler ¶ added in v1.9.0
type ConnectionHandler func(conn quic.Connection)
ConnectionHandler is the handler for quic connection
type Connector ¶
type Connector interface { // Add a connection. Add(connID string, conn Connection) // Remove a connection. Remove(connID string) // Get a connection by connection id. Get(connID string) Connection // GetSnapshot gets the snapshot of all connections. GetSnapshot() map[string]string // GetSourceConns gets the connections by source observe tags. GetSourceConns(sourceID string, tags byte) []Connection // Clean the connector. Clean() }
Connector is a interface to manage the connections and applications.
type Context ¶
type Context struct { // Conn is the connection of client. Conn quic.Connection // Stream is the long-lived connection between client and server. Stream io.ReadWriteCloser // Frame receives from client. Frame frame.Frame // Keys store the key/value pairs in context. Keys map[string]interface{} // contains filtered or unexported fields }
Context for YoMo Server.
func (*Context) CloseWithError ¶
CloseWithError closes the stream and cleans the context.
func (*Context) GetDuration ¶
GetDuration gets a time.Duration value by a specified key.
func (*Context) GetFloat64 ¶
GetFloat64 gets a float64 value by a specified key.
func (*Context) GetStringMap ¶
GetStringMap gets a map[string]interface{} value by a specified key.
func (*Context) GetStringMapString ¶
GetStringMapString gets a map[string]string value by a specified key.
func (*Context) GetStringMapStringSlice ¶
GetStringMapStringSlice gets a map[string][]string value by a specified key.
func (*Context) GetStringSlice ¶
GetStringSlice gets a []string value by a specified key.
type FrameStream ¶
type FrameStream struct {
// contains filtered or unexported fields
}
FrameStream is the QUIC Stream with the minimum unit Frame.
func NewFrameStream ¶
func NewFrameStream(s io.ReadWriter) *FrameStream
NewFrameStream creates a new FrameStream.
func (*FrameStream) ReadFrame ¶
func (fs *FrameStream) ReadFrame() (frame.Frame, error)
ReadFrame reads next frame from QUIC stream.
func (*FrameStream) WriteFrame ¶
func (fs *FrameStream) WriteFrame(f frame.Frame) (int, error)
WriteFrame writes a frame into QUIC stream.
type Listener ¶
type Listener interface { quic.Listener // Name listerner's name Name() string // Versions Versions() []string }
A Listener for incoming connections
type Metadata ¶ added in v1.7.4
type Metadata interface { // Encode is the serialize method Encode() []byte }
Metadata is used for storing extra info of the application
type MetadataBuilder ¶ added in v1.7.4
type MetadataBuilder interface { // Build will return an Metadata instance according to the handshake frame passed in Build(f *frame.HandshakeFrame) (Metadata, error) // Decode is the deserialize method Decode(buf []byte) (Metadata, error) }
MetadataBuilder is the builder of Metadata
type PipeHandler ¶
type PipeHandler func(in <-chan []byte, out chan<- *frame.PayloadFrame)
PipeHandler is the bidirectional stream mode (blocking).
type Route ¶
type Route interface { // Add a route. Add(connID string, name string, observeDataTags []byte) error // Remove a route. Remove(connID string) error // GetForwardRoutes returns all the subscribers by the given data tag. GetForwardRoutes(tag byte) []string }
Route manages data subscribers according to their observed data tags.
type Router ¶
type Router interface { // Route gets the route Route(metadata Metadata) Route // Clean the routes. Clean() }
Router is the interface to manage the routes for applications.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the underlining server of Zipper
func NewServer ¶
func NewServer(name string, opts ...ServerOption) *Server
NewServer create a Server instance.
func (*Server) AddDownstreamServer ¶
AddDownstreamServer add a downstream server to this server. all the DataFrames will be dispatch to all the downstreams.
func (*Server) ConfigMetadataBuilder ¶ added in v1.7.4
func (s *Server) ConfigMetadataBuilder(builder MetadataBuilder)
ConfigMetadataBuilder is used to set metadataBuilder by zipper
func (*Server) ConfigRouter ¶
ConfigRouter is used to set router by zipper
func (*Server) Downstreams ¶
Downstreams return all the downstream servers.
func (*Server) ListenAndServe ¶
ListenAndServe starts the server.
func (*Server) Options ¶
func (s *Server) Options() ServerOptions
Options returns the options of server.
func (*Server) SetAfterHandlers ¶
func (s *Server) SetAfterHandlers(handlers ...FrameHandler)
SetAfterHandlers set the after handlers of server.
func (*Server) SetBeforeHandlers ¶
func (s *Server) SetBeforeHandlers(handlers ...FrameHandler)
SetBeforeHandlers set the before handlers of server.
func (*Server) SetConnectionCloseHandlers ¶ added in v1.9.0
func (s *Server) SetConnectionCloseHandlers(handlers ...ConnectionHandler)
SetConnectionCloseHandlers set the connection close handlers of server.
func (*Server) StatsCounter ¶
StatsCounter returns how many DataFrames pass through server.
func (*Server) StatsFunctions ¶
StatsFunctions returns the sfn stats of server.
type ServerOption ¶
type ServerOption func(*ServerOptions)
ServerOption is the option for server.
func WithAuth ¶
func WithAuth(name string, args ...string) ServerOption
WithAuth sets the server authentication method.
func WithConn ¶
func WithConn(conn net.PacketConn) ServerOption
WithConn sets the connection for the server.
func WithServerQuicConfig ¶
func WithServerQuicConfig(qc *quic.Config) ServerOption
WithServerQuicConfig sets the QUIC configuration for the server.
func WithServerTLSConfig ¶
func WithServerTLSConfig(tc *tls.Config) ServerOption
WithServerTLSConfig sets the TLS configuration for the server.
type ServerOptions ¶
type ServerOptions struct { QuicConfig *quic.Config TLSConfig *tls.Config Addr string Auths []auth.Authentication Conn net.PacketConn }
ServerOptions are the options for YoMo server.