mobile

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mobile provides gomobile-compatible bindings for KeibiDrop. All exported types and functions follow gomobile restrictions: no maps, no slices (except []byte), no channels, no complex types. File lists use index-based access (GetRemoteFileCount + GetRemoteFileName).

Index

Constants

View Source
const (
	OpStatusIdle      = "idle"
	OpStatusRunning   = "running"
	OpStatusSucceeded = "succeeded"
	OpStatusFailed    = "failed"
	OpStatusTimeout   = "timeout"
)

Operation status constants (polled from Swift/Kotlin).

Variables

This section is empty.

Functions

func FileTypeFromName

func FileTypeFromName(name string) string

FileTypeFromName returns a category string for a file based on its extension. Returns one of: "pdf", "image", "video", "audio", "code", "archive", "text", "other".

func FormatFileSize

func FormatFileSize(bytes int64) string

FormatFileSize returns a human-readable file size string.

Types

type API

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

API is the main entry point for mobile apps. Create one instance, call Initialize, then Start in a background thread.

func (*API) CancelDownload

func (api *API) CancelDownload(remoteName string) error

CancelDownload stops an active download. Partial data is preserved. Call SaveFile or ExportFile again to resume.

func (*API) CancelOp

func (api *API) CancelOp() error

CancelOp cancels the current async operation.

func (*API) Connect

func (api *API) Connect() error

Connect determines the creator/joiner role automatically via fingerprint comparison, then creates or joins a room. Blocking.

func (*API) ConnectAsync

func (api *API) ConnectAsync() error

ConnectAsync starts Connect in the background. Poll GetOpStatus() to check progress.

func (*API) CreateRoom

func (api *API) CreateRoom() error

CreateRoom creates a room and waits for the peer to join. Blocking.

func (*API) CreateRoomAsync

func (api *API) CreateRoomAsync() error

CreateRoomAsync starts room creation in the background. Poll GetOpStatus() to check progress.

func (*API) Disconnect

func (api *API) Disconnect() error

Disconnect ends the current session but keeps the engine alive. You can CreateRoom/JoinRoom again after this.

func (*API) ExportFile

func (api *API) ExportFile(remoteName string, destPath string) error

ExportFile downloads a file from the peer and saves it to destPath. destPath is where to write on the device (app sandbox, then share via OS).

func (*API) Fingerprint

func (api *API) Fingerprint() (string, error)

Fingerprint returns your local fingerprint code. Share this with your peer via Signal, Telegram, email, etc.

func (*API) GetConnectionMode

func (api *API) GetConnectionMode() string

GetConnectionMode returns the current connection mode: "lan", "direct", "bridge", or "" if not connected.

func (*API) GetConnectionStatus

func (api *API) GetConnectionStatus() int

GetConnectionStatus returns 0=disconnected, 2=connected, 3=reconnecting.

func (*API) GetDiscoveredPeerAddr

func (api *API) GetDiscoveredPeerAddr(i int) string

GetDiscoveredPeerAddr returns the address of the discovered peer at index i.

func (*API) GetDiscoveredPeerCount

func (api *API) GetDiscoveredPeerCount() int

GetDiscoveredPeerCount returns the number of discovered peers on the LAN.

func (*API) GetDiscoveredPeerName

func (api *API) GetDiscoveredPeerName(i int) string

GetDiscoveredPeerName returns the name of the discovered peer at index i.

func (*API) GetDiscoveryName

func (api *API) GetDiscoveryName() string

GetDiscoveryName returns this device's random display name for LAN discovery.

func (*API) GetDownloadProgress

func (api *API) GetDownloadProgress(remoteName string) int

GetDownloadProgress returns download progress as 0-100, or -1 if not active.

func (*API) GetLastError

func (api *API) GetLastError() string

GetLastError returns the last error message, or empty string.

func (*API) GetLocalAddress

func (api *API) GetLocalAddress() string

GetLocalAddress returns the link-local IPv6 address for local mode connections. Format: "fe80::1234:5678%en0:26431"

func (*API) GetLocalFileCount

func (api *API) GetLocalFileCount() int

GetLocalFileCount returns the number of local files in the last snapshot.

func (*API) GetLocalFileName

func (api *API) GetLocalFileName(i int) string

GetLocalFileName returns the name of the local file at index i in the last snapshot. Returns empty string if i is out of bounds.

func (*API) GetOpStatus

func (api *API) GetOpStatus() *OpStatus

GetOpStatus returns the status of the current async operation.

func (*API) GetRemoteFileCount

func (api *API) GetRemoteFileCount() int

GetRemoteFileCount returns the number of remote files in the last snapshot.

func (*API) GetRemoteFileName

func (api *API) GetRemoteFileName(i int) string

GetRemoteFileName returns the name of the remote file at index i in the last snapshot. Returns empty string if i is out of bounds.

func (*API) GetRemoteFileSize

func (api *API) GetRemoteFileSize(i int) int64

GetRemoteFileSize returns the size in bytes of the remote file at index i in the last snapshot. Returns 0 if i is out of bounds.

func (*API) GetSavePath

func (api *API) GetSavePath() string

GetSavePath returns the configured save folder path.

func (*API) GetVersion

func (api *API) GetVersion() string

GetVersion returns the version string.

func (*API) HasResumableDownload

func (api *API) HasResumableDownload(remoteName string) bool

HasResumableDownload returns true if a .kdbitmap file exists for the given file, meaning a previous download was interrupted and can be resumed.

func (*API) ImportFile

func (api *API) ImportFile(localPath string) error

ImportFile adds a local file to share with the peer. localPath is a path to a file on the device (from file picker, Photos, etc).

func (*API) ImportFileAs

func (api *API) ImportFileAs(localPath string, remoteName string) error

ImportFileAs adds a local file with a custom remote name (preserving folder paths).

func (*API) Initialize

func (api *API) Initialize(logFilePath string, relayURL string, inboundPort int, outboundPort int, savePath string) error

Initialize sets up the KeibiDrop engine. Call once before Start. savePath is where received files are stored (app sandbox directory). No FUSE on mobile. prefetchOnOpen and pushOnWrite are ignored.

func (*API) JoinRoom

func (api *API) JoinRoom() error

JoinRoom joins a room created by the peer. Blocking.

func (*API) JoinRoomAsync

func (api *API) JoinRoomAsync() error

JoinRoomAsync starts joining a room in the background. Poll GetOpStatus() to check progress.

func (*API) PeerFingerprint

func (api *API) PeerFingerprint() string

PeerFingerprint returns the registered peer's fingerprint, or empty string.

func (*API) PollEvent

func (api *API) PollEvent() string

PollEvent returns the next event string, or empty string if none. Non-blocking. Event format: "type:payload" (e.g. "health_changed:healthy:disconnected").

func (*API) RefreshFileList

func (api *API) RefreshFileList()

RefreshFileList takes a consistent snapshot of remote and local files. Call this once per poll cycle, then use the count/name/size getters.

func (*API) RegisterPeer

func (api *API) RegisterPeer(fingerprint string) error

RegisterPeer registers the peer's fingerprint code.

func (*API) RelayEndpoint

func (api *API) RelayEndpoint() string

RelayEndpoint returns the relay URL string.

func (*API) SaveAllFiles

func (api *API) SaveAllFiles() int

SaveAllFiles downloads all remote files to the save folder sequentially. Returns the number of files successfully saved.

func (*API) SaveFile

func (api *API) SaveFile(remoteName string) (string, error)

SaveFile downloads a file from the peer into the save folder. If the file already exists at the correct size, it skips the download. Returns the local path where the file was saved.

func (*API) SetBridgeAddr

func (api *API) SetBridgeAddr(addr string)

SetBridgeAddr overrides the default bridge relay address.

func (*API) SetPeerDirectAddress

func (api *API) SetPeerDirectAddress(addr string) error

SetPeerDirectAddress sets the peer's address for local mode (no relay). Automatically enables local mode (skips relay, uses TOFU handshake).

func (*API) SetStrictMode

func (api *API) SetStrictMode(enabled bool)

SetStrictMode enables/disables strict mode (no data relay fallback).

func (*API) SetupEventCallbacks

func (api *API) SetupEventCallbacks()

SetupEventCallbacks wires health/reconnect events into the event queue. Call once after Initialize, before Start.

func (*API) Start

func (api *API) Start() error

Start runs the KeibiDrop event loop. Blocks until Stop is called. Call this from a background thread on mobile.

func (*API) StartDiscovery

func (api *API) StartDiscovery()

StartDiscovery begins broadcasting presence and listening for peers on the LAN. Also enables local mode (skips relay for connections).

func (*API) Stop

func (api *API) Stop() error

Stop shuts down the engine. Safe to call multiple times.

func (*API) StopDiscovery

func (api *API) StopDiscovery()

StopDiscovery stops LAN discovery and disables local mode.

type OpStatus

type OpStatus struct {
	Status  string
	Message string
}

OpStatus is the result of GetOpStatus(). gomobile-safe (exported fields, simple types).

Jump to

Keyboard shortcuts

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