simports

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 24 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 simports 为 core/internal/sim 提供无环纯内存非明文端口仿真叶包(LayerCoreSim):

  • 存储、日志与导入仿真:InventoryStore、JournalStore、FormatImporter;
  • 签名与主机信任仿真:KeySigner、HostTrust;
  • 扩展会话与系统端口仿真:SSHAgent、ShellProbe、Forwarder、ProcessPort、RemoteSession;
  • OpenSSH 规范化解析与诊断仿真:CanonicalResolver、DiagnosticSink;
  • 多凭据库控制面路由仿真:VaultControlRouter。

架构约束:零生产可达(xopsvet/archbound)、零反向导入父包 core/internal/sim、零明文 SecretBox 消费、 零 time.Now/time.Sleep/裸 go/crypto/rand/path/filepath/nolint;零值适配器统一失败关闭返回 ErrSimNotInitialized。

Index

Constants

This section is empty.

Variables

View Source
var ErrSimNotInitialized = errors.New("sim: 仿真适配器未初始化")

ErrSimNotInitialized 表示零值或未初始化仿真适配器被调用时的规范失败关闭哨兵错误,由父包 sim 只读重导出保持指针同一性。

Functions

This section is empty.

Types

type CanonicalResolver

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

CanonicalResolver 实现 ports.CanonicalResolverPort 的零网络确定性主机/CNAME 解析仿真器(ADR-019 E1), 支持主机记录、CNAME 链与环路模拟、虚拟时钟延迟与确定性故障注入;零值恒失败关闭。

func NewCanonicalResolver

func NewCanonicalResolver(clk ports.Clock) *CanonicalResolver

NewCanonicalResolver 创建零网络确定性规范化解析仿真器(clk 可为 nil,仅在设置延迟时用于虚拟睡眠)。

func (*CanonicalResolver) CNAMELookupCount

func (r *CanonicalResolver) CNAMELookupCount() uint64

func (*CanonicalResolver) Faults

func (b *CanonicalResolver) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*CanonicalResolver) HostLookupCount

func (r *CanonicalResolver) HostLookupCount() uint64

HostLookupCount / CNAMELookupCount / LookupCount / RecordedQueries 提供零 DNS 副作用与查询序列观测。

func (*CanonicalResolver) LookupCNAME

func (r *CanonicalResolver) LookupCNAME(ctx context.Context, host string) (string, error)

LookupCNAME 查询主机名对应的 CNAME 规范名(默认单跳便于调用方校验 PermittedCNAMEs;开启 FollowCNAMEChain 时完整追链并防环)。 遵循 ports.CanonicalResolverPort 契约:返回小写且不含末尾 DNS 根点 '.' 的规范主机名 (真实宿主适配器包装标准库 net.Resolver.LookupCNAME 时亦须在端口边界去除末尾 '.')。

func (*CanonicalResolver) LookupCount

func (r *CanonicalResolver) LookupCount() uint64

func (*CanonicalResolver) LookupHost

func (r *CanonicalResolver) LookupHost(ctx context.Context, host string) ([]string, error)

LookupHost 解析主机名对应地址列表(沿 CNAME 链追查并执行环路与跳数上限防呆,返回防御性副本)。

func (*CanonicalResolver) RecordedQueries

func (r *CanonicalResolver) RecordedQueries() []string

func (*CanonicalResolver) SetCNAME

func (r *CanonicalResolver) SetCNAME(host, target string)

SetCNAME 注册或清空单跳 CNAME 映射(host -> target)。

func (*CanonicalResolver) SetCNAMEChain

func (r *CanonicalResolver) SetCNAMEChain(names ...string)

SetCNAMEChain 按顺序批量注册多跳 CNAME 链(names[0] -> names[1] -> ... -> names[n-1])。

func (*CanonicalResolver) SetCNAMELoop

func (r *CanonicalResolver) SetCNAMELoop(names ...string)

SetCNAMELoop 注册首尾闭环的 CNAME 环路(names[0] -> ... -> names[n-1] -> names[0]),用于验证防环截断。

func (*CanonicalResolver) SetFollowCNAMEChain

func (r *CanonicalResolver) SetFollowCNAMEChain(follow bool)

SetFollowCNAMEChain 控制 LookupCNAME 是返回单跳下一规范名(false,默认,便于调用方逐跳校验与防环)还是递归追链至终点(true)。

func (*CanonicalResolver) SetHost

func (r *CanonicalResolver) SetHost(host string, addrs ...string)

SetHost 注册或清空主机名对应的解析地址列表(不区分大小写,自动归一末尾点号)。

func (*CanonicalResolver) SetHostError

func (r *CanonicalResolver) SetHostError(host string, err error)

SetHostError 为指定主机名注入确定性解析错误(传 nil 清除)。

func (*CanonicalResolver) SetLatency

func (r *CanonicalResolver) SetLatency(d time.Duration)

SetLatency 配置单次查询通过注入 Clock 等待的确定性延迟(<= 0 表示无延迟)。

func (*CanonicalResolver) SetMaxCNAMEHops

func (r *CanonicalResolver) SetMaxCNAMEHops(maxHops int)

SetMaxCNAMEHops 配置解析器内部追链最大跳数上限(<= 0 恢复默认值 16)。

type DiagnosticSink

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

DiagnosticSink 实现 ports.DiagnosticSink 的纯内存确定性诊断接收仿真器(ADR-019 C3), 支持级别过滤、有界容量丢弃计数与记录快照观测;零值恒安全静默忽略。

func NewDiagnosticSink

func NewDiagnosticSink() *DiagnosticSink

NewDiagnosticSink 创建默认接收全部 1..3 级有效诊断记录的纯内存仿真接收器。

func (*DiagnosticSink) Count

func (s *DiagnosticSink) Count() int

Count 返回当前缓冲中的诊断记录数量。

func (*DiagnosticSink) Dropped

func (s *DiagnosticSink) Dropped() uint64

Dropped 返回因有界缓冲满载而丢弃的诊断记录总数。

func (*DiagnosticSink) Emit

Emit 接收单条脱敏诊断记录;未初始化接收器、nil/已取消 ctx、零值/无效 rec 或超级别记录均安全静默忽略。

func (*DiagnosticSink) Faults

func (b *DiagnosticSink) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*DiagnosticSink) Records

func (s *DiagnosticSink) Records() []ports.DiagnosticRecord

Records 返回当前已记录的诊断快照防御性副本。

func (*DiagnosticSink) Reset

func (s *DiagnosticSink) Reset()

Reset 清空已缓冲诊断记录与丢弃计数器。

func (*DiagnosticSink) SetMaxLevel

func (s *DiagnosticSink) SetMaxLevel(level uint8)

SetMaxLevel 设置接收的最大诊断级别(1..3,越界输入静默忽略)。

func (*DiagnosticSink) SetMaxRecords

func (s *DiagnosticSink) SetMaxRecords(limit int)

SetMaxRecords 设置最大缓冲记录条数(<= 0 表示无上限;超限时新记录丢弃并累加 Dropped)。

type FormatImporter

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

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

func NewFormatImporter

func NewFormatImporter(format string) *FormatImporter

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

func (*FormatImporter) Faults

func (b *FormatImporter) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*FormatImporter) Format

func (i *FormatImporter) Format() string

func (*FormatImporter) Import

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

type Forwarder

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

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

func NewForwarder

func NewForwarder() *Forwarder

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

func (*Forwarder) Faults

func (b *Forwarder) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*Forwarder) LastBindOptions

func (f *Forwarder) LastBindOptions() (out ports.ForwardBindOptions)

LastBindOptions 返回最近一次通过参数校验的 StartForward 绑定选项快照(供单测断言策略透传闭环)。

func (*Forwarder) StartForward

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

type HostTrust

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

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

func NewHostTrust

func NewHostTrust() *HostTrust

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

func (*HostTrust) Faults

func (b *HostTrust) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*HostTrust) PreferredAlgorithms

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

func (*HostTrust) RecordHostKey

func (*HostTrust) RevokeKey

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

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

func (*HostTrust) VerifyHostKey

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

type InventoryStore

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

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

func NewInventoryStore

func NewInventoryStore(initial inventory.Graph) (*InventoryStore, error)

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

func (*InventoryStore) CommitCAS

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

func (*InventoryStore) Faults

func (b *InventoryStore) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*InventoryStore) InjectNextDurability

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

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

func (*InventoryStore) Load

func (s *InventoryStore) Load(ctx context.Context) (out ports.InventorySnapshot, err error)

type JournalStore

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

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

func NewJournalStore

func NewJournalStore() *JournalStore

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

func (*JournalStore) Append

func (*JournalStore) CorruptGeneration

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

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

func (*JournalStore) Delete

func (*JournalStore) Faults

func (b *JournalStore) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*JournalStore) ListActive

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

func (*JournalStore) Load

func (*JournalStore) LoadGenerations

func (*JournalStore) PruneGeneration

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

type KeySigner

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

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

func NewKeySigner

func NewKeySigner(keys ...ports.PublicKeyInfo) *KeySigner

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

func (*KeySigner) AddKey

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

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

func (*KeySigner) Faults

func (b *KeySigner) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*KeySigner) InspectPrivateKeyFingerprint

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

func (*KeySigner) ListPublicKeys

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

func (*KeySigner) Sign

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

type ProcessHandler

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

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

type ProcessPort

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

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

func NewProcessPort

func NewProcessPort() *ProcessPort

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

func (*ProcessPort) DialStdio

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

func (*ProcessPort) Faults

func (b *ProcessPort) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*ProcessPort) RegisterCommand

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

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

func (*ProcessPort) Run

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

type RemoteSession

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

RemoteSession 实现 ports.RemoteSession 及具名可选接口 ports.SubsystemRemoteSession、 ports.DirectTTYRemoteSession(ADR-019 A2 / C1 / D3),内部复用 memtree.RemoteSession 管道互斥与 生命周期状态机,补充 StartSubsystem、DirectNativeTTY、ForwardAgent 与 EscapeChar 观测。

func NewRemoteSession

func NewRemoteSession(aliveFn func() bool, cfg memtree.SessionFaultConfig, onClose func()) *RemoteSession

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

func (*RemoteSession) BeginStartLocked

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

BeginStartLocked 委托底层 memtree.RemoteSession 执行持锁状态复核。

func (*RemoteSession) Close

func (s *RemoteSession) Close() error

func (*RemoteSession) LastEscapeChar

func (s *RemoteSession) LastEscapeChar() algebraic.Option[option.EscapeCharSpec]

LastEscapeChar 返回最近一次会话启动请求携带的可选 EscapeChar 规格(供单测断言)。

func (*RemoteSession) LastForwardAgent

func (s *RemoteSession) LastForwardAgent() algebraic.Option[inventory.AgentSpec]

LastForwardAgent 返回最近一次会话启动请求携带的可选 ForwardAgent 规格(供单测断言)。

func (*RemoteSession) LastSubsystem

func (s *RemoteSession) LastSubsystem() string

LastSubsystem 返回最近一次通过 StartSubsystem 启动的子系统名称(供单测断言)。

func (*RemoteSession) ResizePTY

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

func (*RemoteSession) SetDirectNativeTTY

func (s *RemoteSession) SetDirectNativeTTY(enabled bool)

SetDirectNativeTTY 配置该仿真会话是否模拟原生 OpenSSH ControlMaster 控制终端 FD 直通模式(默认 false)。

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) StartSubsystem

func (s *RemoteSession) StartSubsystem(ctx context.Context, subsystem string, streams ports.ExecStreams) error

StartSubsystem 实现 ports.SubsystemRemoteSession,校验非空合法子系统名、ForwardAgent 与 EscapeChar 规格, 保持与管道互斥及单次启动一致契约,并记录启动子系统名供仿真测试观测。

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) UsesDirectNativeTTY

func (s *RemoteSession) UsesDirectNativeTTY() bool

UsesDirectNativeTTY 实现 ports.DirectTTYRemoteSession;未初始化零值失败关闭返回 false。

func (*RemoteSession) Wait

type SSHAgent

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

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

func NewSSHAgent

func NewSSHAgent(keys ...ports.PublicKeyInfo) *SSHAgent

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

func (*SSHAgent) AddKey

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

func (*SSHAgent) DialAgent

func (a *SSHAgent) DialAgent(ctx context.Context, spec algebraic.Option[inventory.AgentSpec]) (net.Conn, error)

func (*SSHAgent) Faults

func (b *SSHAgent) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*SSHAgent) ListAgentKeys

func (a *SSHAgent) ListAgentKeys(ctx context.Context, spec algebraic.Option[inventory.AgentSpec]) ([]ports.PublicKeyInfo, error)

func (*SSHAgent) SetAvailable

func (a *SSHAgent) SetAvailable(en bool)

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

func (*SSHAgent) SignWithAgent

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

type ShellProbe

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

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

func NewShellProbe

func NewShellProbe(result ports.ShellProbeResult) *ShellProbe

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

func (*ShellProbe) Faults

func (b *ShellProbe) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*ShellProbe) ProbeShell

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

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

ProbeShell 借用 SessionOpener 执行确定性远端 Shell 探测(参数级 //xops:borrowed 静态审计零逃逸)。

func (*ShellProbe) SetResult

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

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

type VaultControlRouter

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

VaultControlRouter 实现 ports.VaultControlRouter,按存储名路由至多个独立 VaultControlPort 仿真控制器(ADR-018)。

func NewVaultControlRouter

func NewVaultControlRouter(stores map[string]ports.VaultControlPort) (*VaultControlRouter, error)

NewVaultControlRouter 构造按存储名路由的多库控制面仿真器;可选预注册 stores 映射。

func (*VaultControlRouter) ControlFor

func (r *VaultControlRouter) ControlFor(store string) (ports.VaultControlPort, error)

ControlFor 按存储名路由并返回对应的 VaultControlPort(实现 ports.VaultControlRouter)。

func (*VaultControlRouter) ControlledStores

func (r *VaultControlRouter) ControlledStores() []string

ControlledStores 返回按字典序升序排列的已注册存储名防御性副本(实现 ports.VaultControlRouter)。

func (*VaultControlRouter) Faults

func (b *VaultControlRouter) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*VaultControlRouter) Register

func (r *VaultControlRouter) Register(store string, ctrl ports.VaultControlPort) error

Register 登记或替换指定存储名对应的 VaultControlPort 控制器(拒绝非法存储名或 nil 控制器)。

Jump to

Keyboard shortcuts

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