transfer

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 18 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 transfer manages authorized, single-use file transfer tasks. It is independent of MCP sessions so a task can outlive its creation request.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBusy          = errors.New("transfer capacity unavailable")
	ErrConflict      = errors.New("transfer conflicts with existing task")
	ErrUnauthorized  = errors.New("invalid transfer credential")
	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")
)

Functions

This section is empty.

Types

type Direction

type Direction string
const (
	Upload   Direction = "upload"
	Download Direction = "download"
)

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

func OpenJournal(directory string) (_ *Journal, retErr error)

func (*Journal) Close

func (j *Journal) Close() error

func (*Journal) Load

func (j *Journal) Load(limit int) (_ []Record, retErr error)

func (*Journal) Remove

func (j *Journal) Remove(id string) error

func (*Journal) Save

func (j *Journal) Save(record Record) (retErr error)

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

func (l *Lease) BeginCommit() (context.Context, error)

BeginCommit durably records intent before returning a separate bounded context. Client disconnects after this boundary cannot cancel remote commit.

func (*Lease) Close

func (l *Lease) Close() error

func (*Lease) Complete

func (l *Lease) Complete() (Status, error)

func (*Lease) ConfirmTemporary

func (l *Lease) ConfirmTemporary() error

ConfirmTemporary runs immediately after a successful exclusive open and before writing content. Lost open replies leave ownership unconfirmed.

func (*Lease) Context

func (l *Lease) Context() context.Context

func (*Lease) Fail

func (l *Lease) Fail(cause error) (Status, error)

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

func (l *Lease) Progress(bytes int64) error

Progress updates observable bytes without writing the journal per chunk.

func (*Lease) RejectCommit

func (l *Lease) RejectCommit(cause error) (Status, error)

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

func (l *Lease) Spec() Spec

func (*Lease) Temporary

func (l *Lease) Temporary() (string, error)

Temporary records the exclusive-create intent before the remote file is opened. If exclusive creation fails, the caller must clear this intent and must not remove the conflicting remote file.

func (*Lease) Verify

func (l *Lease) Verify(bytes int64, digest string) error

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

func (Limits) Validate

func (l Limits) Validate() error

type Manager

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

func NewManager

func NewManager(ctx context.Context, store Store, limits Limits) (_ *Manager, retErr error)

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

func (m *Manager) Authenticate(id, token string) (Status, error)

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

func (m *Manager) Cancel(scope, id string) (Status, error)

func (*Manager) CancelWithToken

func (m *Manager) CancelWithToken(id, token string) (Status, error)

func (*Manager) Claim

func (m *Manager) Claim(ctx context.Context, id, token string, direction Direction) (*Lease, error)

func (*Manager) Cleaned

func (m *Manager) Cleaned(id string) error

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

func (m *Manager) Close() error

func (*Manager) Lookup

func (m *Manager) Lookup(scope, id string) (Status, error)

func (*Manager) Prepare

func (m *Manager) Prepare(spec Spec, operationID string) (Prepared, error)

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

func (m *Manager) Record(id string) (Record, error)

func (*Manager) Records

func (m *Manager) Records() []Record

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

func (m *Manager) Retry(scope, requestID, requestDigest string) (Prepared, bool, error)

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

func (m *Manager) Shutdown(ctx context.Context) error

Shutdown rejects new claims, cancels precommit work and gives committing leases their bounded completion window. It can be retried after a timeout.

func (*Manager) Warn

func (m *Manager) Warn(id, warning string) error

type Prepared

type Prepared struct {
	Status Status
	Token  string
}

type Record

type Record struct {
	Version         int       `json:"version"`
	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) Status

func (r Record) Status() Status

Status returns the public view without credentials or authentication scope.

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 State

type State string
const (
	Ready        State = "ready"
	Transferring State = "transferring"
	Verifying    State = "verifying"
	Committing   State = "committing"
	Completed    State = "completed"
	Streamed     State = "streamed"
	Failed       State = "failed"
	Cancelled    State = "cancelled"
	Expired      State = "expired"
	Unknown      State = "unknown"
)

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.

type Store

type Store interface {
	Load(limit int) ([]Record, error)
	Save(Record) error
	Remove(id string) error
	Close() error
}

Store persists complete task snapshots. Save errors may follow an applied write and must disable new mutations until storage is recovered.

Jump to

Keyboard shortcuts

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