croc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 54 Imported by: 1 module, 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

ctx.go

Index

Constants

View Source
const (
	ReconnectVersion = 1
)

Variables

View Source
var (
	ErrRelayConnection = errors.New("relay connection failed")
	// ErrDERPConnection is the compatibility sentinel for failures in the
	// Tailcat-backed data path selected by --transport derp.
	ErrDERPConnection = errors.New("DERP connection failed")
)

ErrRelayConnection marks a failure to establish a relay control or data connection. Callers may use it to invalidate cached relay selections without treating peer or transfer failures as relay availability failures.

Functions

func CopyToClipboard

func CopyToClipboard(value string, quiet bool, extended bool)

CopyToClipboard copies a croc share value using the platform clipboard helper.

func Debug

func Debug(debug bool)

Debug toggles debug mode

func GetFilesInfo

func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error)

This function retrieves the important file information for every file that will be transferred

func GetFilesInfoContext

func GetFilesInfoContext(ctx context.Context, fnames []string, zipfolder bool, ignoreGit bool, exclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error)

GetFilesInfoContext is GetFilesInfo with cancellation support.

func GetFilesInfoWithExactExclusions

func GetFilesInfoWithExactExclusions(fnames []string, zipfolder bool, ignoreGit bool, exclusions, exactExclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error)

GetFilesInfoWithExactExclusions retrieves file information while applying both the legacy substring exclusions and exact relative-path exclusions.

func GetFilesInfoWithExactExclusionsContext

func GetFilesInfoWithExactExclusionsContext(ctx context.Context, fnames []string, zipfolder bool, ignoreGit bool, exclusions, exactExclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error)

GetFilesInfoWithExactExclusionsContext retrieves file information while allowing a large directory walk or zip operation to be canceled.

func ShowReceiveCommandQrCode

func ShowReceiveCommandQrCode(command string)

ShowReceiveCommandQrCode prints a QR code for a share URL.

Types

type Chunk

type Chunk struct {
	Bytes    []byte `json:"b,omitempty"`
	Location int64  `json:"l,omitempty"`
}

Chunk contains information about the needed bytes

type Client

type Client struct {
	Options                         Options
	Pake                            *pake.Pake
	Key                             []byte
	ExternalIP, ExternalIPConnected string

	Step1ChannelSecured       bool
	Step2FileInfoTransferred  bool
	Step3RecipientRequestFile bool
	Step4FileTransferred      bool
	Step5CloseChannels        bool
	SuccessfulTransfer        bool

	// send / receive information of all files
	FilesToTransfer           []FileInfo
	EmptyFoldersToTransfer    []FileInfo
	TotalNumberOfContents     int
	TotalNumberFolders        int
	FilesToTransferCurrentNum int
	FilesHasFinished          map[int]struct{}
	TotalFilesIgnored         int

	// send / receive information of current file
	CurrentFile            *os.File
	CurrentFileChunkRanges []int64
	CurrentFileChunkCount  int
	CurrentFileIsClosed    bool
	LastFolder             string

	TotalSent              int64
	TotalChunksTransferred int
	// contains filtered or unexported fields
}

Client holds the state of the croc transfer

func New

func New(ops Options) (*Client, error)

New establishes a new connection for transferring files between two instances.

func NewCtx

func NewCtx(ctx context.Context, ops Options) (*Client, error)

NewCtx creates a client with context support

func NewQUICCtx

func NewQUICCtx(ctx context.Context, ops Options, config QUICConfig) (*Client, error)

NewQUICCtx retains Croc's transfer engine and PAKE while requiring native QUIC data streams, mutual TLS, and a Flock-capable peer. No TCP data fallback.

func (Client) Cancel

func (s Client) Cancel()

Cancel initiates interruption of my loops and goroutines

func (*Client) Receive

func (c *Client) Receive() (err error)

Receive will receive a file

func (*Client) Send

func (c *Client) Send(filesInfo []FileInfo, emptyFoldersToTransfer []FileInfo, totalNumberFolders int) (err error)

Send will send the specified file

func (*Client) SendError

func (c *Client) SendError()

SendError tells the peer to interrupt their loops and goroutines

type FileInfo

type FileInfo struct {
	Name         string      `json:"n,omitempty"`
	FolderRemote string      `json:"fr,omitempty"`
	FolderSource string      `json:"fs,omitempty"`
	Hash         []byte      `json:"h,omitempty"`
	Size         int64       `json:"s,omitempty"`
	ModTime      time.Time   `json:"m,omitzero"`
	IsCompressed bool        `json:"c"`
	IsEncrypted  bool        `json:"e,omitempty"`
	Symlink      string      `json:"sy,omitempty"`
	Mode         os.FileMode `json:"md,omitempty"`
	TempFile     bool        `json:"tf,omitempty"`
	IsIgnored    bool        `json:"ig,omitempty"`
	Prepared     bool        `json:"p,omitempty"`
	// contains filtered or unexported fields
}

FileInfo registers the information about the file

type Options

type Options struct {
	Agent             bool                               `json:"-"`
	OnProgress        func(int64)                        `json:"-"`
	OnTransport       func(string)                       `json:"-"`
	OnOffer           func([]FileInfo, []FileInfo) error `json:"-"`
	IsSender          bool
	SharedSecret      string
	RoomName          string
	Debug             bool
	RelayAddress      string
	RelayAddress6     string
	PublicRelay       bool
	RelayPorts        []string
	RelayPassword     string
	Stdout            bool
	NoPrompt          bool
	NoMultiplexing    bool
	DisableLocal      bool
	OnlyLocal         bool
	IgnoreStdin       bool
	Ask               bool
	SendingText       bool
	NoCompress        bool
	IP                string
	Overwrite         bool
	Rename            bool
	Curve             string
	HashAlgorithm     string
	ThrottleUpload    string
	ZipFolder         bool
	TestFlag          bool
	GitIgnore         bool
	MulticastAddress  string
	ShowQrCode        bool
	Exclude           []string
	ExcludeFile       []string
	Quiet             bool
	DisableClipboard  bool
	ExtendedClipboard bool
	Transport         TransportMode `json:",omitempty"`
}

Options specifies user specific options

type QUICConfig

type QUICConfig struct {
	Listen    string
	Advertise string
	Streams   int
}

QUICConfig selects directly reachable UDP file-data endpoints. The Croc relay is used only for the PAKE-authenticated control channel.

type RemoteFileRequest

type RemoteFileRequest struct {
	CurrentFileChunkRanges    []int64
	FilesToTransferCurrentNum int
	MachineID                 string
	ExternalIP                string `json:",omitempty"`
	ReconnectVersion          int
	Features                  []string `json:",omitempty"`
}

RemoteFileRequest requests specific bytes

type SenderInfo

type SenderInfo struct {
	FilesToTransfer        []FileInfo
	EmptyFoldersToTransfer []FileInfo
	TotalNumberFolders     int
	MachineID              string
	ExternalIP             string `json:",omitempty"`
	Ask                    bool
	SendingText            bool
	NoCompress             bool
	HashAlgorithm          string
	ReconnectVersion       int
	NextReconnectRoom      string
	Features               []string `json:",omitempty"`
}

SenderInfo lists the files to be transferred

type SimpleMessage

type SimpleMessage struct {
	Bytes   []byte
	Bytes2  []byte
	Kind    string
	Version int
	Curve   string
}

type TransferOptions

type TransferOptions struct {
	PathToFiles      []string
	KeepPathInRemote bool
}

TransferOptions for sending

type TransportMode

type TransportMode string

TransportMode controls how a sender selects the file-data connection after the PAKE-authenticated control channel is established. Receivers must use TransportAuto and follow the sender's negotiated selection.

const (
	TransportAuto  TransportMode = "auto"
	TransportDERP  TransportMode = "derp"
	TransportRelay TransportMode = "relay"
)

func ParseTransportMode

func ParseTransportMode(value string) (TransportMode, error)

ParseTransportMode validates and normalizes a transport name. An empty value is the API-compatible spelling of the default auto mode.

func ResolveTransportMode

func ResolveTransportMode(value string) (effective TransportMode, downgraded bool, err error)

ResolveTransportMode validates a transport name and resolves it against the capabilities compiled into this binary. Relay-only builds downgrade strict Tailcat requests to the croc relay and report that choice to the caller.

Jump to

Keyboard shortcuts

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