silly_ctrl

package module
v0.0.0-...-39cf8b4 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyWithContext

func CopyWithContext(ctx context.Context, src io.Reader, dst io.Writer) error

func DoQUICRequest

func DoQUICRequest[T, R proto.Message](ctx context.Context, msg T, ret R, conn quic.Connection, callback RequestCallback[R]) error

func Forward

func Forward(ctx context.Context, x, y io.ReadWriter) error

func GenerateAuthToken

func GenerateAuthToken(ak, sk string) *packet.Handshake

func GenerateSignature

func GenerateSignature(args ...string) []byte

func GenerateSignatureString

func GenerateSignatureString(args ...string) string

func RetWithError

func RetWithError(e error) *packet.Ret

func RunWorkers

func RunWorkers[T Worker](ctx context.Context, workers ...T) error

Types

type App

type App struct {
	AccessKey string
	Secret    string
}

func (*App) Signature

func (app *App) Signature() *packet.Handshake

func (*App) Validate

func (app *App) Validate(handshake *packet.Handshake) error

type Config

type Config struct {
	HeartbeatInterval    time.Duration `json:"heartbeat_interval"`     // 心跳时间间隔
	MaxHeartbeatInterval time.Duration `json:"max_heartbeat_interval"` // 最大心跳时间间隔
	LocalAddress         string        `json:"local_address"`
	ConnectionQueueSize  int           `json:"connection_queue_size"` // 连接队列的大小
	HandshakeTimeout     time.Duration `json:"handshake_timeout"`
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) Options

func (c *Config) Options(opt ...func(cfg *Config) (*Config, error)) (*Config, error)

type ErrorNo

type ErrorNo uint64
const (
	NoError ErrorNo = iota
	AuthError
	UnknownAppError
	SignatureTimeoutError
	HandshakeFailedError
	UnknownCommandError
	BadParamError
	SessionAlreadyExists
	ApplicationOver
	UnknownSessionError
	UnknownError
)

func (ErrorNo) Code

func (e ErrorNo) Code() uint64

func (ErrorNo) Error

func (e ErrorNo) Error() string

func (ErrorNo) String

func (e ErrorNo) String() string

type Node

type Node interface {
	Run(ctx context.Context, tlsConfig *tls.Config) error
	Connect(ctx context.Context, addr string, app *App, tlsConfig *tls.Config) error
	Manager() SessionManager
}

type RequestCallback

type RequestCallback[R proto.Message] func(ctx context.Context, response R, stream quic.Stream) error

type Service

type Service interface {
	Type() packet.CommandType
	Invoke(ctx context.Context, command *packet.Command, session Session, manager SessionManager, stream quic.Stream) error
}

type ServiceMapping

type ServiceMapping map[packet.CommandType]Service

func (ServiceMapping) Invoke

func (mapping ServiceMapping) Invoke(ctx context.Context, cmd *packet.Command, session Session, manager SessionManager, stream quic.Stream) error

func (ServiceMapping) Register

func (mapping ServiceMapping) Register(services ...Service) ServiceMapping

func (ServiceMapping) Type

func (mapping ServiceMapping) Type() packet.CommandType

type Session

type Session interface {
	ID() string
	RemoteAddr() net.Addr
	IsRemote() bool // IsRemote 是否本地发起的连接
	App() *App
	Info() *packet.Heartbeat
	Exec(ctx context.Context, cmd *packet.Command, callback SessionExecCallback) error
}

type SessionExecCallback

type SessionExecCallback func(ctx context.Context, ret *packet.Ret, sess Session, stream quic.Stream) error

type SessionManager

type SessionManager interface {
	Put(sess Session) error
	Get(accessKey string) (Session, bool)
	Del(accessKey string) error
}

type Validator

type Validator interface {
	Validate(handshake *packet.Handshake) (*App, error)
}

func NewBasicValidator

func NewBasicValidator(apps []App) Validator

type Worker

type Worker interface {
	Tag() string
	Run(ctx context.Context) error
}

func NewWorker

func NewWorker(logger *slog.Logger, name string, creators ...WorkerCreator) Worker

func SimpleWorker

func SimpleWorker(tag string, fn func(ctx context.Context) error) Worker

type WorkerCreator

type WorkerCreator func(ctx context.Context) (Worker, error)

Directories

Path Synopsis
app

Jump to

Keyboard shortcuts

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