Documentation
¶
Index ¶
- Variables
- func ErrorCode(err error) string
- func FormatRemoteAccessURL(webURL string, target RemoteAccessTarget) (string, error)
- func GetJoinNodeName(name string) (string, error)
- func GetWorldSocketURL(base, path string) (string, error)
- func IsLocalPageURL(raw string) bool
- func NewDomainChannels() worldserver.DomainChannels
- func ParseWebOrigin(raw string) (*url.URL, error)
- func RegisterDirectRoutes(router gin.IRouter, node WorldNode, domain worldserver.WorldServer)
- func RegisterNode(ctx context.Context, identity NodeIdentity, ...) (worldserver.RegisterNodeResponse, error)
- func RunBridge(ctx context.Context, opt *WorldNodeOpt, input io.ReadCloser, ...) error
- func RunRelayAttachments(ctx context.Context, base string, identity NodeIdentity, ...)
- func SelectRemoteAccessPage(webURL string, relays, direct []string) string
- func ValidateAdvertisedTargets(defaultTarget string, targets []worldserver.AdvertisedTarget) error
- func WorldNamespaces() []storage.RecordNamespace
- type AcceptedChannel
- type Address
- type ChannelPurpose
- type ForwardRequest
- type FrameTransport
- type InboundTurnRequest
- type ListMessagesParams
- type ListPeersResult
- type ListThreadsParams
- type MessagePage
- type NodeIdentity
- type NodeNotification
- type NodeStatus
- type OpenSessionRequest
- type OpenedSession
- type PeerDialer
- type RecentContact
- type RelayAttachmentChanged
- type RelayEvent
- type RelayIncoming
- type RelayStatus
- type RemoteAccessTarget
- type SecureChannel
- type SendMessageRequest
- type ThreadBinding
- type ThreadPage
- type WorldHost
- type WorldMessage
- type WorldMessageDirection
- type WorldMessageStatus
- type WorldNode
- type WorldNodeOpt
- type WorldPeer
- type WorldRPCServer
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidWorldAddress = errors.New("invalid_world_address")
ErrInvalidWorldAddress 标识无法解析的联邦地址。
Functions ¶
func FormatRemoteAccessURL ¶
func FormatRemoteAccessURL(webURL string, target RemoteAccessTarget) (string, error)
FormatRemoteAccessURL 将目标和登录令牌放入页面 fragment。
func GetJoinNodeName ¶
GetJoinNodeName 未指定节点名时使用本机短主机名。
func GetWorldSocketURL ¶
GetWorldSocketURL 补齐控制面或直连 WebSocket 路径。
func NewDomainChannels ¶
func NewDomainChannels() worldserver.DomainChannels
NewDomainChannels 提供以域身份挂靠和查询成员的传输。
func ParseWebOrigin ¶
ParseWebOrigin 读取 World 远程访问页面的 HTTP 或 HTTPS 来源。
func RegisterDirectRoutes ¶
func RegisterDirectRoutes(router gin.IRouter, node WorldNode, domain worldserver.WorldServer)
RegisterDirectRoutes 按握手提示选择同一监听器上的域或节点身份。
func RegisterNode ¶
func RegisterNode(ctx context.Context, identity NodeIdentity, serverURL, nodeName, joinToken string) (worldserver.RegisterNodeResponse, error)
RegisterNode 用节点身份向控制面注册,返回控制面确认的节点名和域。
func RunBridge ¶
func RunBridge(ctx context.Context, opt *WorldNodeOpt, input io.ReadCloser, output io.WriteCloser) error
RunBridge 在可由 Close 中断的输入输出流上运行 World 节点与宿主的 JSON-RPC 会话。
func RunRelayAttachments ¶
func RunRelayAttachments(ctx context.Context, base string, identity NodeIdentity, events chan<- RelayEvent)
RunRelayAttachments 维护一个公开入口的实例挂靠,按入口报告可达状态。
func SelectRemoteAccessPage ¶
SelectRemoteAccessPage 优先使用指定来源,然后尝试外网 HTTPS relay、HTTPS 直连和其余可用地址。
func ValidateAdvertisedTargets ¶
func ValidateAdvertisedTargets(defaultTarget string, targets []worldserver.AdvertisedTarget) error
ValidateAdvertisedTargets 校验通告项以及裸节点地址对应的默认目标。
func WorldNamespaces ¶
func WorldNamespaces() []storage.RecordNamespace
WorldNamespaces 返回节点独立数据库的记录分组及查询索引。
Types ¶
type AcceptedChannel ¶
type AcceptedChannel struct {
Channel SecureChannel
Purpose ChannelPurpose
PeerKey ed25519.PublicKey
}
AcceptedChannel 返回用途及经签名验证的发起方公钥,匿名 RPC 的公钥为空。
func AcceptRelayChannel ¶
func AcceptRelayChannel(ctx context.Context, acceptURL string, identity NodeIdentity) (AcceptedChannel, error)
AcceptRelayChannel 拨回本次配对地址并用本机身份完成端到端握手。
func AcceptSecureChannel ¶
func AcceptSecureChannel(ctx context.Context, transport FrameTransport, local NodeIdentity) (_ AcceptedChannel, err error)
AcceptSecureChannel 核对用途、目标和签名后返回应用通道。
type Address ¶
type Address struct {
Node string `json:"node"`
Domain string `json:"domain"`
Target string `json:"target,omitempty"`
}
Address 标识联邦节点及其可选目标。
func ParseAddress ¶
ParseAddress 解析节点与可选目标,并补全同域简写。
type ChannelPurpose ¶
type ChannelPurpose string
ChannelPurpose 指定端到端握手认证的业务用途。
const ( ChannelPurposeWorld ChannelPurpose = "world" ChannelPurposeRPC ChannelPurpose = "rpc" ChannelPurposeDomain ChannelPurpose = "domain" )
type ForwardRequest ¶
type FrameTransport ¶
type FrameTransport interface {
// WriteFrame 投递一帧,返回后调用方可复用输入切片。
WriteFrame(ctx context.Context, frame []byte) error
// ReadFrame 读取下一帧,返回的切片归读方使用。
ReadFrame(ctx context.Context) ([]byte, error)
// Close 可并发重复调用,使阻塞及后续读写返回错误。
Close() error
}
FrameTransport 按序传输完整帧,支持一个写方与一个读方并发使用。
type InboundTurnRequest ¶
type InboundTurnRequest struct {
OpenedSession OpenedSession
Message WorldMessage
Target string
}
InboundTurnRequest 将已打开的会话和待处理的来信交给宿主。
type ListMessagesParams ¶
type ListMessagesParams struct {
Direction string `json:"direction,omitempty"`
PeerAddresses []string `json:"peer_addr,omitempty"`
Kind string `json:"kind,omitempty"`
Status string `json:"status,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
ThreadID string `json:"thread_id,omitempty"`
Limit *int `json:"limit,omitempty"`
CursorID *string `json:"cursor_id,omitempty"`
}
type ListPeersResult ¶
type ListPeersResult struct {
Recent []RecentContact `json:"recent"`
Peers []WorldPeer `json:"peers"`
}
type ListThreadsParams ¶
type MessagePage ¶
type MessagePage listPage[WorldMessage]
type NodeIdentity ¶
type NodeIdentity struct {
NodeID string `json:"node_id"`
SignPublic []byte `json:"sign_public"`
SignPrivate []byte `json:"sign_private"`
BoxPublic []byte `json:"box_public"`
BoxPrivate []byte `json:"box_private"`
}
NodeIdentity 保存本机持久身份,私钥仅用于本地签名和密钥协商。
func LoadOrCreateIdentity ¶
func LoadOrCreateIdentity(path string) (NodeIdentity, error)
LoadOrCreateIdentity 从节点私有目录读取身份,首次启用时原子创建。
type NodeNotification ¶
type NodeNotification struct {
Event string `json:"event"`
Data json.RawMessage `json:"data"`
}
NodeNotification 是节点发布的状态、联系人或消息更新。
type NodeStatus ¶
type NodeStatus struct {
Revoked bool `json:"revoked"`
// 本机联邦是否启用?
Enabled bool `json:"enabled"`
AdminEnabled bool `json:"admin_enabled"`
NodeAddr string `json:"node_addr"`
ServerURL string `json:"server_url"`
// 本机是否已收到控制面的通讯录?
Connected bool `json:"connected"`
PendingOutboxCount int `json:"pending_outbox_count"`
RemoteAccessLocalOnly bool `json:"remote_access_local_only,omitempty"`
RemoteAccessRelays []RelayStatus `json:"remote_access_relays,omitempty"`
RemoteAccessURL string `json:"remote_access_url,omitempty"`
RelayAttachments []RelayStatus `json:"relay_attachments,omitempty"`
}
NodeStatus 是节点状态接口返回的运行、连接和离线队列信息。
type OpenSessionRequest ¶
type OpenSessionRequest struct {
ThreadID string `json:"thread_id"`
Target string `json:"target"`
PeerAddr string `json:"peer_addr"`
Title string `json:"title"`
ExistingSessionID string `json:"existing_session_id,omitempty"`
}
OpenSessionRequest 指定来信线程及其已有的宿主会话。
type OpenedSession ¶
type OpenedSession struct {
SessionID string `json:"session_id"`
RootSessionID defs.SessionID `json:"-"`
}
OpenedSession 保存线程绑定的宿主 ID 和本次执行使用的根 Session ID。
type PeerDialer ¶
type PeerDialer struct {
// contains filtered or unexported fields
}
PeerDialer 拨通目标节点或域,按入口缓存公开 relay 的实例列表。零值可以直接使用。
func (*PeerDialer) DialPeer ¶
func (d *PeerDialer) DialPeer(ctx context.Context, address string, peerKey ed25519.PublicKey, entries worldserver.PeerEntries, identity *NodeIdentity, purpose ChannelPurpose) (SecureChannel, error)
DialPeer 在一个直连预算内按序尝试地址,再分别经各个 relay 完成配对与握手。
type RecentContact ¶
RecentContact 给出外域对端及最近活动的线程。
type RelayAttachmentChanged ¶
RelayAttachmentChanged 由挂靠连接收到登记确认或断开时提交。
type RelayEvent ¶
type RelayEvent interface {
// contains filtered or unexported methods
}
RelayEvent 是挂靠连接通知所属事件循环的状态变化或拨入请求。
type RelayIncoming ¶
type RelayIncoming struct {
AcceptURL string
}
RelayIncoming 由挂靠读取任务在 relay 通知目标接通时提交。
type RelayStatus ¶
type RelayStatus struct {
URL string `json:"url"`
Implicit bool `json:"implicit"`
// 是否收到 relay 的挂靠确认?
Connected bool `json:"connected"`
}
RelayStatus 是节点到单个 relay 的挂靠状态。
type RemoteAccessTarget ¶
type RemoteAccessTarget struct {
Name string `json:"name,omitempty"`
Token string `json:"-"`
Node string `json:"node,omitempty"`
Domain string `json:"domain,omitempty"`
PublicKey ed25519.PublicKey `json:"public_key"`
Entries worldserver.PeerEntries `json:"entries"`
}
RemoteAccessTarget 是远程访问链接中公布的节点身份和拨号入口。
func ParseRemoteAccessURL ¶
func ParseRemoteAccessURL(rawURL string) (RemoteAccessTarget, error)
ParseRemoteAccessURL 读取 fragment 的目标和可选登录令牌。
func (RemoteAccessTarget) ConnectionTimeout ¶
func (t RemoteAccessTarget) ConnectionTimeout() time.Duration
ConnectionTimeout 包含直连、各 relay 和最后的认证初始化预算。
func (RemoteAccessTarget) GetDisplayName ¶
func (t RemoteAccessTarget) GetDisplayName() string
GetDisplayName 返回链接携带的名称或目标公钥的短指纹。
type SecureChannel ¶
type SecureChannel interface {
// WriteMessage 加密并发送一条消息。
WriteMessage(ctx context.Context, payload []byte) error
// ReadMessage 认证并解密下一条消息。
ReadMessage(ctx context.Context) ([]byte, error)
// Close 关闭通道,唤醒阻塞的收发操作。
Close() error
}
SecureChannel 在已认证节点间收发消息;一个写方可与一个读方 并发,同方向调用由调用方串行化。
func DialSecureChannel ¶
func DialSecureChannel(ctx context.Context, transport FrameTransport, local *NodeIdentity, peerKey ed25519.PublicKey, purpose ChannelPurpose) (_ SecureChannel, err error)
DialSecureChannel 以预期的响应方公钥验证握手,匿名发起方只能使用 RPC。
type SendMessageRequest ¶
type ThreadBinding ¶
type ThreadBinding struct {
PeerDomain string `json:"peer_domain"`
Target string `json:"target"`
ThreadID string `json:"thread_id"`
ConversationID string `json:"conversation_id"`
PeerAddr string `json:"peer_addr"`
Direction string `json:"direction"` // inbound | outbound
RemainingHops int `json:"remaining_hops"` // 收到时保存的剩余跳数
CreatedAt int64 `json:"created_at"`
}
ThreadBinding 将来信线程绑定到本地对话及该轮的转发预算。
type ThreadPage ¶
type ThreadPage listPage[ThreadBinding]
type WorldHost ¶
type WorldHost interface {
OpenSession(ctx context.Context, req OpenSessionRequest) (OpenedSession, error)
RunInboundTurn(ctx context.Context, req InboundTurnRequest, onSubmitted func()) (string, error)
NotifyOutbound(ctx context.Context, msg WorldMessage) error
}
WorldHost 打开来信会话、执行来信并接收异步回信。
func NewRuntimeHost ¶
NewRuntimeHost 让 World 使用本机 Runtime 处理消息。
type WorldMessage ¶
type WorldMessage struct {
MessageID string `json:"message_id"`
ThreadID string `json:"thread_id"`
Direction WorldMessageDirection `json:"direction"`
PeerAddr string `json:"peer_addr"`
Target string `json:"target,omitempty"`
Kind string `json:"kind"` // message | reply
ConversationID string `json:"conversation_id,omitempty"`
Subject string `json:"subject,omitempty"`
Body string `json:"body"`
InReplyTo string `json:"in_reply_to,omitempty"`
HopLimit int `json:"hop_limit"`
Status WorldMessageStatus `json:"status"`
ReplyBody string `json:"reply_body,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
ErrorText string `json:"error_text,omitempty"`
NotifyConversation bool `json:"notify_conversation"`
ReceivedSequence uint64 `json:"received_sequence,omitempty"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
WorldMessage 保存本节点收发的消息、对话归属和处理结果。
type WorldMessageDirection ¶
type WorldMessageDirection string
WorldMessageDirection 标记消息相对于本节点的收发方向。
const ( WorldMessageDirectionOutbound WorldMessageDirection = "outbound" WorldMessageDirectionInbound WorldMessageDirection = "inbound" )
type WorldMessageStatus ¶
type WorldMessageStatus string
WorldMessageStatus 记录发件投递或收件处理的进度。
const ( WorldMessageStatusPendingOffline WorldMessageStatus = "pending_offline" WorldMessageStatusSending WorldMessageStatus = "sending" WorldMessageStatusUnknown WorldMessageStatus = "unknown" WorldMessageStatusRemoteRunning WorldMessageStatus = "remote_running" WorldMessageStatusReplied WorldMessageStatus = "replied" WorldMessageStatusFailed WorldMessageStatus = "failed" WorldMessageStatusCancelled WorldMessageStatus = "cancelled" WorldMessageStatusAccepted WorldMessageStatus = "accepted" WorldMessageStatusRunning WorldMessageStatus = "running" WorldMessageStatusCompleted WorldMessageStatus = "completed" )
type WorldNode ¶
type WorldNode interface {
executor.ToolProvider
GetStatus(ctx context.Context, token string) (NodeStatus, error)
ListPeers(ctx context.Context) (ListPeersResult, error)
SendMessage(ctx context.Context, req SendMessageRequest) (WorldMessage, error)
// EnqueueMessage 入队后返回消息和可选的结果通道。
EnqueueMessage(ctx context.Context, req SendMessageRequest) (WorldMessage, <-chan WorldMessage, error)
// WaitMessage 等待入队消息的投递结果。
WaitMessage(ctx context.Context, message WorldMessage, finished <-chan WorldMessage) (WorldMessage, error)
Forward(ctx context.Context, rt runtime.Runtime, req ForwardRequest) (WorldMessage, error)
ListMessages(ctx context.Context, params ListMessagesParams) (MessagePage, error)
CancelMessage(ctx context.Context, messageID string) (WorldMessage, error)
ListThreads(ctx context.Context, params ListThreadsParams) (ThreadPage, error)
Subscribe(ctx context.Context) (<-chan NodeNotification, error)
// ServeNodeDirect 接受以节点身份握手的直连。
ServeNodeDirect(c *gin.Context)
// Run 运行节点,退出时取消并等待连接、握手和来信任务。
Run(ctx context.Context, host WorldHost, rpc WorldRPCServer) error
}
WorldNode 把本机对话接入联邦通讯录和端到端消息通道。
func NewWorldNode ¶
func NewWorldNode(opt *WorldNodeOpt) (WorldNode, error)
NewWorldNode 校验节点配置并准备事件循环。
type WorldNodeOpt ¶
type WorldNodeOpt struct {
Records storage.RecordStorage
Identity NodeIdentity
NodeName string
Domain string
ServerURL string
WebURL string
RemoteAccessName string
Relays []string
DirectURLs []string
DefaultTarget string
AdvertiseTargets []worldserver.AdvertisedTarget
DefaultWait time.Duration
Telemetry *telemetry.Telemetry
}
WorldNodeOpt 保存本机身份、通告目标、控制面地址与独立记录库。
func NewWorldNodeOpt ¶
func NewWorldNodeOpt(records storage.RecordStorage, identity NodeIdentity, nodeName, domain, serverURL string) *WorldNodeOpt
NewWorldNodeOpt 设置节点的必需依赖。
type WorldPeer ¶
type WorldPeer struct {
Address string `json:"address"`
NodeName string `json:"node_name"`
// 联系人是否可以投递?
Online bool `json:"online"`
Description string `json:"description,omitempty"`
Targets []worldserver.AdvertisedTarget `json:"targets"`
}
type WorldRPCServer ¶
type WorldRPCServer interface {
ServeWorldRPC(ctx context.Context, conn SecureChannel) error
}
WorldRPCServer 接受节点已完成握手的 RPC 通道。