EchoExtension

class EchoExtension(clock: () -> Long = System::currentTimeMillis) : TetherExtension(source)

x.tether.echo (protocol §7.9): link diagnostics on every side. A request {ts, data?} with an id is answered with {ts, data?, at, via}: the request's own timestamp and data back, the responder's clock and its transport. The asker gets the round trip and an estimate of the clock offset. Touches nothing but the link, so it is safe on a test transport and harmless to leave on.

Constructors

Link copied to clipboard
constructor(clock: () -> Long = System::currentTimeMillis)

Types

Link copied to clipboard
data class Result(val peer: String, val rttMs: Long, val offsetMs: Long, val via: String, val bytes: Int, val error: String? = null)

One answer: round trip, the responder's clock minus ours at the midpoint, its transport, the payload size.

Properties

Link copied to clipboard
open override val id: String

x.<reverse-dns>, for example x.com.example.battery; x.tether.* is reserved for this repository.

Link copied to clipboard
Link copied to clipboard

Every answer (the host's extension thread).

Link copied to clipboard
open val types: Set<String>

The message types it handles and sends: id itself or <id>.<name>.

Link copied to clipboard
open val versions: List<Int>

Major versions this build speaks; announced as <id>/<major> in caps.

Functions

Link copied to clipboard
open fun onLink(session: ExtensionSession, up: Boolean)

A peer that speaks a common version came (up) or went (link down, version withdrawn, extension switched off). A change between two common versions is no new up: ExtensionSession.version always tells the agreed one.

Link copied to clipboard
open override fun onMessage(session: ExtensionSession, message: Message)

A message of one of types from the peer, or an error answering a request this extension sent. A request carries id (answer with ExtensionSession.reply); an answer carries re.

Link copied to clipboard
fun ping(session: ExtensionSession, data: String? = null): Int?

Asks session's peer; the result arrives in onResult. Null when not sent (the peer does not speak echo).

Link copied to clipboard
open fun start(host: ExtensionHost)
Link copied to clipboard
open fun status(): JSONObject?

Optional fields for the Android phone's status.ext[id] (≤ 1 KiB encoded), or null. Phone only.

Link copied to clipboard
open fun stop()