transfer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInternalConfig

func BuildInternalConfig(cfg IOConfig) internalSess.Config

BuildInternalConfig maps IOConfig to an internalSess.Config.

func DecodeData

func DecodeData(dec *zstd.Decoder, scratch, in []byte) (payload, newScratch []byte, err error)

DecodeData decompresses in with dec, reusing scratch to avoid allocation. When dec is nil it returns in unchanged.

func EmitProgressSamples

func EmitProgressSamples(
	ctx context.Context,
	role Role,
	ns *stats.Stats,
)

EmitProgressSamples emits an immediate Sample tagged with role and then one every progressInterval until ctx is canceled. The initial sample guarantees at least one event for transfers that finish in tens of milliseconds (loopback benches, tiny files).

func EmitSDP

func EmitSDP(out io.Writer, role Role, encoded string)

EmitSDP writes the encoded local SDP to out, tagged with role.

func MaybeShowQR

func MaybeShowQR(encoded string, disableQR bool)

MaybeShowQR renders a QR of encoded to stderr when not disabled, text mode is active, and the payload fits qrPayloadLimit. Oversize payloads fall back to a short notice.

func NewDataDecoder

func NewDataDecoder() (*zstd.Decoder, error)

NewDataDecoder builds a single-threaded zstd decoder for DATA payloads.

func NewDataEncoder

func NewDataEncoder(level int) (*zstd.Encoder, error)

NewDataEncoder builds a single-threaded zstd encoder for DATA payloads. One per PC so the library pool doesn't multiply by N.

func ReadRemoteSDP

func ReadRemoteSDP(in io.Reader) (string, error)

ReadRemoteSDP prompts, reads from in, optionally unwraps a {"sdp":"..."} envelope, and returns the encoded SDP. Re-prompts on failure.

func ResolveIO

func ResolveIO(cfg IOConfig) (in io.Reader, out io.Writer)

ResolveIO fills in stdin/stdout defaults and returns the resolved pair.

func RunFrames

func RunFrames(
	ctx context.Context,
	ch *session.Channel,
	fh protocol.FrameHandler,
	bufSize int,
	onErr func(error),
)

RunFrames spawns a goroutine that drives ch.OnFrames and forwards any non-context.Canceled error to onErr. Cancel ctx to stop the loop.

func StartProgressEmitter

func StartProgressEmitter(
	ctx context.Context,
	role Role,
	ns *stats.Stats,
) (stop func())

StartProgressEmitter runs EmitProgressSamples in a goroutine. The returned stop cancels the emitter and waits for the goroutine to exit.

Types

type IOConfig

type IOConfig struct {
	// SDPProvider reads the remote SDP. Nil falls back to os.Stdin.
	SDPProvider io.Reader
	// SDPOutput writes the local SDP. Nil falls back to os.Stdout.
	SDPOutput io.Writer
	// STUNServers is a list of STUN host:port entries. Each is prefixed
	// with "stun:" before being passed through to the ICE config. A nil
	// or empty slice disables STUN entirely — useful on a LAN where
	// host/mDNS candidates are enough.
	STUNServers []string
	// DisableQR suppresses the QR render of the local SDP.
	DisableQR bool
	// LoopbackOnly pins ICE to lo0 and drops STUN (bench only).
	LoopbackOnly bool
	// DisableMDNS suppresses mDNS candidate gathering. Zero-value means
	// mDNS is on (peers advertise `.local` hostnames for host candidates).
	DisableMDNS bool
	// ICELite enables pion's ICE-Lite mode on every PC this session opens.
	//
	// Test-only: it's only safe when both peers are ICE-lite on a guaranteed-
	// routable path (loopback in-process).
	//
	// Production callers must leave this false; the CLI never sets it.
	ICELite bool
}

IOConfig is the shared subset of sender/receiver Config driving SDP I/O and PeerConnection setup.

type Role

type Role uint8

Role identifies the sending or receiving end of a transfer.

const (
	// RoleSender originates the transfer and emits the SDP offer.
	RoleSender Role = iota
	// RoleReceiver accepts the offer and writes into the target file.
	RoleReceiver
)

func (Role) String

func (r Role) String() string

String returns the lowercase identifier for r, or "unknown".

type SessionBase

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

SessionBase is embedded by sender and receiver sessions to share the NetworkStats getter and the resolved SDP I/O handles.

func NewSessionBase

func NewSessionBase(ns *stats.Stats, cfg IOConfig) SessionBase

NewSessionBase returns a SessionBase holding ns and the SDP I/O handles resolved from cfg (stdin/stdout defaults applied).

func (*SessionBase) NetworkStats

func (b *SessionBase) NetworkStats() *stats.Stats

NetworkStats returns the stats pointer. Meaningful after Start returns.

func (*SessionBase) SDPInput

func (b *SessionBase) SDPInput() io.Reader

SDPInput returns the SDP input handle.

func (*SessionBase) SDPOutput

func (b *SessionBase) SDPOutput() io.Writer

SDPOutput returns the SDP output handle.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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