server

package
v0.0.4-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Package server provides the MALT daemon HTTP API.

Index

Constants

View Source
const (
	// DefaultJSONBodyBytes caps any JSON-decoded request body. ProofList and
	// semantic mutation payloads stay well below this in practice.
	DefaultJSONBodyBytes int64 = 8 * 1024 * 1024 // 8 MiB

	// DefaultUnixFSUploadBytes caps a single UnixFS file upload that the
	// daemon buffers in memory before chunking.
	DefaultUnixFSUploadBytes int64 = 1 * 1024 * 1024 * 1024 // 1 GiB
)

Body size defaults for write-side routes. These are sized for the MALT research prototype, where structured JSON requests are typically tens of KB and file uploads are bounded by the host's available memory (AddFileStream currently buffers the whole upload before chunking).

Operators with different needs can override these via WithBodyLimits; tests in particular install much smaller numbers so they can exercise the limit path without allocating real megabytes of memory.

View Source
const (
	// DefaultReadHeaderTimeout caps how long a client has to send the request
	// line and headers. Bodies are read separately and may be longer-lived.
	DefaultReadHeaderTimeout = 10 * time.Second

	// DefaultIdleTimeout caps how long an idle keep-alive connection stays
	// open between requests.
	DefaultIdleTimeout = 60 * time.Second

	// DefaultReadTimeout caps the total time for reading the request,
	// including the body. Long uploads and JSON payloads may need this raised
	// at the operator level.
	DefaultReadTimeout = 5 * time.Minute

	// DefaultWriteTimeout caps the total time spent writing a response back
	// to a client. Range reads of very large list payloads may need this
	// raised.
	DefaultWriteTimeout = 5 * time.Minute

	// DefaultMaxHeaderBytes caps total header size to prevent header-flood
	// abuse and keep ProofList headers from silently exploding.
	DefaultMaxHeaderBytes = 64 * 1024
)

Conservative HTTP server hardening defaults. These are intentionally generous for normal MALT workloads (large UnixFS uploads, slow CAS materialization) but tight enough to keep a single misbehaving client from holding sockets open indefinitely (slowloris) or burying the daemon under one giant header stream.

Callers that need different limits can override them via the WithServerLimits option; tests in particular use much shorter timeouts.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyLimits added in v0.0.2

type BodyLimits struct {
	JSONBytes         int64
	UnixFSUploadBytes int64
}

BodyLimits configures upper bounds on accepted request bodies for write routes. Zero fields fall back to the package defaults.

type Option

type Option func(*Server)

Option configures the daemon server.

func WithBodyLimits added in v0.0.2

func WithBodyLimits(limits BodyLimits) Option

WithBodyLimits overrides the default request-body bounds.

func WithBrowserOrigins

func WithBrowserOrigins(origins []string) Option

WithBrowserOrigins allows browser-based tools to call the local daemon from the configured origins.

func WithLifecycleToken

func WithLifecycleToken(token string) Option

WithLifecycleToken configures the local managed-process identity token used by lifecycle commands.

func WithServerLimits added in v0.0.2

func WithServerLimits(limits ServerLimits) Option

WithServerLimits overrides the default HTTP-level resource bounds. Any zero field falls back to the package defaults; this lets callers tune one knob without restating the rest.

type Server

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

Server serves the daemon HTTP API.

func New

func New(node *node.Node, addr string, opts ...Option) *Server

New creates a new daemon server.

func (*Server) Handler

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

Handler returns the configured HTTP handler.

func (*Server) Shutdown

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

Shutdown gracefully stops the HTTP server.

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server.

type ServerLimits added in v0.0.2

type ServerLimits struct {
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
}

ServerLimits configures HTTP-level resource bounds for the daemon server. Zero values fall back to the defaults above.

Jump to

Keyboard shortcuts

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