sync

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentRuntime

type AgentRuntime struct {
	Uptime               int64 `json:"uptime"`
	CachedTokens         int   `json:"cached_tokens"`
	CachedChannels       int   `json:"cached_channels"`
	CachedModels         int   `json:"cached_models"`
	CachedGlobalRoutings int   `json:"cached_global_routings"`
	CachedUserRoutings   int   `json:"cached_user_routings"`
	ActiveConnections    int   `json:"active_connections"`
	Version              int64 `json:"version"`
	MasterVersion        int64 `json:"master_version"`

	CacheStats map[string]protocol.CacheEntityStats `json:"cache_stats,omitempty"`
}

type AutoAddrUpdate

type AutoAddrUpdate struct {
	AgentID       string               `json:"agent_id"`
	HTTPAddresses []agentproxy.Address `json:"http_addresses"`
}

AutoAddrUpdate is the push event payload for auto-detected address updates.

type FetchHandler

type FetchHandler interface {
	Fetch(ctx context.Context, q dao.AdminQuery, key string) (
		data, side json.RawMessage, found bool, err error,
	)
}

FetchHandler 是单实体的按需拉取处理器。 返回 (data, side, found, err):

  • data 是实体本身的 JSON
  • side 是可选旁路负载(如 token 响应里的 SyncedUser)
  • found=false 表示 master 也未查到(调用方应让 agent 进入负缓存)
  • err 仅用于真正的内部错误(DB 故障等),not-found 用 found=false 表示

type FetchRegistry

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

FetchRegistry 是实体名 → handler 的注册表。 主流程通过 Resolve 路由请求;新增实体仅需注册一次。

func NewFetchRegistry

func NewFetchRegistry() *FetchRegistry

NewFetchRegistry 返回带默认实体(token / user)注册的 registry。 Token / User 的具体 handler 在 fetch_token.go / fetch_user.go 中定义。

func (*FetchRegistry) Register

func (r *FetchRegistry) Register(entity string, h FetchHandler)

Register 注册或替换某实体的 handler。

func (*FetchRegistry) Resolve

func (r *FetchRegistry) Resolve(entity string) (FetchHandler, bool)

Resolve 返回实体对应的 handler。

type Hub

type Hub struct {
	App        dao.AppProvider
	Logger     *zap.Logger
	Bus        app.EventBus
	GetVersion func() int64
	// contains filtered or unexported fields
}

func NewHub

func NewHub(application dao.AppProvider, logger *zap.Logger, bus app.EventBus, getVersion func() int64) *Hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(method string, params any)

Broadcast sends a notification to all connected agents. 复制 conns snapshot 后释放 RLock,再 fan-out。 每条 conn 的 SendNotification 是非阻塞 enqueue(见 ws.Conn.WriteJSON), 病 conn 队列满会自己 Close,不会拖累其他 conn 或新接入。

func (*Hub) Call

func (h *Hub) Call(agentID string, method string, params any, timeout time.Duration) (json.RawMessage, error)

Call sends an RPC request to a connected agent and waits for response.

func (*Hub) ConnectedAgents

func (h *Hub) ConnectedAgents() int

ConnectedAgents returns the number of connected agents

func (*Hub) GetAgentAddresses

func (h *Hub) GetAgentAddresses(agentID string, dbHTTPAddrs string) []agentproxy.Address

GetAgentAddresses returns merged addresses for an agent. Priority: manual config (DB) > auto-detected (memory).

func (*Hub) GetOnlineAgentIDs

func (h *Hub) GetOnlineAgentIDs() []string

GetOnlineAgentIDs returns IDs of currently connected agents.

func (*Hub) GetRuntime

func (h *Hub) GetRuntime(agentID string) *AgentRuntime

GetRuntime returns cached runtime info for an agent, or nil if not available.

func (*Hub) HandleWS

func (h *Hub) HandleWS(c *gin.Context)

func (*Hub) IsOnline

func (h *Hub) IsOnline(agentID string) bool

IsOnline checks if an agent is currently connected.

type Publisher

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

func NewPublisher

func NewPublisher(hub *Hub, bus app.EventBus, version *atomic.Int64, logger *zap.Logger) *Publisher

func (*Publisher) Start

func (p *Publisher) Start()

Jump to

Keyboard shortcuts

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