memtree

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 29 Imported by: 0 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

Overview

Package memtree 为 core/internal/sim 提供共享的纯内存 POSIX 目录树、符号链接步进器与作用域读写句柄。

本包仅由 core/internal/sim 内部复用(0 生产可达),零 os/path/filepath/time.Now/nolint 依赖。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendCSVAsset

func AppendCSVAsset(spec *inventory.ImportBundleSpec, line string) error

AppendCSVAsset 解析单行 CSV 资产(alias,addr,port,user)并追加至 ImportBundleSpec。

func BuildHostTrustCheck

func BuildHostTrustCheck(req ports.HostTrustRequest, known []ports.PublicKeyInfo, revoked bool) (ports.HostTrustCheck, error)

BuildHostTrustCheck 按 Endpoint 信任列表与吊销表构造确定性 HostTrustCheck 结论。

func BuildRemoteStat

func BuildRemoteStat(p pathalg.RemotePath, n *Node) (out ports.RemoteFileStat, err error)

BuildRemoteStat 将内存树节点投影为携带 (dev=1, ino) 锚点的不可变 ports.RemoteFileStat。

func DigestAuditEntries

func DigestAuditEntries(entries []ports.AuditEntry) (sum [sha256.Size]byte, err error)

DigestAuditEntries 计算规范 JSONL 序列的确定性 SHA-256 摘要。

func FillXoshiro256Bytes

func FillXoshiro256Bytes(s *[4]uint64, p []byte)

FillXoshiro256Bytes 使用 xoshiro256++ 确定性填充字节切片(长度 >= 16 时保证非全零)。

func FirstErr

func FirstErr(errs ...error) error

FirstErr 返回首个非 nil 错误。

func GrowBytes

func GrowBytes(buf []byte, size int64) []byte

GrowBytes 确保字节切片长度至少为 size,不足时零值扩容返回新切片。

func NextXoshiro256

func NextXoshiro256(s *[4]uint64) uint64

NextXoshiro256 推进一次 xoshiro256++ 状态并返回下一个 64 位伪随机数。

func NormPath

func NormPath(p string) string

NormPath 将相对或绝对路径规范化为带前导 "/" 的 POSIX 树键。

func OpenSimForwardChannel

func OpenSimForwardChannel(ctx context.Context, transport ports.TunnelTransport, spec ports.ForwardSpec) (string, io.Closer, error)

OpenSimForwardChannel 按 ForwardSpec 方向与显式端点类型(TCP/Unix)演练 TunnelTransport, 同时覆盖本地 StreamLocal 拨号(DialStreamLocal)与远端 StreamLocal 监听(ListenStreamLocal)。

func ParseCSVImportBundle

func ParseCSVImportBundle(format string, raw []byte) (out inventory.ImportBundle, err error)

ParseCSVImportBundle 解析整段 CSV 资产文本(跳过空行与 # 注释)并构造不可变 ImportBundle。

func PreferredAlgosFromKeys

func PreferredAlgosFromKeys(known []ports.PublicKeyInfo) (out []string)

PreferredAlgosFromKeys 从端点已信任公钥切片提取去重且保序的偏好密钥算法列表。

func RelayTerminalStreams

func RelayTerminalStreams(
	ctx context.Context,
	localIn io.Reader,
	localOut io.Writer,
	remoteIn io.Writer,
	remoteOut io.Reader,
	resizeCh <-chan ports.TerminalSize,
	onResize func(ctx context.Context, size ports.TerminalSize) error,
	onRemoteDone func(),
) error

RelayTerminalStreams 在 core/conc.RunWait 监督下并发执行终端输入、远端输出与窗口缩放中继(零裸 go、零泄漏):

  • localIn 遇 io.EOF 时若 remoteIn 实现 io.Closer 则半关闭以传递通道 EOF,同时继续排空 remoteOut;
  • remoteOut 遇 io.EOF(远端退出)时关闭 remoteDone 并调用 onRemoteDone 立即唤醒阻塞的 localIn 与缩放泵。

func ResolveSimTier4

ResolveSimTier4 按原始别名与可选规范化端点折叠匹配虚拟主机的 Tier-4 选项层。

func RunServeWait

func RunServeWait(ctx context.Context, stopCh <-chan struct{}) error

RunServeWait 阻塞等待控制面停止信号或 ctx 取消(stopCh 为 nil 表示在 Serve 附着前已停止)。

func SeedXoshiro256

func SeedXoshiro256(seed uint64) (st [4]uint64)

SeedXoshiro256 使用 SplitMix64 从 64 位种子展开跨平台一致的非零 xoshiro256++ 状态向量。

func SignSimKey

func SignSimKey(prefix string, key inventory.KeyFingerprint, algorithm string, data []byte) (ports.Signature, error)

SignSimKey 对仿真密钥指纹、算法与载荷计算确定性 SHA-256 签名(零真实私钥材料)。

Types

type Addr

type Addr string

Addr 表示纯内存虚拟网络地址。

func (Addr) Network

func (a Addr) Network() string

func (Addr) String

func (a Addr) String() string

type AuditLedger

type AuditLedger struct {
	Entries []ports.AuditEntry
	Locks   map[ports.ProcessInstanceID]*ProcLock
}

AuditLedger 封装 SimAuditCluster 的纯内存审计条目、进程锁状态与崩溃对账算法(ADR-008)。 全部方法要求调用方持有外层互斥锁。

func NewAuditLedger

func NewAuditLedger() *AuditLedger

NewAuditLedger 创建空白审计账本。

func (*AuditLedger) AcquireLockLocked

func (l *AuditLedger) AcquireLockLocked(procID ports.ProcessInstanceID) error

AcquireLockLocked 为 procID 登记活跃进程锁,已被活跃进程占用时返回 ports.ErrLockBusy。

func (*AuditLedger) MutateLockLocked

func (l *AuditLedger) MutateLockLocked(lk *ProcLock, opID security.OperationID, stage bool) bool

MutateLockLocked 登记或注销活跃操作,并在活跃集合由非空归零时返回 true(触发截断计数)。

func (*AuditLedger) ReconcileLocked

func (l *AuditLedger) ReconcileLocked(now time.Time, enospc bool, enospcErr error, onLogScan func()) (out ports.CrashReconcileReport, err error)

ReconcileLocked 执行 O(1) 崩溃对账;无死亡锁时零扫描,存在死亡未闭合操作时通过 onLogScan 计数并补写 AbortedByCrash。

func (*AuditLedger) TerminateLockLocked

func (l *AuditLedger) TerminateLockLocked(procID ports.ProcessInstanceID, closed, crash bool)

TerminateLockLocked 标记进程锁为非活跃;仅当非崩溃且活跃未闭合集合为空时才删除锁记录。 若存在未闭合操作(如 Halted 熔断后关闭),保留锁记录供启动期 ReconcileCrashedAudits 补写 AbortedByCrash。

type BlockingTUNConn added in v1.1.0

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

BlockingTUNConn 是基于零协程 StreamPipe 封装的纯内存阻塞 TUN/TAP 双向连接(完整兼容 net.Conn): Read 在缓冲为空且未关闭时阻塞等待写入或 Close() 才返回 (0, io.EOF),消除非阻塞 EchoConn 空读秒返 EOF 的竞态; Write 在连接打开时接受写入并在已关闭后返回 ports.ErrClosed;Close 幂等且唤醒全部阻塞读者。

func NewBlockingTUNConn added in v1.1.0

func NewBlockingTUNConn(label string) *BlockingTUNConn

NewBlockingTUNConn 构造绑定虚拟标签地址的纯内存阻塞 TUN 连接。

func (*BlockingTUNConn) Close added in v1.1.0

func (c *BlockingTUNConn) Close() error

func (*BlockingTUNConn) LocalAddr added in v1.1.0

func (c *BlockingTUNConn) LocalAddr() net.Addr

func (*BlockingTUNConn) Read added in v1.1.0

func (c *BlockingTUNConn) Read(p []byte) (int, error)

func (*BlockingTUNConn) RemoteAddr added in v1.1.0

func (c *BlockingTUNConn) RemoteAddr() net.Addr

func (*BlockingTUNConn) SetDeadline added in v1.1.0

func (c *BlockingTUNConn) SetDeadline(time.Time) error

func (*BlockingTUNConn) SetReadDeadline added in v1.1.0

func (c *BlockingTUNConn) SetReadDeadline(time.Time) error

func (*BlockingTUNConn) SetWriteDeadline added in v1.1.0

func (c *BlockingTUNConn) SetWriteDeadline(time.Time) error

func (*BlockingTUNConn) Write added in v1.1.0

func (c *BlockingTUNConn) Write(p []byte) (int, error)

type ClockCore

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

ClockCore 封装 100% 确定性并发安全虚拟时钟与定时器队列内核,供 core/internal/sim.SimClock 复用。

func NewClockCore

func NewClockCore(start time.Time) *ClockCore

NewClockCore 构造从 start 起步的确定性虚拟时钟内核。

func (*ClockCore) Advance

func (c *ClockCore) Advance(d time.Duration)

func (*ClockCore) AdvanceToNext

func (c *ClockCore) AdvanceToNext() (delta time.Duration, ok bool)

func (*ClockCore) NewTimer

func (c *ClockCore) NewTimer(d time.Duration) ports.Timer

func (*ClockCore) Now

func (c *ClockCore) Now() time.Time

Now / Since / PendingTimers / Advance / AdvanceToNext / NewTimer / Sleep / WaitPending 驱动虚拟时钟(nil 接收者安全失败关闭)。

func (*ClockCore) PendingTimers

func (c *ClockCore) PendingTimers() int

func (*ClockCore) Since

func (c *ClockCore) Since(t time.Time) time.Duration

func (*ClockCore) Sleep

func (c *ClockCore) Sleep(ctx context.Context, d time.Duration) error

func (*ClockCore) WaitPending

func (c *ClockCore) WaitPending(ctx context.Context, n int) error

type ClockTimer

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

ClockTimer 实现 ports.Timer,由 ClockCore 调度触发。

func (*ClockTimer) C

func (t *ClockTimer) C() <-chan time.Time

func (*ClockTimer) Reset

func (t *ClockTimer) Reset(d time.Duration) bool

func (*ClockTimer) Stop

func (t *ClockTimer) Stop() bool

type DirItem

type DirItem struct {
	Name string
	Node *Node
}

DirItem 表示按名称排序的目录枚举项。

type EchoConn

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

EchoConn 实现纯内存双向回显 net.Conn 与 io.ReadWriteCloser。

func NewEchoConn

func NewEchoConn(addr string) *EchoConn

NewEchoConn 构造绑定虚拟地址的纯内存回显连接。

func (*EchoConn) Close

func (c *EchoConn) Close() error

func (*EchoConn) LocalAddr

func (c *EchoConn) LocalAddr() net.Addr

func (*EchoConn) Read

func (c *EchoConn) Read(p []byte) (int, error)

func (*EchoConn) RemoteAddr

func (c *EchoConn) RemoteAddr() net.Addr

func (*EchoConn) SetDeadline

func (c *EchoConn) SetDeadline(time.Time) error

func (*EchoConn) SetReadDeadline

func (c *EchoConn) SetReadDeadline(time.Time) error

func (*EchoConn) SetWriteDeadline

func (c *EchoConn) SetWriteDeadline(time.Time) error

func (*EchoConn) Write

func (c *EchoConn) Write(p []byte) (int, error)

type EnvPort

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

EnvPort 实现 ports.EnvPort 的纯内存环境变量与本机身份元信息仿真器(零 os.Getenv)。

func NewEnvPort

func NewEnvPort(notInitErr error, env map[string]string, id ports.LocalIdentityInfo) *EnvPort

NewEnvPort 创建预置环境变量快照与可选本机身份信息的仿真环境端口。

func (*EnvPort) Environ

func (e *EnvPort) Environ() map[string]string

func (*EnvPort) Faults

func (b *EnvPort) Faults() *FaultInjector

func (*EnvPort) LookupEnv

func (e *EnvPort) LookupEnv(key string) (val string, ok bool)

func (*EnvPort) LookupLocalIdentity

func (e *EnvPort) LookupLocalIdentity() (out ports.LocalIdentityInfo, err error)

func (*EnvPort) SetEnv

func (e *EnvPort) SetEnv(key, val string)

func (*EnvPort) SetIdentity

func (e *EnvPort) SetIdentity(id ports.LocalIdentityInfo)

type FaultInjector

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

FaultInjector 是面向全部仿真端口的并发安全确定性故障注入器(常驻/单次/概率/自定义钩子)。

func NewFaultInjector

func NewFaultInjector(chanceFn func(num, den int) bool) *FaultInjector

NewFaultInjector 构造确定性故障注入器(chanceFn 仅在使用 SetRate 时需要,可为 nil)。

func (*FaultInjector) Check

func (f *FaultInjector) Check(op string) error

func (*FaultInjector) Clear

func (f *FaultInjector) Clear(op string)

func (*FaultInjector) ClearAll

func (f *FaultInjector) ClearAll()

func (*FaultInjector) Count

func (f *FaultInjector) Count(op string) (n uint64)

func (*FaultInjector) InjectOnce

func (f *FaultInjector) InjectOnce(op string, err error)

func (*FaultInjector) SetHook

func (f *FaultInjector) SetHook(op string, fn func(call uint64) error)

SetHook / SetSticky / InjectOnce / SetRate / Clear / ClearAll / Count / Check 管理与评估故障规则。

func (*FaultInjector) SetRate

func (f *FaultInjector) SetRate(op string, num, den int, err error)

func (*FaultInjector) SetSticky

func (f *FaultInjector) SetSticky(op string, err error)

type FileLock

type FileLock struct {
	Shared    int
	Exclusive bool
	Changed   chan struct{}
}

FileLock 记录纯内存句柄级共享/独占锁状态及等待唤醒通道。

type ForwardHandle

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

ForwardHandle 实现 ports.ForwardHandle 与 pool.ManagedResource,持留池钉选的 TunnelTransport 直至 Close。

func NewForwardHandle

func NewForwardHandle(spec ports.ForwardSpec, boundAddr string, transport ports.TunnelTransport, closer io.Closer) *ForwardHandle

NewForwardHandle 构造已启动的纯内存转发句柄并托管底层资源关闭。

func (*ForwardHandle) BoundAddr

func (h *ForwardHandle) BoundAddr() string

func (*ForwardHandle) Close

func (h *ForwardHandle) Close() error

Close 幂等关闭底层监听/隧道连接并广播 Done 通道。

func (*ForwardHandle) Done

func (h *ForwardHandle) Done() <-chan struct{}

func (*ForwardHandle) Err

func (h *ForwardHandle) Err() error

func (*ForwardHandle) IsValid

func (h *ForwardHandle) IsValid() bool

func (*ForwardHandle) OpenChannel

func (h *ForwardHandle) OpenChannel(ctx context.Context) error

OpenChannel 在 StartForward 返回后通过持留的 transport 再次打开并关闭一条数据通道,验证长生命周期非借用传输契约。

func (*ForwardHandle) Spec

func (h *ForwardHandle) Spec() ports.ForwardSpec

type JournalMap

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

JournalMap 封装按 (TransferID, Generation) 分代存储的纯内存 WAL 引擎, 支持确定性 (Generation, Seq) 排序加载、单代损坏隔离快照与按代清理(ADR-016)。

func NewJournalMap

func NewJournalMap() *JournalMap

NewJournalMap 创建空白双代传输日志映射。

func (*JournalMap) AppendLocked

func (m *JournalMap) AppendLocked(rec fsm.TransferJournalRecord)

AppendLocked 按 (TransferID, Generation) 追加单条有效记录。

func (*JournalMap) CorruptGenerationLocked

func (m *JournalMap) CorruptGenerationLocked(id security.OperationID, generation uint64, cause error)

CorruptGenerationLocked 将指定 (transferID, generation) 标记为损坏态以支持单侧损坏隔离测试。

func (*JournalMap) DeleteLocked

func (m *JournalMap) DeleteLocked(id security.OperationID) error

DeleteLocked 删除指定传输的全部世代日志;不存在返回 ports.ErrNotFound。

func (*JournalMap) ListActiveLocked

func (m *JournalMap) ListActiveLocked() []security.OperationID

ListActiveLocked 返回按字典序排序的全部活跃传输 ID。

func (*JournalMap) LoadGenerationsLocked

func (m *JournalMap) LoadGenerationsLocked(id security.OperationID) ([]ports.JournalGenerationSnapshot, error)

LoadGenerationsLocked 按 Generation 升序返回逐代隔离快照(单侧损坏不影响其他健康世代读取)。

func (*JournalMap) LoadLocked

LoadLocked 按 (Generation 升序, Seq 升序) 合并返回全部记录;任一世代损坏时返回 ErrCorruptData。

func (*JournalMap) PruneGenerationLocked

func (m *JournalMap) PruneGenerationLocked(id security.OperationID, generation uint64) error

PruneGenerationLocked 移除指定 (transferID, generation);若该传输无剩余世代则一并移出活跃集。

type LockedFile

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

LockedFile 实现 ports.LockedFile,带运行时失效哨兵、共享/独占写保护与可选写故障检查。

func NewLockedFile

func NewLockedFile(tree *Tree, abs string, writable bool, checkWrite func() error) *LockedFile

NewLockedFile 构造绑定至树节点 abs 的持锁文件句柄。

func (*LockedFile) Expire

func (lf *LockedFile) Expire()

Expire 置位失效哨兵,阻断回调退出后的任何逃逸访问。

func (*LockedFile) Read

func (lf *LockedFile) Read(p []byte) (n int, err error)

func (*LockedFile) Seek

func (lf *LockedFile) Seek(offset int64, whence int) (next int64, err error)

func (*LockedFile) Stat

func (lf *LockedFile) Stat() (out ports.LocalFileInfo, err error)

func (*LockedFile) Sync

func (lf *LockedFile) Sync() error

func (*LockedFile) Truncate

func (lf *LockedFile) Truncate(size int64) error

func (*LockedFile) Write

func (lf *LockedFile) Write(p []byte) (n int, err error)

type MemListener

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

MemListener 实现带可选失效哨兵的纯内存 net.Listener。

func NewMemListener

func NewMemListener(addr string, expired *atomic.Bool) *MemListener

NewMemListener 构造纯内存 net.Listener(expired 非 nil 时作为借用作用域失效哨兵)。

func (*MemListener) Accept

func (l *MemListener) Accept() (net.Conn, error)

func (*MemListener) Addr

func (l *MemListener) Addr() net.Addr

func (*MemListener) Close

func (l *MemListener) Close() error

type MuxMasterEntry

type MuxMasterEntry struct {
	PID    uint32
	StopCh chan struct{}

	Upstream  ports.TransportConn
	Forwarder ports.ForwarderPort
	ServeOpts ports.MuxServeOptions
	Forwards  map[string]ports.ForwardHandle
	// contains filtered or unexported fields
}

MuxMasterEntry 记录纯内存 ControlMaster 仿真槽位的进程 PID、退出信号、单实例服务选项与可选服务端状态。

func (*MuxMasterEntry) CloseForwards

func (e *MuxMasterEntry) CloseForwards()

CloseForwards 关闭并清空本主进程托管的全部动态端口转发句柄。

func (*MuxMasterEntry) SignalStop

func (e *MuxMasterEntry) SignalStop()

SignalStop 幂等关闭 StopCh 以唤醒阻塞中的 Serve 循环。

type MuxRegistry

type MuxRegistry struct {
	Masters map[string]*MuxMasterEntry
}

MuxRegistry 封装 SimMuxSocket 的纯内存主进程注册表与 PROTOCOL.mux v4 控制动作分发(无外部锁)。

func NewMuxRegistry

func NewMuxRegistry() *MuxRegistry

NewMuxRegistry 创建空白多路复用注册表。

func (*MuxRegistry) AcquireListenLocked

func (r *MuxRegistry) AcquireListenLocked(addr string, pid uint32) bool

AcquireListenLocked 抢占监听槽位;已占用返回 false。

func (*MuxRegistry) ApplyControlLocked

func (r *MuxRegistry) ApplyControlLocked(req ports.MuxControlRequest) (pid uint32, up ports.TransportConn, fwd ports.ForwarderPort, cancelHandle ports.ForwardHandle, ok bool)

ApplyControlLocked 在锁内处理 Control 请求并在必要时提取转发执行所需的非持锁回调上下文。

func (*MuxRegistry) AttachServerLocked

func (r *MuxRegistry) AttachServerLocked(addr string, upstream ports.TransportConn, forwarder ports.ForwarderPort) <-chan struct{}

AttachServerLocked 为指定地址上的主进程绑定 upstream/forwarder 并使用默认 MuxServeOptions,返回退出信号通道。

func (*MuxRegistry) AttachServerWithOptionsLocked added in v1.3.0

func (r *MuxRegistry) AttachServerWithOptionsLocked(addr string, upstream ports.TransportConn, forwarder ports.ForwarderPort, opts ports.MuxServeOptions) <-chan struct{}

AttachServerWithOptionsLocked 为指定地址上的主进程绑定 upstream/forwarder 与单实例 MuxServeOptions 并返回退出信号通道。

func (*MuxRegistry) DetachServerLocked

func (r *MuxRegistry) DetachServerLocked(addr string)

DetachServerLocked 清理服务端持有的转发、服务选项与绑定引用。

func (*MuxRegistry) RegisterLocked

func (r *MuxRegistry) RegisterLocked(addr string, pid uint32)

RegisterLocked 注册指定套接字路径的仿真主进程 PID。

func (*MuxRegistry) ReleaseListenLocked

func (r *MuxRegistry) ReleaseListenLocked(addr string)

ReleaseListenLocked 释放监听槽位并唤醒可能仍在运行的 Serve。

func (*MuxRegistry) StoreForwardLocked

func (r *MuxRegistry) StoreForwardLocked(addr string, spec ports.ForwardSpec, h ports.ForwardHandle) bool

StoreForwardLocked 将成功启动的动态转发句柄登记到活跃主进程(若期间已停机则返回 false 以便立即关闭)。

type Node

type Node struct {
	Kind    ports.RemoteFileType
	Mode    fs.FileMode
	Data    []byte
	Target  string
	ModTime time.Time
	Ino     uint64
}

Node 表示纯内存目录树中的单个文件、目录或符号链接节点。

type ProcLock

type ProcLock struct {
	Live   bool
	Active map[security.OperationID]bool
}

ProcLock 表示纯内存审计集群中单个进程实例的活跃锁与未闭合操作集合。

type RemoteSession

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

RemoteSession 实现 ports.RemoteSession,支持前置管道获取及与 ExecStreams 互斥校验。

func NewRemoteSession

func NewRemoteSession(aliveFn func() bool, cfg SessionFaultConfig) *RemoteSession

NewRemoteSession 构造绑定至底层连接探活回调与故障配置的纯内存远端会话。

func (*RemoteSession) BeginStartLocked

func (s *RemoteSession) BeginStartLocked(streams ports.ExecStreams) error

BeginStartLocked 在持锁复核会话未关闭、未重复启动且流管道无冲突后标记已启动(仅供包内外白盒复核)。

func (*RemoteSession) Close

func (s *RemoteSession) Close() error

func (*RemoteSession) ResizePTY

func (s *RemoteSession) ResizePTY(ctx context.Context, size ports.TerminalSize) error

func (*RemoteSession) Signal

func (s *RemoteSession) Signal(ctx context.Context, sig string) error

func (*RemoteSession) Start

func (*RemoteSession) StartShell

func (s *RemoteSession) StartShell(ctx context.Context, streams ports.ExecStreams) error

func (*RemoteSession) StderrPipe

func (s *RemoteSession) StderrPipe() (io.Reader, error)

func (*RemoteSession) StdinPipe

func (s *RemoteSession) StdinPipe() (io.WriteCloser, error)

func (*RemoteSession) StdoutPipe

func (s *RemoteSession) StdoutPipe() (io.Reader, error)

func (*RemoteSession) Wait

type SSHFPLookup

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

SSHFPLookup 实现 ports.SSHFPLookupPort 的确定性内存 DNS SSHFP 查询仿真器。

func NewSSHFPLookup

func NewSSHFPLookup(notInitErr error) *SSHFPLookup

NewSSHFPLookup 创建空白的 SSHFP 查询仿真器。

func (*SSHFPLookup) Faults

func (b *SSHFPLookup) Faults() *FaultInjector

func (*SSHFPLookup) LookupSSHFP

func (s *SSHFPLookup) LookupSSHFP(ctx context.Context, host netaddr.CanonicalHost) ([]ports.SSHFPRecord, error)

func (*SSHFPLookup) SetRecords

func (s *SSHFPLookup) SetRecords(host netaddr.CanonicalHost, recs ...ports.SSHFPRecord)

type ScopedReader

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

ScopedReader 实现 ports.BoundedReadHandle(io.Reader + io.ReaderAt),带运行时失效哨兵与字节上限守卫。

func NewScopedReader

func NewScopedReader(data []byte, maxBytes int64) (*ScopedReader, func())

NewScopedReader 构造受运行时失效哨兵保护的 *ScopedReader(同时满足 ports.BoundedReadHandle 与 io.Reader), 并返回调用方须经 defer 执行的失效函数。

func (*ScopedReader) Read

func (sr *ScopedReader) Read(p []byte) (int, error)

Read 顺序读取字节流;回调退出后立即返回 ports.ErrHandleExpired。

func (*ScopedReader) ReadAt

func (sr *ScopedReader) ReadAt(p []byte, off int64) (int, error)

ReadAt 在任意非负偏移处随机读取;回调退出后立即返回 ports.ErrHandleExpired,负偏移返回 ports.ErrInvalidArgument。

type ScopedWriter

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

ScopedWriter 为作用域写回调提供失效哨兵与可选写故障检查。

func NewScopedWriter

func NewScopedWriter(buf *bytes.Buffer, expired *atomic.Bool, checkWrite func() error) *ScopedWriter

NewScopedWriter 构造受 expired 哨兵保护的作用域写入器。

func (*ScopedWriter) Write

func (sw *ScopedWriter) Write(p []byte) (int, error)

Write 写入缓冲前检查失效哨兵与故障注入。

type SessionFaultConfig

type SessionFaultConfig struct {
	Output   string
	Outcome  execution.ExecutionOutcome
	StartErr error
	WaitErr  error
}

SessionFaultConfig 封装 RemoteSession 的仿真输出与错误注入参数。

type StreamPipe

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

StreamPipe 是零协程、并发安全、非阻塞写入且支持半关闭 EOF 唤醒的纯内存流管道(供 SimRemoteSession 复用)。

func NewStreamPipe

func NewStreamPipe() *StreamPipe

NewStreamPipe 构造打开状态的纯内存流管道。

func (*StreamPipe) Close

func (p *StreamPipe) Close() error

Close 幂等关闭写入端并广播唤醒全部阻塞读者返回 io.EOF。

func (*StreamPipe) Read

func (p *StreamPipe) Read(b []byte) (int, error)

Read 从缓冲读取字节;缓冲为空且未关闭时阻塞直至新数据到达或 Close 返回 io.EOF。

func (*StreamPipe) Write

func (p *StreamPipe) Write(b []byte) (int, error)

Write 非阻塞写入缓冲并唤醒等待读者;已关闭时返回 io.ErrClosedPipe。

type TUNDevicePort

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

TUNDevicePort 实现 ports.TUNDevicePort 的纯内存本机 TUN/TAP 虚拟网卡仿真器。

func NewTUNDevicePort

func NewTUNDevicePort(notInitErr error) *TUNDevicePort

NewTUNDevicePort 创建默认可用的纯内存本机 TUN/TAP 设备仿真器。

func (*TUNDevicePort) Faults

func (b *TUNDevicePort) Faults() *FaultInjector

func (*TUNDevicePort) OpenLocalTUN

func (t *TUNDevicePort) OpenLocalTUN(ctx context.Context, spec ports.TUNSpec) (io.ReadWriteCloser, string, error)

func (*TUNDevicePort) SetAvailable

func (t *TUNDevicePort) SetAvailable(en bool)

type TerminalHandle

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

TerminalHandle 实现 ports.TerminalHandle,封装带运行时失效哨兵的纯内存 PTY 输入/输出、缩放与双向 Relay。

func NewTerminalHandle

func NewTerminalHandle(size ports.TerminalSize, inSnap []byte, blockAfter bool, resizes []ports.TerminalSize, onWrite func([]byte)) (*TerminalHandle, func())

NewTerminalHandle 构造受失效哨兵保护的纯内存终端句柄并返回过期清理函数。

func (*TerminalHandle) Read

func (h *TerminalHandle) Read(p []byte) (int, error)

Read 从预置终端输入流读取字节;blockAfter 为 true 且耗尽后等待中继退出信号。

func (*TerminalHandle) Relay

func (h *TerminalHandle) Relay(ctx context.Context, remoteIn io.Writer, remoteOut io.Reader, onResize func(ctx context.Context, size ports.TerminalSize) error) error

Relay 在同步作用域内并发驱动终端输入、远端输出与窗口缩放回调(零裸 go、零泄漏)。

func (*TerminalHandle) ResizeEvents

func (h *TerminalHandle) ResizeEvents() <-chan ports.TerminalSize

func (*TerminalHandle) Size

func (h *TerminalHandle) Size() (out ports.TerminalSize, err error)

Size 返回当前窗口尺寸。

func (*TerminalHandle) Write

func (h *TerminalHandle) Write(p []byte) (int, error)

Write 将输出字节并发安全地递交至终端输出接收回调(ADR-019 v2.2 S3-Q4a)。

type Tree

type Tree struct {
	Mu           sync.Mutex
	StrictParent bool
	Clock        ports.Clock
	NextIno      uint64
	Nodes        map[string]*Node
	Locks        map[string]*FileLock
}

Tree 统一采用前导 "/" 规范路径封装纯内存 POSIX 目录树(本地沙箱、操作员只读与远端共用), 通过逐段符号链接步进器 WalkPathLocked 共享单一 pathalg.MaxSymlinkHops 预算。

func New

func New(clk ports.Clock, strictParent bool, rootPerm fs.FileMode) *Tree

New 创建仅含根目录 "/" 的纯内存目录树。

func (*Tree) AllocIno

func (t *Tree) AllocIno() uint64

AllocIno 分配单调递增的虚拟 inode 编号(调用方须持有 t.Mu)。

func (*Tree) CheckRegularSlotLocked

func (t *Tree) CheckRegularSlotLocked(abs string, exclusive bool) (*Node, error)

CheckRegularSlotLocked 校验 abs 的父目录与目标槽位是否满足常规文件(及可选独占)前置条件。

func (*Tree) CheckRemoteWriteTargetLocked

func (t *Tree) CheckRemoteWriteTargetLocked(rawKey string, spec ports.RemoteWriteSpec) (string, error)

CheckRemoteWriteTargetLocked 校验远端原子写入目标的父目录、NoClobber、目录冲突与期望锚点。

func (*Tree) ChmodRemoteLocked

func (t *Tree) ChmodRemoteLocked(key string, perm fs.FileMode) error

ChmodRemoteLocked 保留文件类型位并更新远端对象标准权限位与修改时间。

func (*Tree) ChtimesLocalLocked

func (t *Tree) ChtimesLocalLocked(abs string, atime, mtime time.Time) error

ChtimesLocalLocked 校验合法 RFC 3339 时间戳与无软链路径并更新沙箱常规文件或目录的修改时间。

func (*Tree) ChtimesRemoteLocked

func (t *Tree) ChtimesRemoteLocked(key string, atime, mtime time.Time) error

ChtimesRemoteLocked 校验合法 RFC 3339 时间戳并更新远端对象修改时间(支撑 scp -p)。

func (*Tree) CollectSymlinksLocked

func (t *Tree) CollectSymlinksLocked() (out []pathalg.SymlinkBinding)

CollectSymlinksLocked 收集树内全部可映射为 LocalRootedDest 的符号链接绑定,供域层闭环校验使用。

func (*Tree) CreateSymlinkLocalLocked

func (t *Tree) CreateSymlinkLocalLocked(link pathalg.LocalRootedDest, target string) error

CreateSymlinkLocalLocked 在树锁保护下按策略 (b) 校验并创建沙箱内相对符号链接。

func (*Tree) HasChildrenLocked

func (t *Tree) HasChildrenLocked(dirAbs string) bool

HasChildrenLocked 判断 dirAbs 下是否存在任意子孙节点(调用方须持有 t.Mu)。

func (*Tree) ListDirLocked

func (t *Tree) ListDirLocked(abs string, followParent, followLeaf, rejectSymlink bool) (items []DirItem, err error)

ListDirLocked 按字典序枚举指定目录直接子节点(调用方须持有 t.Mu)。

func (*Tree) ListLocalDirLocked

func (t *Tree) ListLocalDirLocked(abs string) ([]ports.LocalDirEntry, error)

ListLocalDirLocked 在树锁保护下将目录项转换为已校验 LocalDirEntry 列表。

func (*Tree) MkdirAllLocked

func (t *Tree) MkdirAllLocked(abs string, perm fs.FileMode, followParent bool) error

MkdirAllLocked 递归创建目录链,按 followParent 决定是否跟随已有中间符号链接(调用方须持有 t.Mu)。

func (*Tree) Now

func (t *Tree) Now() time.Time

Now 返回当前确定性 UTC 时间戳。

func (*Tree) OpenOrCreateRegularLocked

func (t *Tree) OpenOrCreateRegularLocked(abs string, create bool, checkWrite func() error, perm fs.FileMode) (*Node, error)

OpenOrCreateRegularLocked 打开已有常规文件或在 create==true 时新建常规文件节点。

func (*Tree) ReadPrivateRegularLocked added in v1.3.0

func (t *Tree) ReadPrivateRegularLocked(abs string, limits ports.ReadLimits) ([]byte, error)

ReadPrivateRegularLocked 在树锁保护下原子校验无软链、常规文件、仅属主权限(mode&0o077==0)与体积上限并返回数据副本。

func (*Tree) ReadRegularLocked

func (t *Tree) ReadRegularLocked(abs string, followParent, followLeaf, rejectSymlink bool, limits ports.ReadLimits, dirErr error) ([]byte, error)

ReadRegularLocked 校验目标为常规文件且未超出 limits 上限后返回数据副本(调用方须持有 t.Mu)。

func (*Tree) ReadRemoteChunkLocked

func (t *Tree) ReadRemoteChunkLocked(key string, offset, length int64) ([]byte, bool, error)

ReadRemoteChunkLocked 在持有 t.Mu 下读取远端常规文件 [offset, offset+length) 区间副本与 EOF 标记。

func (*Tree) ReleaseLock

func (t *Tree) ReleaseLock(abs string, mode ports.LockMode)

ReleaseLock 释放 abs 上的指定模式文件锁并广播唤醒等待者。

func (*Tree) RelocateSubtreeLocked

func (t *Tree) RelocateSubtreeLocked(oldKey, newKey string, src *Node)

RelocateSubtreeLocked 将 oldKey(及其目录子树)原子迁移至 newKey(调用方须持有 t.Mu 且已完成前置校验)。

func (*Tree) RemoveLocked

func (t *Tree) RemoveLocked(abs string, followParent, rejectSymlink bool) error

RemoveLocked 删除文件、符号链接或空目录(拒绝删除根目录与非空目录,调用方须持有 t.Mu)。

func (*Tree) RemoveRemoteDirLocked

func (t *Tree) RemoveRemoteDirLocked(abs string) error

RemoveRemoteDirLocked 仅删除远端空目录(SFTP SSH_FXP_RMDIR);非目录或非空目录返回 ports.ErrInvalidArgument。

func (*Tree) RemoveRemoteFileLocked

func (t *Tree) RemoveRemoteFileLocked(abs string) error

RemoveRemoteFileLocked 仅删除远端常规文件或符号链接;若目标为目录则返回 ports.ErrRemoteIsDir。

func (*Tree) RenameLocalLocked

func (t *Tree) RenameLocalLocked(oldAbs, newAbs string) error

RenameLocalLocked 在沙箱根内校验非符号链接与类型兼容性并原子重命名 oldAbs -> newAbs。

func (*Tree) RenameRemoteLocked

func (t *Tree) RenameRemoteLocked(rawOld, rawNew string, spec ports.RemoteRenameSpec) error

RenameRemoteLocked 执行远端 POSIX 原子重命名(支持 RemoteRenameSpec 的互斥 NoClobber/ExpectedAnchor 校验与目录子树迁移)。

func (*Tree) ResolveParentLocked

func (t *Tree) ResolveParentLocked(abs string, followParent, rejectSymlink bool) (string, error)

ResolveParentLocked 解析 abs 的父目录并拼接末段基名返回目标树键(调用方须持有 t.Mu)。

func (*Tree) TryAcquireLock

func (t *Tree) TryAcquireLock(abs string, mode ports.LockMode, create bool, perm fs.FileMode, checkWrite func() error) (bool, <-chan struct{}, error)

TryAcquireLock 尝试对 abs 加共享或独占锁;冲突时返回等待唤醒通道。

func (*Tree) VerifyAnchorLocked

func (t *Tree) VerifyAnchorLocked(key string, expected ports.RemoteFileAnchor) error

VerifyAnchorLocked 核验远端树节点与期望 (type, dev, ino) 锚点是否一致。

func (*Tree) WalkPathLocked

func (t *Tree) WalkPathLocked(abs string, followParent, followLeaf, rejectSymlink bool) (string, *Node, error)

WalkPathLocked 逐段解析 abs,在中间目录段与末段共享 MaxSymlinkHops 软链跳数上限(调用方须持有 t.Mu)。

func (*Tree) WriteChunkLocalLocked

func (t *Tree) WriteChunkLocalLocked(abs string, offset int64, chunk []byte, perm fs.FileMode) error

WriteChunkLocalLocked 在树锁保护下向常规暂存文件写入分片数据。

func (*Tree) WriteRemoteChunkLocked

func (t *Tree) WriteRemoteChunkLocked(rawKey string, offset int64, chunk []byte) error

WriteRemoteChunkLocked 向远端常规文件 offset 处非截断写入分片数据。

Jump to

Keyboard shortcuts

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