stream

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeviceIDFromCert

func DeviceIDFromCert(cert []byte) entity.DeviceID

Types

type Client

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

func NewClient

func NewClient(options *ClientOptions) (cli *Client)

func (*Client) Close

func (cli *Client) Close() error

func (*Client) Serve

func (cli *Client) Serve(ctx context.Context)

type ClientOptions

type ClientOptions struct {
	Handler ConnectionHandler
	DialOptions
}

type ConnectionHandler

type ConnectionHandler interface {
	ServeConn(ctx context.Context, conn quic.Connection)
	Close() error
}

type ConnectionProvider

type ConnectionProvider interface {
	Acquire(ctx context.Context, peer *entity.Server) (quic.Connection, error)
}

ConnectionProvider 链接器(不需要进行多线程保护)

type ConnectionTracker

type ConnectionTracker interface {
	Enter(conn_id uint64, device_id entity.DeviceID, conn quic.Connection)
	Leave(conn_id uint64, device_id entity.DeviceID, conn quic.Connection)
	Close() error
}

func NewDefaultConnectionTracker

func NewDefaultConnectionTracker() ConnectionTracker

type DefaultConnectionHandler

type DefaultConnectionHandler struct {
	Tracker ConnectionTracker
	Handler StreamHandler
	// contains filtered or unexported fields
}

func (*DefaultConnectionHandler) Close

func (svr *DefaultConnectionHandler) Close() error

func (*DefaultConnectionHandler) ServeConn

func (svr *DefaultConnectionHandler) ServeConn(ctx context.Context, conn quic.Connection)

type DefaultConnectionProvider

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

func (*DefaultConnectionProvider) Acquire

func (provider *DefaultConnectionProvider) Acquire(ctx context.Context, peer *entity.Server) (conn quic.Connection, err error)

type DefaultConnectionTracker

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

func (*DefaultConnectionTracker) Close

func (st *DefaultConnectionTracker) Close() error

func (*DefaultConnectionTracker) Enter

func (st *DefaultConnectionTracker) Enter(conn_id uint64, device_id entity.DeviceID, conn quic.Connection)

func (*DefaultConnectionTracker) Leave

func (st *DefaultConnectionTracker) Leave(conn_id uint64, device_id entity.DeviceID, conn quic.Connection)

type DefaultSessionManager

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

func (*DefaultSessionManager) Acquire

func (mgr *DefaultSessionManager) Acquire(ctx context.Context, peer *entity.Server) (ss *SessionStream, err error)

func (*DefaultSessionManager) Close

func (mgr *DefaultSessionManager) Close() error

func (*DefaultSessionManager) EnsureConn

func (mgr *DefaultSessionManager) EnsureConn(ctx context.Context, peer *entity.Server) (conn quic.Connection, err error)

func (*DefaultSessionManager) Serve

func (mgr *DefaultSessionManager) Serve(ctx context.Context)

type DialOptions

type DialOptions struct {
	Address     string
	Certificate string
	PrivateKey  string

	ApplicationProtocol string
	Retry               int           // 默认 0 时,不做重试;当 Retry < 0 时无限重试
	Backoff             time.Duration // 默认 2400ms 重试间隔
}

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, peer *entity.Server) error
	Serve(ctx context.Context)
	Close() error
}

type ServeMux

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

func NewServeMux

func NewServeMux() (mux *ServeMux)

func (ServeMux) Handle

func (mux ServeMux) Handle(path string, handler StreamHandler)

func (ServeMux) HandleFunc

func (mux ServeMux) HandleFunc(path string, fn func(ctx context.Context, ss *SessionStream))

func (ServeMux) ServeStream

func (mux ServeMux) ServeStream(ctx context.Context, src *SessionStream)

type Server

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

func NewServer

func NewServer(options *ServerOptions) (svr *Server, err error)

func (*Server) Close

func (svr *Server) Close() error

func (*Server) Serve

func (svr *Server) Serve(ctx context.Context)

type ServerOptions

type ServerOptions struct {
	Handler     ConnectionHandler
	Authorize   func(device_id entity.DeviceID) bool
	Certificate string
	PrivateKey  string

	ApplicationProtocol string
}

type SessionManager

type SessionManager interface {
	EnsureConn(ctx context.Context, peer *entity.Server) (conn quic.Connection, err error)
	Acquire(ctx context.Context, peer *entity.Server) (stream *SessionStream, err error)
	Serve(ctx context.Context)
	Close() error
}

func NewSessionManager

func NewSessionManager(options *SessionManagerOptions) (mgr SessionManager)

type SessionManagerOptions

type SessionManagerOptions struct {
	DialOptions
	Resolver Resolver // 默认为空时,不支持 P2P 寻址
	Handler  ConnectionHandler
}

type SessionStream

type SessionStream struct {
	Peer entity.Server
	Conn quic.Connection
	// contains filtered or unexported fields
}

func NewSessionStream

func NewSessionStream(peer *entity.Server, conn quic.Connection) (ss *SessionStream, err error)

func (*SessionStream) CloseWrite

func (ss *SessionStream) CloseWrite() error

func (*SessionStream) Read

func (ss *SessionStream) Read(data []byte) (int, error)

func (*SessionStream) Reader

func (ss *SessionStream) Reader() *bufio.Reader

func (*SessionStream) RemoteAddr

func (ss *SessionStream) RemoteAddr() net.Addr

func (*SessionStream) RemotePeer

func (ss *SessionStream) RemotePeer() *entity.Server

func (*SessionStream) Write

func (ss *SessionStream) Write(data []byte) (int, error)

type StreamHandler

type StreamHandler interface {
	ServeStream(ctx context.Context, stream *SessionStream)
}

type StreamHandlerFunc

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

func (StreamHandlerFunc) ServeStream

func (shf StreamHandlerFunc) ServeStream(ctx context.Context, ss *SessionStream)

type Transport

type Transport struct {
	// contains filtered or unexported fields
}
var DefaultTransport *Transport

func InitTransport

func InitTransport(options TransportOptions) (tr *Transport, err error)

func (*Transport) Close

func (tr *Transport) Close() (err error)

func (*Transport) Dial

func (tr *Transport) Dial(ctx context.Context, options *DialOptions) (conn quic.Connection, device_id entity.DeviceID, err error)

func (*Transport) LocalAddress

func (tr *Transport) LocalAddress() net.Addr

func (*Transport) WriteTo

func (tr *Transport) WriteTo(b []byte, a net.Addr) (int, error)

type TransportOptions

type TransportOptions struct {
	LocalAddress string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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