Help us shape the future of Go! Take the 2026 Go Developer Survey

p2px

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

View Source
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 NewService

func NewService(deps Deps) *Service

NewService 构造(幂等清扫孤儿 + 起配额监控协程)。

func (*Service) Cancel

func (s *Service) Cancel(ctx context.Context, taskID string) error

Cancel 取消任务(kill 进程组)。

func (*Service) List

func (s *Service) List(ctx context.Context) []*TaskSnapshot

List 任务列表(创建时间倒序)。

func (*Service) MarkPublished

func (s *Service) MarkPublished(taskID string)

MarkPublished 置发布标记(handler 在全部文件铸分享成功后调用)。

func (*Service) PublishPaths

func (s *Service) PublishPaths(ctx context.Context, taskID string) ([]string, error)

PublishPaths 收件任务的可发布绝对路径(三层防穿越:任务态校验+目录归属+symlink 归一)。 只列顶层常规文件(目录由 share 侧逐文件递归处理不在本期范围)。 幂等闸:已发布过的任务拒绝(重复/并发 publish 会重复铸分享+重复拷存储)。

func (*Service) Recv

func (s *Service) Recv(ctx context.Context, code string) (*Task, error)

Recv 发起接收任务(口令 → spawn p2pc recv --yes --out <收件区>/<taskID>)。

func (*Service) Send

func (s *Service) Send(ctx context.Context, paths []string) (*Task, error)

Send 发起发送任务(白名单校验 → spawn p2pc send → 口令行异步解析进任务)。

func (*Service) Status

func (s *Service) Status(ctx context.Context) (Status, error)

Status 状态面:二进制探测 + 生效配置 + 收件区用量。

func (*Service) Stop

func (s *Service) Stop() error

Stop 停机(Cleanup 调用;幂等):杀全部在途子进程 + 停监控。

type Status

type Status struct {
	Available     bool
	BinaryPath    string
	Enabled       bool
	RegistryURL   string
	RecvDir       string
	InboxUsed     int64
	InboxQuota    int64
	DeployAllowed bool
}

Status admin 状态面。

type Task

type Task struct {
	ID        string
	Kind      string // send | recv
	Code      string
	Paths     []string
	BytesDone int64
	CreatedAt time.Time
	// contains filtered or unexported fields
}

Task 直传任务(内存态;重启即 expired 语义——pid 文件清扫兜底)。

func (*Task) Snapshot

func (t *Task) Snapshot() TaskSnapshot

Snapshot 并发安全快照。

type TaskSnapshot

type TaskSnapshot struct {
	ID         string
	Kind       string
	State      string
	Code       string
	Paths      []string
	BytesDone  int64
	Error      string
	CreatedAt  time.Time
	FinishedAt time.Time
}

TaskSnapshot 对外只读快照(handler 消费)。

Jump to

Keyboard shortcuts

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