Documentation
¶
Overview ¶
Package memtree 为 core/internal/sim 提供共享的纯内存 POSIX 目录树、符号链接步进器与作用域读写句柄。
本包仅由 core/internal/sim 内部复用(0 生产可达),零 os/path/filepath/time.Now/nolint 依赖。
Index ¶
- func AppendCSVAsset(spec *inventory.ImportBundleSpec, line string) error
- func BuildHostTrustCheck(req ports.HostTrustRequest, known []ports.PublicKeyInfo, revoked bool) (ports.HostTrustCheck, error)
- func BuildRemoteStat(p pathalg.RemotePath, n *Node) (out ports.RemoteFileStat, err error)
- func DigestAuditEntries(entries []ports.AuditEntry) (sum [sha256.Size]byte, err error)
- func FillXoshiro256Bytes(s *[4]uint64, p []byte)
- func FirstErr(errs ...error) error
- func GrowBytes(buf []byte, size int64) []byte
- func NextXoshiro256(s *[4]uint64) uint64
- func NormPath(p string) string
- func OpenSimForwardChannel(ctx context.Context, transport ports.TunnelTransport, spec ports.ForwardSpec) (string, io.Closer, error)
- func ParseCSVImportBundle(format string, raw []byte) (out inventory.ImportBundle, err error)
- func PreferredAlgosFromKeys(known []ports.PublicKeyInfo) (out []string)
- func RelayTerminalStreams(ctx context.Context, localIn io.Reader, localOut io.Writer, remoteIn io.Writer, ...) error
- func ResolveSimTier4(hosts []ports.OpenSSHVirtualHost, target option.OriginalHostSpec, ...) option.OptionLayer
- func RunServeWait(ctx context.Context, stopCh <-chan struct{}) error
- func SeedXoshiro256(seed uint64) (st [4]uint64)
- func SignSimKey(prefix string, key inventory.KeyFingerprint, algorithm string, data []byte) (ports.Signature, error)
- type Addr
- type AuditLedger
- func (l *AuditLedger) AcquireLockLocked(procID ports.ProcessInstanceID) error
- func (l *AuditLedger) MutateLockLocked(lk *ProcLock, opID security.OperationID, stage bool) bool
- func (l *AuditLedger) ReconcileLocked(now time.Time, enospc bool, enospcErr error, onLogScan func()) (out ports.CrashReconcileReport, err error)
- func (l *AuditLedger) TerminateLockLocked(procID ports.ProcessInstanceID, closed, crash bool)
- type ClockCore
- func (c *ClockCore) Advance(d time.Duration)
- func (c *ClockCore) AdvanceToNext() (delta time.Duration, ok bool)
- func (c *ClockCore) NewTimer(d time.Duration) ports.Timer
- func (c *ClockCore) Now() time.Time
- func (c *ClockCore) PendingTimers() int
- func (c *ClockCore) Since(t time.Time) time.Duration
- func (c *ClockCore) Sleep(ctx context.Context, d time.Duration) error
- func (c *ClockCore) WaitPending(ctx context.Context, n int) error
- type ClockTimer
- type DirItem
- type EchoConn
- func (c *EchoConn) Close() error
- func (c *EchoConn) LocalAddr() net.Addr
- func (c *EchoConn) Read(p []byte) (int, error)
- func (c *EchoConn) RemoteAddr() net.Addr
- func (c *EchoConn) SetDeadline(time.Time) error
- func (c *EchoConn) SetReadDeadline(time.Time) error
- func (c *EchoConn) SetWriteDeadline(time.Time) error
- func (c *EchoConn) Write(p []byte) (int, error)
- type EnvPort
- func (e *EnvPort) Environ() map[string]string
- func (b *EnvPort) Faults() *FaultInjector
- func (e *EnvPort) LookupEnv(key string) (val string, ok bool)
- func (e *EnvPort) LookupLocalIdentity() (out ports.LocalIdentityInfo, err error)
- func (e *EnvPort) SetEnv(key, val string)
- func (e *EnvPort) SetIdentity(id ports.LocalIdentityInfo)
- type FaultInjector
- func (f *FaultInjector) Check(op string) error
- func (f *FaultInjector) Clear(op string)
- func (f *FaultInjector) ClearAll()
- func (f *FaultInjector) Count(op string) (n uint64)
- func (f *FaultInjector) InjectOnce(op string, err error)
- func (f *FaultInjector) SetHook(op string, fn func(call uint64) error)
- func (f *FaultInjector) SetRate(op string, num, den int, err error)
- func (f *FaultInjector) SetSticky(op string, err error)
- type FileLock
- type ForwardHandle
- func (h *ForwardHandle) BoundAddr() string
- func (h *ForwardHandle) Close() error
- func (h *ForwardHandle) Done() <-chan struct{}
- func (h *ForwardHandle) Err() error
- func (h *ForwardHandle) IsValid() bool
- func (h *ForwardHandle) OpenChannel(ctx context.Context) error
- func (h *ForwardHandle) Spec() ports.ForwardSpec
- type JournalMap
- func (m *JournalMap) AppendLocked(rec fsm.TransferJournalRecord)
- func (m *JournalMap) CorruptGenerationLocked(id security.OperationID, generation uint64, cause error)
- func (m *JournalMap) DeleteLocked(id security.OperationID) error
- func (m *JournalMap) ListActiveLocked() []security.OperationID
- func (m *JournalMap) LoadGenerationsLocked(id security.OperationID) ([]ports.JournalGenerationSnapshot, error)
- func (m *JournalMap) LoadLocked(id security.OperationID) ([]fsm.TransferJournalRecord, error)
- func (m *JournalMap) PruneGenerationLocked(id security.OperationID, generation uint64) error
- type LockedFile
- func (lf *LockedFile) Expire()
- func (lf *LockedFile) Read(p []byte) (n int, err error)
- func (lf *LockedFile) Seek(offset int64, whence int) (next int64, err error)
- func (lf *LockedFile) Stat() (out ports.LocalFileInfo, err error)
- func (lf *LockedFile) Sync() error
- func (lf *LockedFile) Truncate(size int64) error
- func (lf *LockedFile) Write(p []byte) (n int, err error)
- type MemListener
- type MuxMasterEntry
- type MuxRegistry
- func (r *MuxRegistry) AcquireListenLocked(addr string, pid uint32) bool
- func (r *MuxRegistry) ApplyControlLocked(req ports.MuxControlRequest) (pid uint32, up ports.TransportConn, fwd ports.ForwarderPort, ...)
- func (r *MuxRegistry) AttachServerLocked(addr string, upstream ports.TransportConn, forwarder ports.ForwarderPort) <-chan struct{}
- func (r *MuxRegistry) DetachServerLocked(addr string)
- func (r *MuxRegistry) RegisterLocked(addr string, pid uint32)
- func (r *MuxRegistry) ReleaseListenLocked(addr string)
- func (r *MuxRegistry) StoreForwardLocked(addr string, spec ports.ForwardSpec, h ports.ForwardHandle) bool
- type Node
- type ProcLock
- type RemoteSession
- func (s *RemoteSession) BeginStartLocked(streams ports.ExecStreams) error
- func (s *RemoteSession) Close() error
- func (s *RemoteSession) ResizePTY(ctx context.Context, size ports.TerminalSize) error
- func (s *RemoteSession) Signal(ctx context.Context, sig string) error
- func (s *RemoteSession) Start(ctx context.Context, cmd execution.CommandPlan, streams ports.ExecStreams) error
- func (s *RemoteSession) StartShell(ctx context.Context, streams ports.ExecStreams) error
- func (s *RemoteSession) StderrPipe() (io.Reader, error)
- func (s *RemoteSession) StdinPipe() (io.WriteCloser, error)
- func (s *RemoteSession) StdoutPipe() (io.Reader, error)
- func (s *RemoteSession) Wait(ctx context.Context) (execution.ExecutionOutcome, error)
- type SSHFPLookup
- type ScopedReader
- type ScopedWriter
- type SessionFaultConfig
- type StreamPipe
- type TUNDevicePort
- type TerminalHandle
- func (h *TerminalHandle) Read(p []byte) (int, error)
- func (h *TerminalHandle) Relay(ctx context.Context, remoteIn io.Writer, remoteOut io.Reader, ...) error
- func (h *TerminalHandle) ResizeEvents() <-chan ports.TerminalSize
- func (h *TerminalHandle) Size() (out ports.TerminalSize, err error)
- func (h *TerminalHandle) Write(p []byte) (int, error)
- type Tree
- func (t *Tree) AllocIno() uint64
- func (t *Tree) CheckRegularSlotLocked(abs string, exclusive bool) (*Node, error)
- func (t *Tree) CheckRemoteWriteTargetLocked(rawKey string, spec ports.RemoteWriteSpec) (string, error)
- func (t *Tree) ChmodRemoteLocked(key string, perm fs.FileMode) error
- func (t *Tree) ChtimesLocalLocked(abs string, atime, mtime time.Time) error
- func (t *Tree) ChtimesRemoteLocked(key string, atime, mtime time.Time) error
- func (t *Tree) CollectSymlinksLocked() (out []pathalg.SymlinkBinding)
- func (t *Tree) CreateSymlinkLocalLocked(link pathalg.LocalRootedDest, target string) error
- func (t *Tree) HasChildrenLocked(dirAbs string) bool
- func (t *Tree) ListDirLocked(abs string, followParent, followLeaf, rejectSymlink bool) (items []DirItem, err error)
- func (t *Tree) ListLocalDirLocked(abs string) ([]ports.LocalDirEntry, error)
- func (t *Tree) MkdirAllLocked(abs string, perm fs.FileMode, followParent bool) error
- func (t *Tree) Now() time.Time
- func (t *Tree) OpenOrCreateRegularLocked(abs string, create bool, checkWrite func() error, perm fs.FileMode) (*Node, error)
- func (t *Tree) ReadRegularLocked(abs string, followParent, followLeaf, rejectSymlink bool, ...) ([]byte, error)
- func (t *Tree) ReadRemoteChunkLocked(key string, offset, length int64) ([]byte, bool, error)
- func (t *Tree) ReleaseLock(abs string, mode ports.LockMode)
- func (t *Tree) RelocateSubtreeLocked(oldKey, newKey string, src *Node)
- func (t *Tree) RemoveLocked(abs string, followParent, rejectSymlink bool) error
- func (t *Tree) RemoveRemoteDirLocked(abs string) error
- func (t *Tree) RemoveRemoteFileLocked(abs string) error
- func (t *Tree) RenameLocalLocked(oldAbs, newAbs string) error
- func (t *Tree) RenameRemoteLocked(rawOld, rawNew string, spec ports.RemoteRenameSpec) error
- func (t *Tree) ResolveParentLocked(abs string, followParent, rejectSymlink bool) (string, error)
- func (t *Tree) TryAcquireLock(abs string, mode ports.LockMode, create bool, perm fs.FileMode, ...) (bool, <-chan struct{}, error)
- func (t *Tree) VerifyAnchorLocked(key string, expected ports.RemoteFileAnchor) error
- func (t *Tree) WalkPathLocked(abs string, followParent, followLeaf, rejectSymlink bool) (string, *Node, error)
- func (t *Tree) WriteChunkLocalLocked(abs string, offset int64, chunk []byte, perm fs.FileMode) error
- func (t *Tree) WriteRemoteChunkLocked(rawKey string, offset int64, chunk []byte) error
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 ¶
DigestAuditEntries 计算规范 JSONL 序列的确定性 SHA-256 摘要。
func FillXoshiro256Bytes ¶
FillXoshiro256Bytes 使用 xoshiro256++ 确定性填充字节切片(长度 >= 16 时保证非全零)。
func NextXoshiro256 ¶
NextXoshiro256 推进一次 xoshiro256++ 状态并返回下一个 64 位伪随机数。
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 ¶
func ResolveSimTier4(hosts []ports.OpenSSHVirtualHost, target option.OriginalHostSpec, endpoint algebraic.Option[netaddr.Endpoint]) option.OptionLayer
ResolveSimTier4 按原始别名与可选规范化端点折叠匹配虚拟主机的 Tier-4 选项层。
func RunServeWait ¶
RunServeWait 阻塞等待控制面停止信号或 ctx 取消(stopCh 为 nil 表示在 Serve 附着前已停止)。
func SeedXoshiro256 ¶
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 AuditLedger ¶
type AuditLedger struct {
Entries []ports.AuditEntry
Locks map[ports.ProcessInstanceID]*ProcLock
}
AuditLedger 封装 SimAuditCluster 的纯内存审计条目、进程锁状态与崩溃对账算法(ADR-008)。 全部方法要求调用方持有外层互斥锁。
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 ClockCore ¶
type ClockCore struct {
// contains filtered or unexported fields
}
ClockCore 封装 100% 确定性并发安全虚拟时钟与定时器队列内核,供 core/internal/sim.SimClock 复用。
func NewClockCore ¶
NewClockCore 构造从 start 起步的确定性虚拟时钟内核。
func (*ClockCore) AdvanceToNext ¶
func (*ClockCore) Now ¶
Now / Since / PendingTimers / Advance / AdvanceToNext / NewTimer / Sleep / WaitPending 驱动虚拟时钟(nil 接收者安全失败关闭)。
func (*ClockCore) PendingTimers ¶
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) Stop ¶
func (t *ClockTimer) Stop() bool
type EchoConn ¶
type EchoConn struct {
// contains filtered or unexported fields
}
EchoConn 实现纯内存双向回显 net.Conn 与 io.ReadWriteCloser。
func (*EchoConn) RemoteAddr ¶
type EnvPort ¶
type EnvPort struct {
// contains filtered or unexported fields
}
EnvPort 实现 ports.EnvPort 的纯内存环境变量与本机身份元信息仿真器(零 os.Getenv)。
func NewEnvPort ¶
NewEnvPort 创建预置环境变量快照与可选本机身份信息的仿真环境端口。
func (*EnvPort) Faults ¶
func (b *EnvPort) Faults() *FaultInjector
func (*EnvPort) LookupLocalIdentity ¶
func (e *EnvPort) LookupLocalIdentity() (out ports.LocalIdentityInfo, err error)
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) SetSticky ¶
func (f *FaultInjector) SetSticky(op string, err error)
type FileLock ¶
type FileLock struct {
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) 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 (*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 ¶
func (m *JournalMap) LoadLocked(id security.OperationID) ([]fsm.TransferJournalRecord, error)
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) 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
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) 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
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 (*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 并返回退出信号通道。
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 (s *RemoteSession) Start(ctx context.Context, cmd execution.CommandPlan, streams ports.ExecStreams) error
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 ¶
func (s *RemoteSession) Wait(ctx context.Context) (execution.ExecutionOutcome, error)
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 执行的失效函数。
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 哨兵保护的作用域写入器。
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 复用)。
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 返回当前窗口尺寸。
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 (*Tree) CheckRegularSlotLocked ¶
CheckRegularSlotLocked 校验 abs 的父目录与目标槽位是否满足常规文件(及可选独占)前置条件。
func (*Tree) CheckRemoteWriteTargetLocked ¶
func (t *Tree) CheckRemoteWriteTargetLocked(rawKey string, spec ports.RemoteWriteSpec) (string, error)
CheckRemoteWriteTargetLocked 校验远端原子写入目标的父目录、NoClobber、目录冲突与期望锚点。
func (*Tree) ChmodRemoteLocked ¶
ChmodRemoteLocked 保留文件类型位并更新远端对象标准权限位与修改时间。
func (*Tree) ChtimesLocalLocked ¶
ChtimesLocalLocked 校验合法 RFC 3339 时间戳与无软链路径并更新沙箱常规文件或目录的修改时间。
func (*Tree) ChtimesRemoteLocked ¶
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 ¶
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 ¶
MkdirAllLocked 递归创建目录链,按 followParent 决定是否跟随已有中间符号链接(调用方须持有 t.Mu)。
func (*Tree) OpenOrCreateRegularLocked ¶
func (t *Tree) OpenOrCreateRegularLocked(abs string, create bool, checkWrite func() error, perm fs.FileMode) (*Node, error)
OpenOrCreateRegularLocked 打开已有常规文件或在 create==true 时新建常规文件节点。
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 ¶
ReadRemoteChunkLocked 在持有 t.Mu 下读取远端常规文件 [offset, offset+length) 区间副本与 EOF 标记。
func (*Tree) ReleaseLock ¶
ReleaseLock 释放 abs 上的指定模式文件锁并广播唤醒等待者。
func (*Tree) RelocateSubtreeLocked ¶
RelocateSubtreeLocked 将 oldKey(及其目录子树)原子迁移至 newKey(调用方须持有 t.Mu 且已完成前置校验)。
func (*Tree) RemoveLocked ¶
RemoveLocked 删除文件、符号链接或空目录(拒绝删除根目录与非空目录,调用方须持有 t.Mu)。
func (*Tree) RemoveRemoteDirLocked ¶
RemoveRemoteDirLocked 仅删除远端空目录(SFTP SSH_FXP_RMDIR);非目录或非空目录返回 ports.ErrInvalidArgument。
func (*Tree) RemoveRemoteFileLocked ¶
RemoveRemoteFileLocked 仅删除远端常规文件或符号链接;若目标为目录则返回 ports.ErrRemoteIsDir。
func (*Tree) RenameLocalLocked ¶
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 ¶
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)。