sim

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 31 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 sim 提供 XOps v2 全部出站端口(core/ports)的 100% 确定性内存仿真与故障注入引擎(Plan P2-T6)。

架构约束:零生产可达(xopsvet/archbound);零 time.Now/time.Sleep/裸 go/crypto/rand/path/filepath/nolint; SimVault 采用 AES-256-GCM 静态密文存储;全部作用域借用句柄均带运行时失效哨兵。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSimNotInitialized = errors.New("sim: 仿真适配器未初始化")
	ErrFaultInjected     = errors.New("sim: 命中确定性故障注入规则")
	ErrSimulatedENOSPC   = errors.New("sim: 模拟磁盘空间不足 (ENOSPC)")
	ErrSimulatedCrash    = errors.New("sim: 模拟进程 SIGKILL 突发崩溃")
)

仿真器导出的不可变哨兵错误。

Functions

func DefaultBaseTime

func DefaultBaseTime() time.Time

DefaultBaseTime 返回默认确定性 UTC 基准时刻(2026-05-01T12:00:00Z)。

Types

type AuditBoundary

type AuditBoundary uint8

AuditBoundary 标识可供 DST 精确触发 SIGKILL 崩溃注入的审计生命周期边界。

const (
	// AuditBoundaryAfterStage 表示完成 StageOperation(+opID) 后的崩溃注入点。
	AuditBoundaryAfterStage AuditBoundary = iota + 1
	// AuditBoundaryAfterAuthorized 表示前置 Audit(Authorized) 落盘后的崩溃注入点。
	AuditBoundaryAfterAuthorized
	// AuditBoundaryAfterFinalized 表示终态 Audit(Finalized) 落盘后的崩溃注入点。
	AuditBoundaryAfterFinalized
	// AuditBoundaryAfterUnstage 表示完成 UnstageOperation(-opID) 后的崩溃注入点。
	AuditBoundaryAfterUnstage
)

type FaultInjector

type FaultInjector = memtree.FaultInjector

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

func NewFaultInjector

func NewFaultInjector(rng *SeededRand) *FaultInjector

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

type HopFaultProfile

type HopFaultProfile struct {
	DialLatency, KeepaliveLatency   time.Duration
	DialErr, KeepaliveErr           error
	StuckClose                      bool // Close 阻塞直至父跳板关闭(INV-C3 90ms 升级)或 UnblockClose
	SessionOutput                   string
	SessionOutcome                  execution.ExecutionOutcome
	SessionStartErr, SessionWaitErr error
}

HopFaultProfile 定义单跳拨号与连接层的延迟、失败、保活与卡死关闭故障参数。

type ProcessHandler

type ProcessHandler func(ctx context.Context, spec ports.ProcessSpec, stdin []byte) (ports.ProcessResult, error)

ProcessHandler 定义 SimProcessPort 的可编程命令处理回调。

type SeededRand

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

SeededRand 是基于 SplitMix64 + xoshiro256++ 的并发安全确定性 PRNG,实现 ports.Entropy (io.Reader)。

func NewSeededRand

func NewSeededRand(seed uint64) *SeededRand

NewSeededRand 以 64 位种子构造跨平台逐字节一致的确定性随机与熵源。

func (*SeededRand) Bool

func (r *SeededRand) Bool() bool

func (*SeededRand) Chance

func (r *SeededRand) Chance(num, den int) bool

func (*SeededRand) Faults

func (b *SeededRand) Faults() *FaultInjector

func (*SeededRand) Fork

func (r *SeededRand) Fork() *SeededRand

func (*SeededRand) IntN

func (r *SeededRand) IntN(n int) int

func (*SeededRand) Perm

func (r *SeededRand) Perm(n int) []int

func (*SeededRand) Read

func (r *SeededRand) Read(p []byte) (int, error)

func (*SeededRand) SetReadFault

func (r *SeededRand) SetReadFault(err error)

SetReadFault / Read / Uint64 / IntN / Bool / Chance / Fork / Perm 提供熵读取与随机调度。

func (*SeededRand) Uint64

func (r *SeededRand) Uint64() uint64

type SimAuditCluster

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

SimAuditCluster 模拟多进程共享的 audit.jsonl 与 run/<ProcessInstanceID>.lock 目录(ADR-008 / RFC §3.4), 实现 ports.AuditReconciler:无死亡锁 O(1) 零读取 audit.jsonl,遇死亡锁按活跃差集补写唯一 AbortedByCrash。

func NewSimAuditCluster

func NewSimAuditCluster() *SimAuditCluster

NewSimAuditCluster 创建空白的共享审计集群仿真器。

func (*SimAuditCluster) AuditLogScans

func (c *SimAuditCluster) AuditLogScans() uint64

func (*SimAuditCluster) Digest

func (c *SimAuditCluster) Digest() (sum [sha256.Size]byte, err error)

func (*SimAuditCluster) Entries

func (c *SimAuditCluster) Entries() []ports.AuditEntry

func (*SimAuditCluster) Faults

func (b *SimAuditCluster) Faults() *FaultInjector

func (*SimAuditCluster) LockTruncations

func (c *SimAuditCluster) LockTruncations() uint64

func (*SimAuditCluster) NewSink

func (c *SimAuditCluster) NewSink(procID ports.ProcessInstanceID) (*SimAuditSink, error)

NewSink 与 NewSinkFromEntropy 为指定进程签发持实时进程锁的 SimAuditSink。

func (*SimAuditCluster) NewSinkFromEntropy

func (c *SimAuditCluster) NewSinkFromEntropy(entropy io.Reader) (*SimAuditSink, error)

func (*SimAuditCluster) ReconcileCrashedAudits

func (c *SimAuditCluster) ReconcileCrashedAudits(ctx context.Context, now time.Time) (out ports.CrashReconcileReport, err error)

ReconcileCrashedAudits 实现 ports.AuditReconciler:无死亡锁 O(1) 零扫描,发现死亡锁补写 AbortedByCrash 并删锁。

func (*SimAuditCluster) SetENOSPC

func (c *SimAuditCluster) SetENOSPC(en bool)

SetENOSPC / AuditLogScans / LockTruncations / Entries / Digest 提供故障控制与 O(1) 观测。

type SimAuditSink

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

SimAuditSink 表示单个进程持有的只追加审计接收器,实现 ports.AuditSink,支持 SIGKILL 与边界钩子。

func (*SimAuditSink) Close

func (s *SimAuditSink) Close() error

func (*SimAuditSink) ProcessInstanceID

func (s *SimAuditSink) ProcessInstanceID() (out ports.ProcessInstanceID)

func (*SimAuditSink) Record

func (s *SimAuditSink) Record(ctx context.Context, entry ports.AuditEntry) error

func (*SimAuditSink) SetBoundaryHook

func (s *SimAuditSink) SetBoundaryHook(fn func(b AuditBoundary, opID security.OperationID))

SetBoundaryHook / ProcessInstanceID / StageOperation / UnstageOperation / Record / Close / SimulateSIGKILL。

func (*SimAuditSink) SimulateSIGKILL

func (s *SimAuditSink) SimulateSIGKILL()

func (*SimAuditSink) StageOperation

func (s *SimAuditSink) StageOperation(ctx context.Context, opID security.OperationID) error

func (*SimAuditSink) UnstageOperation

func (s *SimAuditSink) UnstageOperation(ctx context.Context, opID security.OperationID) error

type SimClock

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

SimClock 提供 100% 确定性并发安全虚拟时钟与定时器调度器(实现 ports.Clock,零 time.Sleep)。

func NewSimClock

func NewSimClock(start time.Time) *SimClock

NewSimClock 构造从 start(零值默认 DefaultBaseTime)起步的虚拟时钟。

func (*SimClock) Advance

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

func (*SimClock) AdvanceToNext

func (c *SimClock) AdvanceToNext() (time.Duration, bool)

func (*SimClock) Faults

func (b *SimClock) Faults() *FaultInjector

func (*SimClock) NewTimer

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

func (*SimClock) Now

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

Now / Since / PendingTimers / Advance / AdvanceToNext / NewTimer / Sleep / WaitPending 驱动虚拟时钟。

func (*SimClock) PendingTimers

func (c *SimClock) PendingTimers() int

func (*SimClock) Since

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

func (*SimClock) Sleep

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

func (*SimClock) WaitPending

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

type SimDialer

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

SimDialer 实现 ports.DialerPort,支持多跳虚拟延迟、卡死关闭根升级与零泄漏连接追踪。

func NewSimDialer

func NewSimDialer(clk ports.Clock, rng *SeededRand) *SimDialer

NewSimDialer 创建确定性拨号仿真器。

func (*SimDialer) ConnsSnapshot

func (d *SimDialer) ConnsSnapshot() []*SimTransportConn

func (*SimDialer) DialCount

func (d *SimDialer) DialCount() uint64

func (*SimDialer) DialHop

DialHop 建立单跳或多跳仿真传输连接。

func (*SimDialer) Faults

func (b *SimDialer) Faults() *FaultInjector

func (*SimDialer) OpenConns

func (d *SimDialer) OpenConns() int64

func (*SimDialer) SetDefaultProfile

func (d *SimDialer) SetDefaultProfile(p HopFaultProfile)

SetDefaultProfile / SetHopIndexProfile / SetDigestProfile / DialCount / OpenConns / ConnsSnapshot / UnblockAll。

func (*SimDialer) SetDigestProfile

func (d *SimDialer) SetDigestProfile(dig plan.HopDigest, p HopFaultProfile)

func (*SimDialer) SetHopIndexProfile

func (d *SimDialer) SetHopIndexProfile(idx uint32, p HopFaultProfile)

func (*SimDialer) UnblockAll

func (d *SimDialer) UnblockAll()

type SimEnvPort

type SimEnvPort = memtree.EnvPort

SimEnvPort / SimSSHFPLookup / SimTUNDevicePort 为 memtree 纯内存仿真端口的公开别名。

func NewSimEnvPort

func NewSimEnvPort(env map[string]string, id ports.LocalIdentityInfo) *SimEnvPort

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

type SimFormatImporter

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

SimFormatImporter 实现 ports.FormatImporter,将 CSV 行(alias,addr,port,user)解析为 ImportBundle。

func NewSimFormatImporter

func NewSimFormatImporter(format string) *SimFormatImporter

NewSimFormatImporter 创建格式导入仿真器(空格式名默认 "csv")。

func (*SimFormatImporter) Faults

func (b *SimFormatImporter) Faults() *FaultInjector

func (*SimFormatImporter) Format

func (i *SimFormatImporter) Format() string

func (*SimFormatImporter) Import

func (i *SimFormatImporter) Import(ctx context.Context, _ string, r io.Reader) (out inventory.ImportBundle, err error)

type SimForwardHandle

type SimForwardHandle = memtree.ForwardHandle

SimForwardHandle 是 memtree.ForwardHandle 的别名,实现 ports.ForwardHandle 与 pool.ManagedResource。

type SimForwarder

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

SimForwarder 实现 ports.ForwarderPort,返回持留池钉选传输的 *SimForwardHandle(满足 pool.ManagedResource)。

func NewSimForwarder

func NewSimForwarder() *SimForwarder

NewSimForwarder 创建纯内存 SSH 隧道转发仿真器。

func (*SimForwarder) Faults

func (b *SimForwarder) Faults() *FaultInjector

func (*SimForwarder) StartForward

func (f *SimForwarder) StartForward(ctx context.Context, transport ports.TunnelTransport, spec ports.ForwardSpec) (ports.ForwardHandle, error)

StartForward 启动单条受管隧道转发并持留非借用 transport 直至 ForwardHandle.Close()(支持启动后持续打开新通道)。

type SimHostTrust

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

SimHostTrust 实现按 Endpoint (Host, Port) 严格隔离的主机密钥信任库仿真器(INV-E2)。

func NewSimHostTrust

func NewSimHostTrust() *SimHostTrust

NewSimHostTrust 创建空白主机密钥信任库仿真器。

func (*SimHostTrust) Faults

func (b *SimHostTrust) Faults() *FaultInjector

func (*SimHostTrust) PreferredAlgorithms

func (t *SimHostTrust) PreferredAlgorithms(ctx context.Context, ep netaddr.Endpoint, _ option.KnownHostsList) ([]string, error)

func (*SimHostTrust) RecordHostKey

func (*SimHostTrust) RevokeKey

func (t *SimHostTrust) RevokeKey(fp inventory.KeyFingerprint)

RevokeKey 吊销指定主机公钥指纹,后续核验将返回 HostTrustRevoked。

func (*SimHostTrust) VerifyHostKey

func (t *SimHostTrust) VerifyHostKey(ctx context.Context, req ports.HostTrustRequest) (out ports.HostTrustCheck, err error)

type SimInteractionPort

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

SimInteractionPort 实现 ports.InteractionPort 的可编程确认、审批、文本与机密输入仿真器。

func NewSimInteractionPort

func NewSimInteractionPort(interactive bool) *SimInteractionPort

NewSimInteractionPort 创建确定性交互端口仿真器。

func (*SimInteractionPort) CanInteract

func (i *SimInteractionPort) CanInteract() bool

func (*SimInteractionPort) Confirm

func (*SimInteractionPort) Faults

func (b *SimInteractionPort) Faults() *FaultInjector

func (*SimInteractionPort) PromptApproval

func (*SimInteractionPort) PromptSecret

func (i *SimInteractionPort) PromptSecret(ctx context.Context, req ports.SecretPromptRequest, fn func(box *secret.SecretBox) error) error

PromptSecret 经 secret.WithBytes 借出受管 *secret.SecretBox,回调退出前无条件清零。

func (*SimInteractionPort) PromptText

func (*SimInteractionPort) SetApprovalPolicy

func (i *SimInteractionPort) SetApprovalPolicy(v security.Verdict, err error, tamper bool)

func (*SimInteractionPort) SetInteractive

func (i *SimInteractionPort) SetInteractive(en bool)

SetInteractive / SetApprovalPolicy / SetReplies 配置交互可用性、审批策略(含摘要篡改)与预设回答。

func (*SimInteractionPort) SetReplies

func (i *SimInteractionPort) SetReplies(text string, secretBytes []byte)

type SimInventoryStore

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

SimInventoryStore 实现 ports.InventoryStore,支持 CAS 并发冲突与不确定落盘结果注入。

func NewSimInventoryStore

func NewSimInventoryStore(initial inventory.Graph) (*SimInventoryStore, error)

NewSimInventoryStore 以初始资产图(无效时自动构造空有效图)创建存储仿真器。

func (*SimInventoryStore) CommitCAS

func (s *SimInventoryStore) CommitCAS(ctx context.Context, expected ports.Revision, next inventory.Graph) (out ports.DurabilityOutcome, err error)

func (*SimInventoryStore) Faults

func (b *SimInventoryStore) Faults() *FaultInjector

func (*SimInventoryStore) InjectNextDurability

func (s *SimInventoryStore) InjectNextDurability(out ports.DurabilityOutcome)

InjectNextDurability 注入下一次 CommitCAS 的持久化结果(如 Applied&&!Durable 或 Unknown)。

func (*SimInventoryStore) Load

type SimJournalStore

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

SimJournalStore 实现 ports.JournalStore 的纯内存确定性双代传输 WAL 仿真器(支持按代隔离与单侧损坏注入)。

func NewSimJournalStore

func NewSimJournalStore() *SimJournalStore

NewSimJournalStore 创建空白双代传输 Journal 仿真器。

func (*SimJournalStore) Append

func (*SimJournalStore) CorruptGeneration

func (s *SimJournalStore) CorruptGeneration(id security.OperationID, generation uint64, cause error)

CorruptGeneration 将指定 (transferID, generation) 标记为损坏态以供双代损坏隔离崩溃恢复测试。

func (*SimJournalStore) Delete

func (*SimJournalStore) Faults

func (b *SimJournalStore) Faults() *FaultInjector

func (*SimJournalStore) ListActive

func (s *SimJournalStore) ListActive(ctx context.Context) ([]security.OperationID, error)

func (*SimJournalStore) Load

func (*SimJournalStore) LoadGenerations

func (*SimJournalStore) PruneGeneration

func (s *SimJournalStore) PruneGeneration(ctx context.Context, id security.OperationID, generation uint64) error

type SimKeySigner

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

SimKeySigner 实现 ports.KeySignerPort 的确定性签名与指纹查询仿真器。

func NewSimKeySigner

func NewSimKeySigner(keys ...ports.PublicKeyInfo) *SimKeySigner

NewSimKeySigner 创建预置公钥的密钥签名仿真器。

func (*SimKeySigner) AddKey

func (s *SimKeySigner) AddKey(pub ports.PublicKeyInfo, keyPath string)

AddKey 注册公钥及其可选私钥路径映射(未注册路径查询时返回 ErrNotFound)。

func (*SimKeySigner) Faults

func (b *SimKeySigner) Faults() *FaultInjector

func (*SimKeySigner) InspectPrivateKeyFingerprint

func (s *SimKeySigner) InspectPrivateKeyFingerprint(ctx context.Context, keyPath inventory.KeyPathSpec, _ algebraic.Option[secret.Ref]) (out inventory.KeyFingerprint, err error)

func (*SimKeySigner) ListPublicKeys

func (s *SimKeySigner) ListPublicKeys(ctx context.Context, auth inventory.AuthMethod) ([]ports.PublicKeyInfo, error)

func (*SimKeySigner) Sign

func (s *SimKeySigner) Sign(ctx context.Context, key inventory.KeyFingerprint, algorithm string, data []byte) (out ports.Signature, err error)

type SimMuxSocket

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

SimMuxSocket 实现 ports.MuxSocketPort 的零 OS 套接字纯内存仿真器(含 Serve、OpenProxy 与精确身份 DialMux)。

func NewSimMuxSocket

func NewSimMuxSocket(dialer *SimDialer) *SimMuxSocket

NewSimMuxSocket 创建纯内存多路复用套接字仿真器(可选绑定 dialer 以纳入连接计数与虚拟时钟)。

func (*SimMuxSocket) Control

func (*SimMuxSocket) DialMux

func (m *SimMuxSocket) DialMux(ctx context.Context, sockPath pathalg.LocalSourcePath, hopDigest plan.HopDigest, endpoint netaddr.Endpoint) (ports.TransportConn, error)

func (*SimMuxSocket) Faults

func (b *SimMuxSocket) Faults() *FaultInjector

func (*SimMuxSocket) OpenProxy

func (m *SimMuxSocket) OpenProxy(ctx context.Context, sockPath pathalg.LocalSourcePath) (net.Conn, error)

func (*SimMuxSocket) Probe

func (m *SimMuxSocket) Probe(ctx context.Context, sockPath pathalg.LocalSourcePath) (out ports.MuxControlResponse, err error)

func (*SimMuxSocket) RegisterMaster

func (m *SimMuxSocket) RegisterMaster(sockPath pathalg.LocalSourcePath, pid uint32)

RegisterMaster 注册指定路径的仿真 ControlMaster 进程 PID。

func (*SimMuxSocket) Serve

func (m *SimMuxSocket) Serve(
	ctx context.Context,

	ln net.Listener,
	upstream ports.TransportConn,
	forwarder ports.ForwarderPort,
) error

Serve 在 WithListener 借出的 ln 上以纯内存 PROTOCOL.mux v4 服务端模式响应控制面停止或动态转发请求。

func (*SimMuxSocket) WithListener

func (m *SimMuxSocket) WithListener(ctx context.Context, socketPath pathalg.LocalSourcePath, fn func(ln net.Listener) error) error

WithListener 在同步闭包内借出带失效哨兵的纯内存 net.Listener,退出时自动失效并注销(兼容含 ':' 路径)。

type SimOpenSSHConfigSource

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

SimOpenSSHConfigSource 实现 ports.OpenSSHConfigSource 的虚拟主机与 Tier-4 选项折叠仿真器。

func NewSimOpenSSHConfigSource

func NewSimOpenSSHConfigSource(hosts ...ports.OpenSSHVirtualHost) *SimOpenSSHConfigSource

NewSimOpenSSHConfigSource 创建预置虚拟主机的 OpenSSHConfigSource 仿真器。

func (*SimOpenSSHConfigSource) Faults

func (b *SimOpenSSHConfigSource) Faults() *FaultInjector

func (*SimOpenSSHConfigSource) ListVirtualHosts

func (s *SimOpenSSHConfigSource) ListVirtualHosts(ctx context.Context) ([]ports.OpenSSHVirtualHost, error)

func (*SimOpenSSHConfigSource) ResolveTier4

type SimOperatorReadFS

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

SimOperatorReadFS 实现 ports.OperatorReadFS 的人工只读源内存仿真器(复用 memtree.Tree)。

func NewSimOperatorReadFS

func NewSimOperatorReadFS() *SimOperatorReadFS

NewSimOperatorReadFS 创建空白的操作员只读源仿真器。

func (*SimOperatorReadFS) Faults

func (b *SimOperatorReadFS) Faults() *FaultInjector

func (*SimOperatorReadFS) PutFile

func (o *SimOperatorReadFS) PutFile(p pathalg.LocalSourcePath, data []byte) error

PutFile 与 PutSymlink 注册仿真只读常规文件与符号链接夹具。

func (o *SimOperatorReadFS) PutSymlink(linkPath, targetPath pathalg.LocalSourcePath) error

func (*SimOperatorReadFS) WithOperatorRead

func (o *SimOperatorReadFS) WithOperatorRead(ctx context.Context, srcPath pathalg.LocalSourcePath, policy pathalg.SymlinkPolicy, fn func(r ports.BoundedReadHandle, size int64) error) error

WithOperatorRead 按 SymlinkPolicy 逐段解析并打开只读源,在同步闭包内借出受哨兵保护的随机读取句柄。

type SimPrivilegeEscalator

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

SimPrivilegeEscalator 实现 ports.PrivilegeEscalationPort,仅以 SHA-256 摘要校验借用的提权口令(0 明文留存)。

func NewSimPrivilegeEscalator

func NewSimPrivilegeEscalator() *SimPrivilegeEscalator

NewSimPrivilegeEscalator 创建默认免密放行的远端提权仿真器。

func (*SimPrivilegeEscalator) Faults

func (b *SimPrivilegeEscalator) Faults() *FaultInjector

func (*SimPrivilegeEscalator) RunPrivileged

RunPrivileged 通过借用的 opener 打开远端会话并校验可选提权口令(参数级 //xops:borrowed 静态审计零逃逸)。

func (*SimPrivilegeEscalator) SetOutcome

func (*SimPrivilegeEscalator) SetRequiredPassword

func (p *SimPrivilegeEscalator) SetRequiredPassword(raw []byte)

SetRequiredPassword 设置提权所需口令的摘要(传空切片关闭口令校验);SetOutcome 预设自定义执行结果。

type SimProcessPort

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

SimProcessPort 是零 os/exec 的纯内存子进程与 stdio 管道仿真器,实现 ports.ProcessPort。

func NewSimProcessPort

func NewSimProcessPort() *SimProcessPort

NewSimProcessPort 创建纯内存子进程仿真器("fail"/"false" 返回退出码 1,其余默认回显 stdin)。

func (*SimProcessPort) DialStdio

func (p *SimProcessPort) DialStdio(ctx context.Context, spec ports.ProcessSpec) (net.Conn, error)

func (*SimProcessPort) Faults

func (b *SimProcessPort) Faults() *FaultInjector

func (*SimProcessPort) RegisterCommand

func (p *SimProcessPort) RegisterCommand(cmd string, fn ProcessHandler)

RegisterCommand 注册或注销指定命令名的自定义处理回调。

func (*SimProcessPort) Run

func (p *SimProcessPort) Run(ctx context.Context, spec ports.ProcessSpec, stdin io.Reader) (out ports.ProcessResult, err error)

type SimRemoteFS

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

SimRemoteFS 是纯内存远端 POSIX/SFTP 文件系统仿真器(ADR-016,仅使用 path 包,支持中间目录软链解析、(dev,ino) 锚点与原子子树重命名)。

func NewSimRemoteFS

func NewSimRemoteFS(clk ports.Clock) *SimRemoteFS

NewSimRemoteFS 创建预置根目录 "/" 的远端 POSIX 文件系统仿真器。

func (*SimRemoteFS) Chmod

func (r *SimRemoteFS) Chmod(ctx context.Context, p pathalg.RemotePath, perm fs.FileMode) error

Chmod 修改远端目标对象标准权限位(仅允许 0o001..0o777,拒绝零值及特殊权限位)。

func (*SimRemoteFS) Chtimes

func (r *SimRemoteFS) Chtimes(ctx context.Context, p pathalg.RemotePath, atime, mtime time.Time) error

Chtimes 修改远端目标对象访问与修改时间(拒绝零值时间戳,支撑 scp -p)。

func (*SimRemoteFS) Close

func (r *SimRemoteFS) Close() error

func (*SimRemoteFS) Faults

func (b *SimRemoteFS) Faults() *FaultInjector

func (*SimRemoteFS) Lstat

func (*SimRemoteFS) MkdirAll

func (r *SimRemoteFS) MkdirAll(ctx context.Context, dir pathalg.RemotePath, perm fs.FileMode) error
func (r *SimRemoteFS) PutSymlink(linkPath pathalg.RemotePath, target string) error

func (*SimRemoteFS) ReadChunk

func (r *SimRemoteFS) ReadChunk(ctx context.Context, p pathalg.RemotePath, offset int64, dst io.Writer, length int64) (int64, error)

ReadChunk 从远端常规文件 offset 处读取至多 length 字节写入 dst;读满返回 (length, nil),遇 EOF 返回 (实际字节数, io.EOF)。

func (*SimRemoteFS) ReadDir

func (r *SimRemoteFS) ReadDir(ctx context.Context, dir pathalg.RemotePath) (out []ports.RemoteDirEntry, err error)
func (r *SimRemoteFS) ReadLink(ctx context.Context, p pathalg.RemotePath) (target string, err error)

func (*SimRemoteFS) RealPath

func (r *SimRemoteFS) RealPath(ctx context.Context, p pathalg.RemotePath) (out pathalg.RemotePath, err error)

func (*SimRemoteFS) Remove

func (r *SimRemoteFS) Remove(ctx context.Context, p pathalg.RemotePath) error

func (*SimRemoteFS) RemoveDir

func (r *SimRemoteFS) RemoveDir(ctx context.Context, dir pathalg.RemotePath) error

func (*SimRemoteFS) RenameAtomic

func (r *SimRemoteFS) RenameAtomic(ctx context.Context, oldPath, newPath pathalg.RemotePath, spec ports.RemoteRenameSpec) error

func (*SimRemoteFS) SetENOSPC

func (r *SimRemoteFS) SetENOSPC(en bool)

SetENOSPC / PutSymlink 提供远端磁盘满故障与软链重定向夹具支持。

func (*SimRemoteFS) Stat

func (*SimRemoteFS) WithReadFile

func (r *SimRemoteFS) WithReadFile(ctx context.Context, p pathalg.RemotePath, limits ports.ReadLimits, fn func(rd io.Reader, size int64) error) error

WithReadFile 在 limits 上限内以同步闭包借出远端文件只读流。

func (*SimRemoteFS) WriteChunk

func (r *SimRemoteFS) WriteChunk(ctx context.Context, p pathalg.RemotePath, offset int64, src io.Reader, length int64) error

func (*SimRemoteFS) WriteFileAtomic

func (r *SimRemoteFS) WriteFileAtomic(ctx context.Context, p pathalg.RemotePath, spec ports.RemoteWriteSpec, src io.Reader) (out ports.RemoteFileStat, err error)

type SimRemoteSession

type SimRemoteSession = memtree.RemoteSession

SimRemoteSession 是 memtree.RemoteSession 的别名,实现 ports.RemoteSession 及管道互斥校验。

type SimSSHAgent

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

SimSSHAgent 实现 ports.SSHAgentPort 的纯内存 SSH Agent 通道、公钥列举与签名仿真器。

func NewSimSSHAgent

func NewSimSSHAgent(keys ...ports.PublicKeyInfo) *SimSSHAgent

NewSimSSHAgent 创建预置公钥且默认可用的 SSH Agent 仿真器。

func (*SimSSHAgent) AddKey

func (a *SimSSHAgent) AddKey(pub ports.PublicKeyInfo)

func (*SimSSHAgent) DialAgent

func (*SimSSHAgent) Faults

func (b *SimSSHAgent) Faults() *FaultInjector

func (*SimSSHAgent) ListAgentKeys

func (*SimSSHAgent) SetAvailable

func (a *SimSSHAgent) SetAvailable(en bool)

SetAvailable / AddKey 控制 Agent 可达状态与已加载公钥。

func (*SimSSHAgent) SignWithAgent

func (a *SimSSHAgent) SignWithAgent(ctx context.Context, spec algebraic.Option[inventory.AgentSpec], key inventory.KeyFingerprint, algorithm string, data []byte) (out ports.Signature, err error)

type SimSSHFPLookup

type SimSSHFPLookup = memtree.SSHFPLookup

SimEnvPort / SimSSHFPLookup / SimTUNDevicePort 为 memtree 纯内存仿真端口的公开别名。

func NewSimSSHFPLookup

func NewSimSSHFPLookup() *SimSSHFPLookup

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

type SimScopedRootFS

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

SimScopedRootFS 实现 ports.ScopedRootFS,纯内存仿真 *os.Root、旁路锁、策略 (b) 软链与 ENOSPC。

func NewSimScopedRootFS

func NewSimScopedRootFS(clk ports.Clock) *SimScopedRootFS

NewSimScopedRootFS 创建纯内存 ScopedRootFS 仿真器。

func (*SimScopedRootFS) EnsureRoot

func (f *SimScopedRootFS) EnsureRoot(dir pathalg.LocalDir, perm fs.FileMode) error

EnsureRoot 幂等确保沙箱根目录 dir 存在,校验 perm 为非零标准权限位且受故障注入约束。

func (*SimScopedRootFS) Faults

func (b *SimScopedRootFS) Faults() *FaultInjector

func (*SimScopedRootFS) SetENOSPC

func (f *SimScopedRootFS) SetENOSPC(en bool)

SetENOSPC 开启或关闭模拟磁盘满(ENOSPC)故障。

func (*SimScopedRootFS) WithRoot

func (f *SimScopedRootFS) WithRoot(dir pathalg.LocalDir, fn func(root ports.RootHandle) error) error

WithRoot 在同步作用域内借出绑定至 dir 的 RootHandle,退出即失效借用哨兵。

type SimShellProbe

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

SimShellProbe 实现 ports.ShellProbePort 的两阶段远端 Shell 探测仿真器。

func NewSimShellProbe

func NewSimShellProbe(result ports.ShellProbeResult) *SimShellProbe

NewSimShellProbe 创建返回指定探测快照的仿真器(若传入零值则默认 POSIX sh 阶段 1 结果)。

func (*SimShellProbe) Faults

func (b *SimShellProbe) Faults() *FaultInjector

func (*SimShellProbe) ProbeShell

func (p *SimShellProbe) ProbeShell(
	ctx context.Context,

	opener ports.SessionOpener,
) (out ports.ShellProbeResult, err error)

func (*SimShellProbe) SetResult

func (p *SimShellProbe) SetResult(res ports.ShellProbeResult)

SetResult 更新仿真探测返回结果。

type SimTUNDevicePort

type SimTUNDevicePort = memtree.TUNDevicePort

SimEnvPort / SimSSHFPLookup / SimTUNDevicePort 为 memtree 纯内存仿真端口的公开别名。

func NewSimTUNDevicePort

func NewSimTUNDevicePort() *SimTUNDevicePort

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

type SimTerminalPort

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

SimTerminalPort 实现 ports.TerminalPort 的纯内存 PTY/ConPTY、双向 Relay 与孤儿进程组判定仿真器。

func NewSimTerminalPort

func NewSimTerminalPort(interactive bool, cols, rows uint16) *SimTerminalPort

NewSimTerminalPort 创建纯内存终端仿真器(cols/rows 为 0 时默认 80x24)。

func (*SimTerminalPort) CanSuspendProcessGroup

func (t *SimTerminalPort) CanSuspendProcessGroup() (v security.Verdict, err error)

func (*SimTerminalPort) Faults

func (b *SimTerminalPort) Faults() *FaultInjector

func (*SimTerminalPort) IsInteractive

func (t *SimTerminalPort) IsInteractive() bool

func (*SimTerminalPort) Output

func (t *SimTerminalPort) Output() []byte

func (*SimTerminalPort) QueueResize

func (t *SimTerminalPort) QueueResize(sizes ...ports.TerminalSize)

func (*SimTerminalPort) SetBlockInputAfterData

func (t *SimTerminalPort) SetBlockInputAfterData(block bool)

func (*SimTerminalPort) SetInput

func (t *SimTerminalPort) SetInput(data []byte)

func (*SimTerminalPort) SetSuspendResult

func (t *SimTerminalPort) SetSuspendResult(v security.Verdict, err error)

SetSuspendResult / SetInput / SetBlockInputAfterData / QueueResize / Output 配置测试夹具并观测终端写入输出。

func (*SimTerminalPort) Size

func (t *SimTerminalPort) Size() (out ports.TerminalSize, err error)

func (*SimTerminalPort) WithRawTerminal

func (t *SimTerminalPort) WithRawTerminal(ctx context.Context, fn func(term ports.TerminalHandle) error) error

WithRawTerminal 在同步作用域内借出带失效哨兵与双向 Relay 能力的 TerminalHandle,退出时关闭 ResizeEvents。

type SimTransportConn

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

SimTransportConn 实现 ports.TransportConn,支持外部断连 Drop、保活与卡死关闭升级。

func (*SimTransportConn) Close

func (c *SimTransportConn) Close() error

func (*SimTransportConn) DialStreamLocal

func (c *SimTransportConn) DialStreamLocal(ctx context.Context, remoteSocket pathalg.RemotePath) (net.Conn, error)

func (*SimTransportConn) DialTCP

func (c *SimTransportConn) DialTCP(ctx context.Context, target netaddr.HostPort) (net.Conn, error)

func (*SimTransportConn) Drop

func (c *SimTransportConn) Drop()

Drop 模拟底层连接静默断连(不关闭 closedCh);UnblockClose 解除 StuckClose 阻塞。

func (*SimTransportConn) Endpoint

func (c *SimTransportConn) Endpoint() netaddr.Endpoint

func (*SimTransportConn) HopDigest

func (c *SimTransportConn) HopDigest() plan.HopDigest

func (*SimTransportConn) IsAlive

func (c *SimTransportConn) IsAlive() bool

func (*SimTransportConn) IsClosed

func (c *SimTransportConn) IsClosed() bool

func (*SimTransportConn) KeepaliveCount

func (c *SimTransportConn) KeepaliveCount() uint64

func (*SimTransportConn) ListenStreamLocal

func (c *SimTransportConn) ListenStreamLocal(ctx context.Context, remoteSocket pathalg.RemotePath) (net.Listener, error)

func (*SimTransportConn) ListenTCP

func (c *SimTransportConn) ListenTCP(ctx context.Context, bindAddr string) (net.Listener, error)

func (*SimTransportConn) OpenRemoteFS

func (c *SimTransportConn) OpenRemoteFS(ctx context.Context) (ports.RemoteFSPort, error)

func (*SimTransportConn) OpenSession

func (c *SimTransportConn) OpenSession(ctx context.Context) (ports.RemoteSession, error)

func (*SimTransportConn) OpenTUN

func (*SimTransportConn) SendKeepalive

func (c *SimTransportConn) SendKeepalive(ctx context.Context) error

func (*SimTransportConn) UnblockClose

func (c *SimTransportConn) UnblockClose()

type SimVault

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

SimVault 是采用 AES-256-GCM 静态密文存储的确定性凭据库仿真器,同时实现 ports.SecretVault 与 ports.VaultControlPort(ADR-011 / P2-T6)。 仅保存 AES-GCM 密文、确定性随机 Nonce 与主口令 SHA-256 摘要,0 行内 nolint,完整通过 secretbox/secrettaint/linearlease 审计。

func NewSimVault

func NewSimVault(rng *SeededRand) *SimVault

NewSimVault 使用确定性随机源派生 AES-256 主密钥并创建已初始化且已解锁的 SimVault。

func NewUninitializedSimVault

func NewUninitializedSimVault(rng *SeededRand) *SimVault

NewUninitializedSimVault 创建处于 VaultStateUninitialized 状态的空白 SimVault,用于验证 Init/Unlock/Lock 生命周期。

func (*SimVault) CiphertextFor

func (v *SimVault) CiphertextFor(ref secret.Ref) (ct []byte, ok bool)

func (*SimVault) Delete

func (v *SimVault) Delete(ctx context.Context, ref secret.Ref) error

Delete 删除 ref 对应的静态密文记录。

func (*SimVault) Faults

func (b *SimVault) Faults() *FaultInjector

func (*SimVault) Init

func (v *SimVault) Init(
	ctx context.Context,

	pass *secret.SecretBox,
) error

Init 使用借用的主口令 SecretBox 初始化凭据库(参数级 //xops:borrowed 审计零逃逸);已初始化返回 ErrAlreadyExists。

func (*SimVault) IsLocked

func (v *SimVault) IsLocked() bool

func (*SimVault) Lock

func (v *SimVault) Lock(ctx context.Context) error

Lock 锁定凭据库(实现 ports.VaultControlPort);未初始化返回 ErrNotFound。

func (*SimVault) PutAndVerify

func (v *SimVault) PutAndVerify(
	ctx context.Context,
	ref secret.Ref,

	box *secret.SecretBox,
) error

PutAndVerify 以 AES-256-GCM 加密写入 ref,从存储读回密文解密并执行常量时间 Equal 校验;失败则原子回滚旧条目(INV-F3)。

func (*SimVault) SetVerifyMismatch

func (v *SimVault) SetVerifyMismatch(en bool)

SetVerifyMismatch / IsLocked / CiphertextFor / TamperCiphertext 控制测试故障与密文观测。

func (*SimVault) Status

func (v *SimVault) Status(ctx context.Context) (out ports.VaultStatus, err error)

Status 返回当前凭据库生命周期状态快照(实现 ports.VaultControlPort)。

func (*SimVault) TamperCiphertext

func (v *SimVault) TamperCiphertext(ref secret.Ref) bool

func (*SimVault) Unlock

func (v *SimVault) Unlock(
	ctx context.Context,

	pass *secret.SecretBox,
) error

Unlock 使用借用的主口令 SecretBox 解锁凭据库(参数级 //xops:borrowed 审计零逃逸);未初始化返回 ErrNotFound,口令失配返回 ErrAuthFailed。

func (*SimVault) WithSecret

func (v *SimVault) WithSecret(ctx context.Context, ref secret.Ref, fn func(box *secret.SecretBox) error) error

WithSecret 解密静态密文并在同步闭包内借出 *secret.SecretBox,退出前无条件清零底层明文。

Directories

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

Jump to

Keyboard shortcuts

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