Import path:
gitlab.soludian.com/soludian/fountain/libs/fnet/fquic
fquic
import "gitlab.soludian.com/soludian/fountain/libs/fnet/fquic"Index
- Constants
- Variables
- func New() runnable.AppInstance
- func SendMessageToStream(stream *quic.Stream, server *Server, cntl *codec.MessageController, msg proto.Message) error
- func WithConfig(c *config) runnable.AppInstance
- func WithConfigKey(configKey string) runnable.AppInstance
- type DefaultQUICCodec
- type Handle
- type Option
- func WithAddr(addr string) Option
- func WithConnectionReceiveWindow(initial, max uint64) Option
- func WithDatagrams(enable bool) Option
- func WithHandshakeIdleTimeout(timeout time.Duration) Option
- func WithKeepAlivePeriod(period time.Duration) Option
- func WithMaxIdleTimeout(timeout time.Duration) Option
- func WithMaxIncomingStreams(max int64) Option
- func WithMaxIncomingUniStreams(max int64) Option
- func WithMaxTokenAge(age time.Duration) Option
- func WithMetrics(enable bool) Option
- func WithName(name string) Option
- func WithSlowLogThreshold(threshold time.Duration) Option
- func WithStreamReceiveWindow(initial, max uint64) Option
- func WithTLS(certFile, keyFile string) Option
- type OptionFunc
- type QUICCodec
- type Server
- func GetFountainInstance(opts ...Option) *Server
- func InstallFountainInstance(opts ...Option) *Server
- func (s *Server) BroadcastMessage(msg proto.Message) error
- func (s *Server) BroadcastRawData(data []byte) error
- func (s *Server) Counter() metrics.Counter
- func (s *Server) Destroy() error
- func (s *Server) FindServiceHandler(msg proto.Message) Handle
- func (s *Server) FindStreamHandler(name string) StreamHandler
- func (s *Server) GetConnectionManager() *connect.ConnectionManager
- func (s *Server) GetLocalAddr() net.Addr
- func (s *Server) GetMessageCodec() *codec.MessageController
- func (s *Server) Histogram() metrics.Histogram
- func (s *Server) Initialize() error
- func (s *Server) PackageName() string
- func (s *Server) RegisterServiceHandler(x proto.Message, handler Handle)
- func (s *Server) RegisterStreamHandler(name string, handler StreamHandler)
- func (s *Server) SendMessageByConn(conn *quic.Conn, cntl *codec.MessageController, msg proto.Message) error
- func (s *Server) SendMessageByConnID(key string, msg *codec.Message) error
- func (s *Server) Serving()
- func (s *Server) SetCallback(callback ServerCallback)
- func (s *Server) Use(mw middleware.Middleware)
- type ServerCallback
- type StreamHandler
Constants
const (
KPackageName = "fquic"
)Variables
var KDefaultServerName = env.GetFullAppService(KPackageName)func New
func New() runnable.AppInstanceNew creates a new QUIC server instance with default configuration
func SendMessageToStream
func SendMessageToStream(stream *quic.Stream, server *Server, cntl *codec.MessageController, msg proto.Message) errorSendMessageToStream sends a protobuf message to an existing stream
func WithConfig
func WithConfig(c *config) runnable.AppInstanceWithConfig creates a new QUIC server instance with provided configuration
func WithConfigKey
func WithConfigKey(configKey string) runnable.AppInstanceWithConfigKey creates a new QUIC server instance with configuration from config key
type DefaultQUICCodec
DefaultQUICCodec implements QUICCodec for QUIC streams Similar to DefaultTCPCodec but adapted for QUIC
type DefaultQUICCodec struct{}func (*DefaultQUICCodec) Close
func (c *DefaultQUICCodec) Close() errorClose closes the codec (no-op for stateless codec)
func (*DefaultQUICCodec) Receive
func (c *DefaultQUICCodec) Receive(stream *quic.Stream) (*codec.Message, error)Receive reads a codec.Message from QUIC stream Uses the same protocol format as TCP codec
func (*DefaultQUICCodec) Send
func (c *DefaultQUICCodec) Send(stream *quic.Stream, msg *codec.Message) errorSend sends a codec.Message over QUIC stream Uses the same protocol format as TCP codec
type Handle
Handle defines the function signature for message handlers Similar to ftcp pattern: func(*connect.Connection, *codec.MessageController, proto.Message) error
type Handle func(*connect.Connection, *codec.MessageController, proto.Message) errorfunc FindHandler
func FindHandler(msg proto.Message, server *Server) HandleFindHandler finds a handler for a protobuf message
type Option
Option defines the interface for configuring QUIC server options
type Option interface {
Apply(c *config)
}func WithAddr
func WithAddr(addr string) OptionWithAddr sets the server address
func WithConnectionReceiveWindow
func WithConnectionReceiveWindow(initial, max uint64) OptionWithConnectionReceiveWindow sets the initial and maximum connection receive window
func WithDatagrams
func WithDatagrams(enable bool) OptionWithDatagrams enables or disables datagram support
func WithHandshakeIdleTimeout
func WithHandshakeIdleTimeout(timeout time.Duration) OptionWithHandshakeIdleTimeout sets the handshake idle timeout
func WithKeepAlivePeriod
func WithKeepAlivePeriod(period time.Duration) OptionWithKeepAlivePeriod sets the keep-alive period
func WithMaxIdleTimeout
func WithMaxIdleTimeout(timeout time.Duration) OptionWithMaxIdleTimeout sets the maximum idle timeout
func WithMaxIncomingStreams
func WithMaxIncomingStreams(max int64) OptionWithMaxIncomingStreams sets the maximum number of incoming bidirectional streams
func WithMaxIncomingUniStreams
func WithMaxIncomingUniStreams(max int64) OptionWithMaxIncomingUniStreams sets the maximum number of incoming unidirectional streams
func WithMaxTokenAge
func WithMaxTokenAge(age time.Duration) OptionWithMaxTokenAge sets the maximum token age
func WithMetrics
func WithMetrics(enable bool) OptionWithMetrics enables or disables metrics
func WithName
func WithName(name string) OptionWithName sets the server name
func WithSlowLogThreshold
func WithSlowLogThreshold(threshold time.Duration) OptionWithSlowLogThreshold sets the slow log threshold
func WithStreamReceiveWindow
func WithStreamReceiveWindow(initial, max uint64) OptionWithStreamReceiveWindow sets the initial and maximum stream receive window
func WithTLS
func WithTLS(certFile, keyFile string) OptionWithTLS sets the TLS certificate and key files
type OptionFunc
OptionFunc is a function that implements the Option interface
type OptionFunc func(c *config)func (OptionFunc) Apply
func (f OptionFunc) Apply(c *config)Apply implements the Option interface
type QUICCodec
QUICCodec interface for QUIC message encoding/decoding
type QUICCodec interface {
Send(stream *quic.Stream, msg *codec.Message) error
Receive(stream *quic.Stream) (*codec.Message, error)
Close() error
}func NewQUICCodec
func NewQUICCodec() QUICCodecNewQUICCodec creates a new QUIC codec
type Server
Server represents a QUIC server instance
type Server struct {
*runnable.ServerInstance
// contains filtered or unexported fields
}func GetFountainInstance
func GetFountainInstance(opts ...Option) *ServerGetFountainInstance is an alias for InstallFountainInstance for compatibility
func InstallFountainInstance
func InstallFountainInstance(opts ...Option) *ServerInstallFountainInstance creates and configures a QUIC server instance
func (*Server) BroadcastMessage
func (s *Server) BroadcastMessage(msg proto.Message) errorBroadcastMessage broadcasts a message to all connected clients using server-level encoding
func (*Server) BroadcastRawData
func (s *Server) BroadcastRawData(data []byte) errorBroadcastRawData broadcasts raw bytes to all connected clients using worker pool
func (*Server) Counter
func (s *Server) Counter() metrics.CounterCounter returns the metrics counter
func (*Server) Destroy
func (s *Server) Destroy() errorDestroy gracefully shuts down the server
func (*Server) FindServiceHandler
func (s *Server) FindServiceHandler(msg proto.Message) HandleFindServiceHandler finds a protobuf message handler
func (*Server) FindStreamHandler
func (s *Server) FindStreamHandler(name string) StreamHandlerFindStreamHandler finds a stream handler by name
func (*Server) GetConnectionManager
func (s *Server) GetConnectionManager() *connect.ConnectionManagerGetConnectionManager returns the connection manager for advanced operations
func (*Server) GetLocalAddr
func (s *Server) GetLocalAddr() net.AddrGetLocalAddr returns the local address the server is listening on
func (*Server) GetMessageCodec
func (s *Server) GetMessageCodec() *codec.MessageControllerGetMessageCodec returns the server-level message codec
func (*Server) Histogram
func (s *Server) Histogram() metrics.HistogramHistogram returns the metrics histogram
func (*Server) Initialize
func (s *Server) Initialize() errorInitialize prepares the server for serving
func (*Server) PackageName
func (s *Server) PackageName() stringPackageName package name
func (*Server) RegisterServiceHandler
func (s *Server) RegisterServiceHandler(x proto.Message, handler Handle)RegisterServiceHandler registers a protobuf message handler Similar to ftcp RegisterServiceHandler
func (*Server) RegisterStreamHandler
func (s *Server) RegisterStreamHandler(name string, handler StreamHandler)RegisterStreamHandler registers a stream handler by name
func (*Server) SendMessageByConn
func (s *Server) SendMessageByConn(conn *quic.Conn, cntl *codec.MessageController, msg proto.Message) errorSendMessageByConn sends a protobuf message over QUIC connection. It wraps a raw *quic.Conn in a transient connect.Connection so the shared SendMessage codec path can be reused. Callers that already have a managed connect.Connection should call connect.Connection.SendMessage directly to avoid the wrapping cost.
func (*Server) SendMessageByConnID
func (s *Server) SendMessageByConnID(key string, msg *codec.Message) errorSendMessageByConnID func; Send data according to addr
func (*Server) Serving
func (s *Server) Serving()Serving starts serving QUIC connections
func (*Server) SetCallback
func (s *Server) SetCallback(callback ServerCallback)SetCallback sets the server callback for connection events
func (*Server) Use
func (s *Server) Use(mw middleware.Middleware)Use adds a middleware to the server
type ServerCallback
ServerCallback defines the callback interface for QUIC server events
type ServerCallback interface {
OnNewQUICConnection(conn *quic.Conn)
OnQUICConnectionClosed(conn *quic.Conn)
OnQUICStream(stream *quic.Stream)
}type StreamHandler
StreamHandler defines handler function for QUIC streams
type StreamHandler func(stream *quic.Stream) errorGenerated by gomarkdoc