Documentation
¶
Overview ¶
Package transfer manages authorized, single-use file transfer tasks. It is independent of MCP sessions so a task can outlive its creation request.
Index ¶
- Variables
- func ValidateDiagnostic(value string) error
- type Authorization
- type Direction
- type Journal
- type Lease
- func (l *Lease) BeginCommit() (context.Context, error)
- func (l *Lease) BeginCommitBound(permit ports.Permit) (context.Context, error)
- func (l *Lease) Close() error
- func (l *Lease) Complete() (Status, error)
- func (l *Lease) ConfirmTemporary() error
- func (l *Lease) Context() context.Context
- func (l *Lease) Fail(cause error) (Status, error)
- func (l *Lease) Progress(bytes int64) error
- func (l *Lease) RejectCommit(cause error) (Status, error)
- func (l *Lease) ReserveCommit(permit ports.Permit) error
- func (l *Lease) Spec() Spec
- func (l *Lease) Temporary() (string, error)
- func (l *Lease) Verify(bytes int64, digest string) error
- type Limits
- type Manager
- func (m *Manager) Authenticate(id, token string) (Status, error)
- func (m *Manager) Cancel(scope, id string) (Status, error)
- func (m *Manager) CancelWithToken(id, token string) (Status, error)
- func (m *Manager) Claim(ctx context.Context, id, token string, direction Direction) (*Lease, error)
- func (m *Manager) ClaimBound(ctx context.Context, id, token string, direction Direction, ...) (*Lease, error)
- func (m *Manager) Cleaned(id string) error
- func (m *Manager) Close() error
- func (m *Manager) FindRequest(scope, requestID, digest string) (Record, bool, error)
- func (m *Manager) InvalidateReady(id string, cause error) error
- func (m *Manager) Lookup(scope, id string) (Status, error)
- func (m *Manager) Prepare(spec Spec, operationID string) (Prepared, error)
- func (m *Manager) PrepareBound(spec Spec, operationID string, permit ports.Permit) (Prepared, error)
- func (m *Manager) Record(id string) (Record, error)
- func (m *Manager) Records() []Record
- func (m *Manager) Retry(scope, requestID, requestDigest string) (Prepared, bool, error)
- func (m *Manager) RetryBound(id string, permit ports.Permit) (Prepared, error)
- func (m *Manager) Shutdown(ctx context.Context) error
- func (m *Manager) Warn(id, warning string) error
- type Prepared
- type Record
- type Spec
- type State
- type Status
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( ErrBusy = errors.New("transfer capacity unavailable") ErrConflict = errors.New("transfer conflicts with existing task") ErrNotFound = errors.New("transfer not found") ErrExpired = errors.New("transfer start window expired") ErrClosed = errors.New("transfer manager closed") ErrInvalidState = errors.New("transfer state does not permit this operation") ErrStoreLocked = errors.New("transfer metadata is already in use") ErrStoreUnusable = errors.New("transfer metadata cannot be persisted") ErrRecordTooLarge = errors.New("transfer record exceeds size limit") )
var ErrBindingRequired = errors.New("transfer requires its original authorization binding")
Functions ¶
func ValidateDiagnostic ¶
ValidateDiagnostic bounds the JSON content as well as its UTF-8 byte length. This is used for exact operator reasons, which must not be silently truncated.
Types ¶
type Authorization ¶
type Authorization struct {
Snapshot ports.OperationSnapshot `json:"snapshot"`
Binding ports.Binding `json:"binding"`
}
Authorization is secret-free, private journal data. Binding covers the canonical Spec; RequestDigest in Spec continues to identify the client input.
func (Authorization) MarshalJSON ¶
func (a Authorization) MarshalJSON() ([]byte, error)
The v2 journal encodes opaque credential CAS tokens as base64. Legacy CLI providers use binary SHA-256 strings, which JSON strings cannot round-trip.
func (*Authorization) UnmarshalJSON ¶
func (a *Authorization) UnmarshalJSON(data []byte) error
type Journal ¶
type Journal struct {
// contains filtered or unexported fields
}
Journal serializes durable task snapshots under a permanent process lock. A failed Save may already have replaced a file; callers must fail closed rather than infer that an error means no persistent change occurred.
func OpenJournal ¶
type Lease ¶
type Lease struct {
// contains filtered or unexported fields
}
Lease owns a single data request. Call Close on every path, including error paths. No background worker is started: the HTTP handler performs the stream.
func (*Lease) BeginCommit ¶
BeginCommit durably records intent before returning a separate bounded context. Client disconnects after this boundary cannot cancel remote commit.
func (*Lease) BeginCommitBound ¶
BeginCommitBound durably records an admitted reservation. Direct callers without a prior ReserveCommit atomically reserve here before persistence.
func (*Lease) ConfirmTemporary ¶
ConfirmTemporary runs immediately after a successful exclusive open and before writing content. Lost open replies leave ownership unconfirmed.
func (*Lease) Fail ¶
Fail classifies uncertain commits conservatively. It does not remove any remote file; cleanup uses a separate connection and this task's owned path.
func (*Lease) RejectCommit ¶
RejectCommit is reserved for a caller with evidence that rename was never attempted or was explicitly rejected by the remote SFTP server. Transport failure without that evidence must use Fail, producing Unknown instead.
func (*Lease) ReserveCommit ¶
ReserveCommit completes gate admission under the same lock as task Cancel. The caller supplies a gate-issued commit permit; no remote I/O occurs here.
type Limits ¶
type Limits struct {
MaxFileBytes int64
MaxActive int
MaxPerTarget int
MaxReady int
MaxRecords int
StartWindow time.Duration
Retention time.Duration
TotalTimeout time.Duration
CommitTimeout time.Duration
}
func DefaultLimits ¶
func DefaultLimits() Limits
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
NewManager takes ownership of store even if recovery fails. Recovery never resumes a stream or commits a remote file; it only classifies durable intent.
func (*Manager) Authenticate ¶
Authenticate deliberately returns the same error for an unknown task and a bad credential. Lookup for MCP management is separately scoped by service auth.
func (*Manager) CancelWithToken ¶
func (*Manager) ClaimBound ¶
func (m *Manager) ClaimBound(ctx context.Context, id, token string, direction Direction, permit ports.Permit) (*Lease, error)
ClaimBound takes the original client/request context separately from the stream permit. This distinction preserves task cancellation during commit admission while allowing an already granted commit to outlive stream revocation.
func (*Manager) Cleaned ¶
Cleaned records confirmed temporary-file removal or a failed exclusive creation that produced no owned file. Never use it to resolve unknown commit.
func (*Manager) FindRequest ¶
FindRequest never rotates credentials. It lets the runtime validate the original binding before RetryBound, without holding the manager lock over I/O.
func (*Manager) InvalidateReady ¶
InvalidateReady does not change active, completed, or uncertain results.
func (*Manager) Prepare ¶
Prepare returns the same task for an identical request. A still-ready task receives a new credential, revoking the previous one without extending TTL.
func (*Manager) PrepareBound ¶
func (m *Manager) PrepareBound(spec Spec, operationID string, permit ports.Permit) (Prepared, error)
PrepareBound is the versioned runtime entry. Legacy Prepare keeps writing v1 for compatibility; unbound records cannot acquire runtime execution authority.
func (*Manager) Records ¶
Records provides an immutable snapshot for local recovery and owned-file cleanup. It is not a client status response and contains credential digests.
func (*Manager) Retry ¶
Retry returns an already-authorized task without opening the remote target or approving it again. Exact client input is compared before credential reissue.
func (*Manager) RetryBound ¶
type Record ¶
type Record struct {
Version int `json:"version"`
Authorization *Authorization `json:"authorization,omitempty"`
ID string `json:"id"`
OperationID string `json:"operationID"`
Spec Spec `json:"spec"`
TokenDigest string `json:"tokenDigest"`
State State `json:"state"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
StartBefore time.Time `json:"startBefore"`
StatusExpiresAt time.Time `json:"statusExpiresAt"`
TempPath string `json:"tempPath,omitempty"`
TempOwned bool `json:"tempOwned"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256,omitempty"`
Error string `json:"error,omitempty"`
Warning string `json:"warning,omitempty"`
CleanupPending bool `json:"cleanupPending"`
CancelRequested bool `json:"cancelRequested"`
Resolved bool `json:"resolved"`
Resolution string `json:"resolution,omitempty"`
}
Record is private journal data, not an HTTP response. TokenDigest must never be exposed by tool output or status responses.
func (Record) CheckPermit ¶
CheckPermit validates recorded intent and the host's admitted capability. The gate, not the journal, establishes whether dependencies are still current.
type Spec ¶
type Spec struct {
RequestID string `json:"requestID"`
RequestDigest string `json:"requestDigest,omitempty"`
RequestedPath string `json:"requestedPath,omitempty"`
Scope string `json:"scope"`
Direction Direction `json:"direction"`
NodeID string `json:"nodeID"`
TargetID string `json:"targetID"`
RemotePath string `json:"remotePath"`
Size int64 `json:"size"`
SHA256 string `json:"sha256,omitempty"`
Overwrite bool `json:"overwrite"`
SourceModTime int64 `json:"sourceModTime,omitempty"`
}
Spec is the immutable, approved operation. TargetID identifies the resolved SSH target and account, including aliases that share a destination lock.
type Status ¶
type Status struct {
ID string `json:"transferID"`
OperationID string `json:"operationID"`
Direction Direction `json:"direction"`
NodeID string `json:"nodeID"`
RemotePath string `json:"remotePath"`
State State `json:"state"`
Size int64 `json:"size"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256,omitempty"`
Error string `json:"error,omitempty"`
Warning string `json:"warning,omitempty"`
CleanupPending bool `json:"cleanupPending"`
TempOwned bool `json:"temporaryOwnershipConfirmed"`
CancelRequested bool `json:"cancelRequested"`
Resolved bool `json:"resolved"`
StartBefore time.Time `json:"startBefore"`
StatusExpiresAt time.Time `json:"statusExpiresAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Status deliberately excludes authentication scope and credential digests.