runtime

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionNotBound = errors.New("client session is not bound")
	ErrSessionExpired  = errors.New("client session has expired")
	ErrSessionClosed   = errors.New("client session is closed")
)
View Source
var (
	ErrConnectionExists   = errors.New("proxy connection already exists")
	ErrConnectionNotFound = errors.New("proxy connection not found")
	ErrInvalidIdentity    = errors.New("proxy identity is invalid")
	ErrUpstreamMissing    = errors.New("proxy upstream is missing")
)

Functions

func RespondSessionError added in v0.3.0

func RespondSessionError(s *api.Session, err error)

RespondSessionError completes the original RPC with a stable liveness error.

Types

type ClientSessionOptions added in v0.3.0

type ClientSessionOptions struct {
	TTL      time.Duration
	Now      func() time.Time
	OnOpened func(context.Context, int64, *proxypb.ClientSessionRef) error
	OnClosed func(context.Context, int64, *proxypb.ClientSessionRef, proxypb.SessionEndReason) error
}

ClientSessionOptions controls ephemeral, per-connection liveness. Hooks run without the lease lock and must not assume a loaded business User.

type ClientSessions added in v0.3.0

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

ClientSessions owns leases, not business users or sockets. Explicit Open is the only operation that creates a lease. Renew cannot resurrect a closed connection.

func NewClientSessions added in v0.3.0

func NewClientSessions(opts ClientSessionOptions) *ClientSessions

NewClientSessions creates a component with no implicit background goroutine.

func (*ClientSessions) Close added in v0.3.0

func (m *ClientSessions) Close(ctx context.Context) error

Close retires all live references and rejects further activation.

func (*ClientSessions) Count added in v0.3.0

func (m *ClientSessions) Count(uid int64) int

Count reports currently live connections without loading a User or renewing.

func (*ClientSessions) End added in v0.3.0

End is idempotent and closes only one full connection reference. A close that arrives before Open retires the reference as well, preventing reordered activation.

func (*ClientSessions) Expire added in v0.3.0

func (m *ClientSessions) Expire(ctx context.Context) error

Expire removes elapsed leases and old retirement markers. Retired references are retained at least as long as a bounded lifecycle RPC can remain in flight. Heartbeats always reject unknown references, including after marker collection.

func (*ClientSessions) Open added in v0.3.0

Open accepts only a previously authenticated live proxy reference. Repeated Open is idempotent and does not renew; a different UID cannot steal the same reference.

func (*ClientSessions) RegisterHeartbeat added in v0.3.0

func (m *ClientSessions) RegisterHeartbeat(reg *api.Registry) error

RegisterHeartbeat provides an optional pure framework heartbeat. Business heartbeats use their own PB, validate business conditions, then call RenewCaller.

func (*ClientSessions) RegisterRPC added in v0.3.0

func (m *ClientSessions) RegisterRPC(reg *api.Registry) error

RegisterRPC binds proxy-only lifecycle messages to the UID's business owner. These handlers do not load, create, or mark a business User active.

func (*ClientSessions) Renew added in v0.3.0

Renew extends only the exact, already-live UID/reference binding.

func (*ClientSessions) RenewCaller added in v0.3.0

func (m *ClientSessions) RenewCaller(s *api.Session) error

RenewCaller renews only the trusted connection associated with this invocation.

func (*ClientSessions) Run added in v0.3.0

func (m *ClientSessions) Run(ctx context.Context) error

Run owns the expiry loop; the application invokes it in its service lifecycle.

func (*ClientSessions) Validate added in v0.3.0

func (m *ClientSessions) Validate(ctx context.Context, uid int64, ref *proxypb.ClientSessionRef) error

Validate checks liveness without extending the deadline.

func (*ClientSessions) ValidateCaller added in v0.3.0

func (m *ClientSessions) ValidateCaller(s *api.Session) error

ValidateCaller verifies the current invocation's exact connection without renewing it.

type Delivery

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

Delivery 跟踪用于下行消息的存活传输连接。

func NewDelivery

func NewDelivery() *Delivery

NewDelivery 创建空的存活连接投递注册表。

func (*Delivery) Add

func (d *Delivery) Add(conn proxy.Connection) error

Add 按 ID 注册一个连接,并拒绝重复所有权。

func (*Delivery) Broadcast

func (d *Delivery) Broadcast(ctx context.Context, connIDs []string, msg rpc.Message) error

Broadcast 向每个连接 ID 发送同一条消息,并合并失败。

func (*Delivery) Close

func (d *Delivery) Close(ctx context.Context, connID string) error

Close 关闭并注销一个连接 ID。

func (*Delivery) CloseAll added in v0.3.0

func (d *Delivery) CloseAll(ctx context.Context) error

CloseAll also closes connections that have not authenticated yet.

func (*Delivery) Remove

func (d *Delivery) Remove(connID string) bool

Remove 注销一个连接 ID,并返回其是否存在。

func (*Delivery) Send

func (d *Delivery) Send(ctx context.Context, connID string, msg rpc.Message) error

Send 克隆并投递一条下行消息到已注册连接。

type Gateway

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

Gateway 拥有已认证客户端 Session,并转发上行消息;它不了解 Player、World、DBPlayer 或 feature Module。

func NewGateway

func NewGateway(auth proxy.Authenticator, upstream proxy.Upstream) *Gateway

NewGateway 创建带空连接索引和 UID 索引的 proxy Gateway。

func (*Gateway) Accept

func (g *Gateway) Accept(ctx context.Context, conn proxy.Connection, req proxy.AuthRequest) (Session, error)

Accept 认证并注册一个连接。

func (*Gateway) AcceptIdentity

func (g *Gateway) AcceptIdentity(conn proxy.Connection, identity proxy.Identity) (Session, error)

AcceptIdentity 直接按已认证身份注册连接。

func (*Gateway) ConnectionIDs

func (g *Gateway) ConnectionIDs(uid int64) []string

ConnectionIDs 返回 uid 当前已认证的连接 ID 列表。

func (*Gateway) Disconnect

func (g *Gateway) Disconnect(connID string) bool

Disconnect 从 Session 注册表移除一个连接。

func (*Gateway) DisconnectSession

func (g *Gateway) DisconnectSession(connID string) (Session, bool)

DisconnectSession 从 Session 注册表移除一个连接,并返回被移除的 Session。

func (*Gateway) MembershipLock added in v0.3.0

func (g *Gateway) MembershipLock() sync.Locker

MembershipLock coordinates adapter admission and first/last UID subscription changes across every server sharing this gateway. Do not hold it over business RPC, lifecycle hooks or socket writes. It is not the registry's internal lock.

func (*Gateway) Receive

func (g *Gateway) Receive(ctx context.Context, connID string, msg rpc.Message) error

Receive 向上游转发一条已认证客户端消息。

func (*Gateway) Session

func (g *Gateway) Session(connID string) (Session, bool)

Session 按连接 ID 返回连接级 Session 快照。

func (*Gateway) Sessions added in v0.3.0

func (g *Gateway) Sessions() []Session

Sessions returns detached connection metadata for orderly proxy shutdown.

func (*Gateway) SessionsByUID

func (g *Gateway) SessionsByUID(uid int64) []Session

SessionsByUID 返回 uid 当前已认证的 Session 快照。

type RPCSessionLifecycle added in v0.3.0

type RPCSessionLifecycle struct {
	Bus     rpc.Bus
	Timeout time.Duration
}

RPCSessionLifecycle binds a live authenticated proxy to the business owner's lifecycle routes. Local and NATS buses use the same messages and metadata.

func NewRPCSessionLifecycle added in v0.3.0

func NewRPCSessionLifecycle(bus rpc.Bus) *RPCSessionLifecycle

NewRPCSessionLifecycle creates the standard proxy lifecycle adapter.

func (*RPCSessionLifecycle) OnConnect added in v0.3.0

func (l *RPCSessionLifecycle) OnConnect(ctx context.Context, session Session) error

OnConnect waits for the business owner to accept this exact connection lease.

func (*RPCSessionLifecycle) OnDisconnect added in v0.3.0

func (l *RPCSessionLifecycle) OnDisconnect(ctx context.Context, session Session, reason proxypb.SessionEndReason) error

OnDisconnect notifies the owner; expiry is the fallback when delivery fails.

type RPCUpstream

type RPCUpstream struct {
	Bus      rpc.Bus
	Delivery *Delivery
	Timeout  time.Duration
}

RPCUpstream 将已认证客户端消息转发到 aifd-rpc Bus。

func NewRPCUpstream

func NewRPCUpstream(bus rpc.Bus, delivery *Delivery) *RPCUpstream

NewRPCUpstream 创建使用指定 Bus 的上行转发器。

func (*RPCUpstream) Forward

func (u *RPCUpstream) Forward(ctx context.Context, env proxy.Envelope) error

Forward 将 Envelope 中的消息按 uid 投递到 RPC route。

type Session

type Session struct {
	ConnectionID    string
	Identity        proxy.Identity
	ProxyInstanceID string
}

Session 是 proxy 连接级 runtime 状态。

func (Session) Ref added in v0.3.0

func (s Session) Ref() *proxypb.ClientSessionRef

Ref returns the native connection's immutable wire reference.

Jump to

Keyboard shortcuts

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