server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

Package server implements the AgentTransfer server: HTTP API + MCP + share pages, inbound SMTP, the TTL janitor, and the long-poll hub — one process, one folder of state.

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.1.0-dev"

Version is stamped at build time via -ldflags; keep a sane default.

Functions

func ParseDiskReserve

func ParseDiskReserve(s string, total int64) (int64, error)

ParseDiskReserve resolves a DISK_RESERVE value — "10%" of the volume, an absolute size like "50GB", or "off"/"0" — into bytes (0 = disabled). total is the volume capacity, needed for the percentage form.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize parses sizes like "500MB", "5GB", "1048576".

func ParseTTL

func ParseTTL(s string) (time.Duration, error)

ParseTTL parses positive durations like "90m", "3h", "24h", "1d".

Types

type Config

type Config struct {
	// Domain enables email + autocert, e.g. "agents.example.com".
	Domain string
	// DataDir holds the SQLite database and blob directory.
	DataDir string
	// HTTPAddr is the HTTP(S) listen address. Defaults to ":443" when Domain
	// is set (autocert) and ":8080" otherwise.
	HTTPAddr string
	// SMTPAddr is the inbound SMTP listen address (":25" when Domain is set;
	// empty disables).
	SMTPAddr string
	// Outbound is the relay: "resend:<key>", "smtp://user:pass@host:587" or
	// "smtps://...". Empty disables outbound email.
	Outbound string
	// AdminToken gates signup and admin endpoints. Generated and printed on
	// first boot if unset.
	AdminToken string
	// OpenSignup allows unauthenticated signup (rate-limited per IP, owner
	// email verification required before outbound send).
	OpenSignup bool
	// PublicURL overrides the advertised base URL (useful behind a proxy).
	PublicURL string
	// ACMEEmail is the optional Let's Encrypt account email.
	ACMEEmail string
	// BehindProxy disables autocert and trusts X-Forwarded-For.
	BehindProxy bool

	// Connect (client side): URL of a connect host to borrow a public
	// subdomain and email service from, e.g. "https://agenttransfer.dev".
	// The instance registers anonymously, keeps one outbound tunnel open,
	// and needs no domain, DNS, open ports, or relay of its own.
	Connect string
	// ConnectDomain (host side): serve the connect service for
	// "*.<ConnectDomain>" subdomains. Requires Domain mode (TLS + SMTP);
	// usually set equal to Domain.
	ConnectDomain string
	// ConnectSendRate caps relayed outbound emails per connected instance
	// per day (spam blast radius).
	ConnectSendRate int64
	// ConnectBytesPerDay caps proxied bytes per connected instance per day
	// (egress cost + abuse blast radius).
	ConnectBytesPerDay int64

	MaxFileSize  int64
	DefaultTTL   time.Duration
	MaxTTL       time.Duration
	SendRate     int64 // outbound emails per agent per day
	UploadRate   int64 // uploads per agent per day
	StorageQuota int64 // live folder bytes per agent
	// StorageQuotaUnverified is the folder cap for agents whose owner has not
	// verified yet — anonymous signups get a small drive until a human vouches.
	StorageQuotaUnverified int64
	// HumanRecipientsMax caps the unique remote (non-local) addresses an agent
	// may ever email — the "circle": a compromised agent can spam at most this
	// many strangers. The verified owner is always exempt; <0 disables the cap.
	HumanRecipientsMax int64
	Metrics            string // off | localhost | admin

	// DiskReserve is the global backstop against disk fill: uploads are
	// refused (507) while the volume holding DataDir has less free space than
	// this. "10%" of the volume, an absolute size like "50GB", or "off".
	// Applied only when set — FromEnv defaults it to "10%"; hand-built configs
	// (tests, demo) leave it off unless they opt in.
	DiskReserve string
	// MaxAgentsPerOwner caps how many agents one owner_email can register via
	// open signup — identities must not be free in bulk. <0 disables.
	MaxAgentsPerOwner int64
	// IPRate is the per-IP hourly request budget on the public unauthenticated
	// pages (/f/, /u/, index). IPv4 keys per address, IPv6 per /64. <=0
	// disables — FromEnv defaults it to 600.
	IPRate int64
	// UploadBodyTimeout bounds how long one upload request may spend sending
	// its body (slow-body parking defense). It is a read deadline only —
	// downloads deliberately have no write timeout. <=0 disables — FromEnv
	// defaults it to 1h.
	UploadBodyTimeout time.Duration
	// UnverifiedFileTTL makes files owned by agents WITHOUT a verified owner
	// expire — the storage mirror of the quota tier: anonymous signups get a
	// scratchpad, verified owners get the drive. Verifying lifts the expiry
	// on the agent's existing files. <=0 disables — FromEnv defaults it
	// to 24h.
	UnverifiedFileTTL time.Duration
}

Config is the operator-facing configuration, read from environment variables. Everything has a working default; a bare `agenttransfer serve` runs a full local instance.

func FromEnv

func FromEnv() (Config, error)

FromEnv builds a Config from the environment.

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults fills the derived defaults; safe to call on hand-built configs (tests, demo).

func (*Config) BaseURL

func (c *Config) BaseURL() string

BaseURL returns the advertised base URL, no trailing slash.

func (*Config) EmailEnabled

func (c *Config) EmailEnabled() bool

EmailEnabled reports whether this instance can do email at all.

func (*Config) Instance

func (c *Config) Instance() string

Instance returns the addressing domain ("local" when none configured).

type Server

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

Server owns all runtime state.

func New

func New(cfg Config) (s *Server, firstBootAdmin string, err error)

New opens the store and builds a Server. If no admin token was configured and none exists yet, the generated one is returned once via firstBootAdmin.

func (*Server) BaseURL

func (s *Server) BaseURL() string

BaseURL returns the advertised base URL.

func (*Server) Close

func (s *Server) Close() error

Close releases the store.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler builds the full HTTP handler (REST + MCP + pages).

func (*Server) JanitorOnce

func (s *Server) JanitorOnce() error

JanitorOnce runs one janitor sweep: expire links, expire unclaimed files, GC orphan blobs, prune bookkeeping. Exported for tests and the demo.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the HTTP(S) listener, the inbound SMTP listener, and the janitor, then blocks until ctx is canceled.

func (*Server) SetBaseURL

func (s *Server) SetBaseURL(u string)

SetBaseURL overrides the advertised base URL (demo/tests bind random ports).

func (*Server) Store

func (s *Server) Store() *store.Store

Store exposes the store (demo and tests).

Jump to

Keyboard shortcuts

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