mobile

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MPL-2.0 Imports: 15 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. Swift and Kotlin poll these values.

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.

func GenerateMasterKeyHex added in v0.3.0

func GenerateMasterKeyHex() (string, error)

GenerateMasterKeyHex returns a random 32-byte master key as a hex string. Store it in the platform keychain and pass it to EnablePersistentIdentity on each launch.

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) AddContact added in v0.3.0

func (api *API) AddContact(name string, fingerprint string) error

AddContact adds a new contact by name and fingerprint.

func (*API) CancelDownload

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

CancelDownload stops an active download. Partial data stays on disk. 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) ConnectToContactAsync added in v0.3.0

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

ConnectToContactAsync starts connecting to a saved contact 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) DecideLocalRole added in v0.3.5

func (api *API) DecideLocalRole(myName, peerName, peerAddr string) bool

DecideLocalRole reports whether this device creates (true) or joins (false) in local mode. Desktop uses the same rule, so both sides resolve name collisions the same way.

func (*API) Disconnect

func (api *API) Disconnect() error

Disconnect ends the current session but keeps the engine alive. Call CreateRoom or JoinRoom again to start a new session.

func (*API) EnablePersistentIdentity added in v0.3.0

func (api *API) EnablePersistentIdentity(configDir string, masterKeyHex string) error

EnablePersistentIdentity loads or creates a stable device identity. masterKeyHex is a 64-char hex string (32 bytes) from the platform keychain. Call once after Initialize, before Start.

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 the write location on the device, usually in the app sandbox.

func (*API) Fingerprint

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

Fingerprint returns the local fingerprint code. Send it to the peer over an out-of-band channel.

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) GetContactCount added in v0.3.0

func (api *API) GetContactCount() int

GetContactCount returns the number of contacts in the last snapshot.

func (*API) GetContactFingerprint added in v0.3.0

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

GetContactFingerprint returns the fingerprint of the contact at index i.

func (*API) GetContactName added in v0.3.0

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

GetContactName returns the name of the contact at index i.

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 reports whether a .kdbitmap file exists for the file. The bitmap marks an interrupted download that can resume.

func (*API) ImportFile

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

ImportFile adds a local file to share with the peer. localPath is a device file path, for example from a file picker.

func (*API) ImportFileAs

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

ImportFileAs adds a local file with a custom remote name. The name can keep 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 the app sandbox directory for received files. Mobile has no FUSE.

func (*API) IsContactOnline added in v0.3.0

func (api *API) IsContactOnline(i int) bool

IsContactOnline returns whether the contact at index i is online.

func (*API) IsIncognito added in v0.3.0

func (api *API) IsIncognito() bool

IsIncognito returns whether the engine is in incognito mode.

func (*API) IsPeerAlreadyContact added in v0.3.0

func (api *API) IsPeerAlreadyContact() bool

IsPeerAlreadyContact returns whether the connected peer is already in the address book.

func (*API) IsPeerPersistent added in v0.3.0

func (api *API) IsPeerPersistent() bool

IsPeerPersistent returns whether the connected peer has a stable identity.

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) RefreshContacts added in v0.3.0

func (api *API) RefreshContacts()

RefreshContacts takes a snapshot of the address book for index-based access.

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) RemoveContact added in v0.3.0

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

RemoveContact removes a contact by fingerprint.

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) SaveCurrentPeerAsContact added in v0.3.0

func (api *API) SaveCurrentPeerAsContact(name string) error

SaveCurrentPeerAsContact saves the connected peer as a named contact.

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 address for local mode. It also enables local mode: no relay, TOFU handshake.

func (*API) SetStrictMode

func (api *API) SetStrictMode(enabled bool)

SetStrictMode toggles strict mode, which blocks the 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 starts the LAN presence broadcast and peer listener. It also enables local mode, so connections skip the relay.

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.

func (*API) ToggleIncognito added in v0.3.0

func (api *API) ToggleIncognito(incognito bool) (string, error)

ToggleIncognito switches between persistent and ephemeral identity. Returns the new fingerprint string.

func (*API) UnshareFile added in v0.3.0

func (api *API) UnshareFile(name string) error

UnshareFile removes a file from the shared list without deleting from disk.

type OpStatus

type OpStatus struct {
	Status  string
	Message string
}

OpStatus is the result of GetOpStatus(). Exported fields and simple types keep it gomobile-safe.

Jump to

Keyboard shortcuts

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