Documentation
¶
Overview ¶
Package p2px P2P 设备直传 supervisor(2026-10-14 对称节点 spec §7)。
职责切分:数据面走子进程(每任务 spawn p2pc,进程组 kill 即取消,与 desktop sidecar 语义一致——p2pc 协议层无 ctx 取消,kill 是唯一取消面); 控制面进程内:任务编排/口令与输出解析/配额监控/孤儿清扫。standalone 专属 (多副本语义未定义,与 federation 同约束)。
配置来源:SystemConfig p2p.direct 子段(DB 热生效),经 Deps.GetDirect 注入 (构造注入,棘轮规则 8:不直读全局 conf)。env/yaml 不参与直传段——后台即真相。
spawn.go — p2pc 子进程生命周期:spawn/输出解析/配额监控/进程组取消。
Index ¶
- Constants
- type Deps
- type Service
- func (s *Service) Cancel(ctx context.Context, taskID string) error
- func (s *Service) List(ctx context.Context) []*TaskSnapshot
- func (s *Service) MarkPublished(taskID string)
- func (s *Service) PublishPaths(ctx context.Context, taskID string) ([]string, error)
- func (s *Service) Recv(ctx context.Context, code string) (*Task, error)
- func (s *Service) Send(ctx context.Context, paths []string) (*Task, error)
- func (s *Service) Status(ctx context.Context) (Status, error)
- func (s *Service) Stop() error
- type Status
- type Task
- type TaskSnapshot
Constants ¶
const ( StateWaiting = "waiting" // 已 spawn,等待对端接入/传输启动 StateRunning = "running" // 传输进行中(收到口令行之外的首个输出) StateDone = "done" StateFailed = "failed" StateCanceled = "canceled" )
任务状态机。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct {
// Standalone 部署形态判定(棘轮规则 8:构造注入,不直读全局 conf)
Standalone func() bool
// DataDir 服务数据目录(默认收件区/任务工作区基准)
DataDir string
// GetDirect 读当前直传配置(DB 热生效;bool=false 表示未配置)
GetDirect func(ctx context.Context) (conf.P2PDirectConfig, bool)
// MonitorInterval 配额监控周期(缺省 5s;测试可压到毫秒级)
MonitorInterval time.Duration
// InboxTTL 收件区文件存活期(缺省 7 天;终态/已发布/无属主目录超期即清扫,spec §7.3)
InboxTTL time.Duration
}
Deps supervisor 依赖注入(生产由 bootstrap/wiring 装配;测试注入桩)。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service supervisor 服务。
func (*Service) List ¶
func (s *Service) List(ctx context.Context) []*TaskSnapshot
List 任务列表(创建时间倒序)。
func (*Service) MarkPublished ¶
MarkPublished 置发布标记(handler 在全部文件铸分享成功后调用)。
func (*Service) PublishPaths ¶
PublishPaths 收件任务的可发布绝对路径(三层防穿越:任务态校验+目录归属+symlink 归一)。 只列顶层常规文件(目录由 share 侧逐文件递归处理不在本期范围)。 幂等闸:已发布过的任务拒绝(重复/并发 publish 会重复铸分享+重复拷存储)。
type Status ¶
type Status struct {
Available bool
BinaryPath string
Enabled bool
RegistryURL string
RecvDir string
InboxUsed int64
InboxQuota int64
DeployAllowed bool
}
Status admin 状态面。