|
YAACC - UPNP Client and Server
|
One TCP connection to one FCast receiver, protocol v3 (docs/tech.md, "FCast"; design.md, section 1). More...


Classes | |
| enum | CloseReason |
| Why a connection ended. More... | |
| class | Config |
| The times and sizes, injectable so tests do not wait. | |
| interface | Listener |
| Receives what the connection learns, in order, on one thread. More... | |
Public Member Functions | |
| FCastConnection (InetSocketAddress target, Listener listener, Config config, MonotonicClock clock, String senderName, String appName, String appVersion) | |
| void | connect () throws IOException |
| Connects and starts the threads; the connection is usable when this returns. | |
| InetSocketAddress | getTarget () |
| The receiver's address. | |
| int | getPeerVersion () |
| The version the receiver announced (1 or more), 0 while it has not said. | |
| int | getNegotiatedVersion () |
The version this connection speaks: the smaller of the receiver's and FCastMessages#MAX_VERSION; 3 until the receiver said. | |
| FCastPin.Source | getPinSource () |
| Where the pinned key came from, or null if the connection is not secured. | |
| boolean | isSecure () |
| True if this connection runs inside TLS 1.3 (protocol v4, pinned key). | |
| boolean | isClosed () |
| boolean | send (FCastOpcode opcode, String body) throws FCastProtocolException |
| Queues a message for the receiver. | |
| boolean | sendV4 (byte[] message) throws FCastProtocolException |
| Queues a message that only version 4 has (tracks, subtitles). | |
| void | close () |
Closes the connection; the listener gets onClosed(CLOSED_BY_US). | |
| boolean | awaitTermination (long millis) throws InterruptedException |
| For tests and for an orderly exit: waits until all threads of this connection ended. | |
Static Public Attributes | |
| static final int | MIN_SDK_FOR_V4 = 29 |
The first Android API level with TLS 1.3 in SSLContext (no TLS provider library is added, D3). | |
One TCP connection to one FCast receiver, protocol v3 (docs/tech.md, "FCast"; design.md, section 1).
Handshake. connect() connects (with a timeout) and sends Version 3 at once without waiting for the receiver's (both reference receivers expect the sender's first). The receiver's Version is only an upper bound: the connection speaks the smaller number (getNegotiatedVersion()); a receiver of version 4 is spoken to in 3, and this class never sends Version 4 (the desktop receiver would switch to TLS). Our own Initial follows the receiver's Version (or initialWaitMillis without one) and only if the connection speaks 3: a receiver of version 1 or 2 never gets an opcode it does not have (task 2.4). Until the receiver's Version is known the connection assumes 3.
Threads. One reader thread (it answers a Ping with a Pong before anything else, so a slow listener can not make the receiver drop us), one writer thread with a bounded queue (a receiver that stops reading can not make memory grow: the queue is full, the connection is closed with WRITE_OVERFLOW; a single write that blocks longer than writeTimeoutMillis closes it with WRITE_TIMEOUT), one dispatcher thread that calls the Listener in order (bounded as well: FLOOD), and one watchdog thread (heartbeat, write timeout, the late Initial). All are daemon threads and end when the connection is closed (awaitTermination).
Version 1. A receiver of version 1 has no Ping, so it is never pinged and silence does not end the connection (a failing socket does).
Errors. A framing error (size 0, over 32000 bytes, truncated) ends the connection; a body that does not parse is dropped and logged, the connection goes on; an opcode that is not known is skipped.
| de.yaacc.fcast.protocol.FCastConnection.FCastConnection | ( | InetSocketAddress | target, |
| Listener | listener, | ||
| Config | config, | ||
| MonotonicClock | clock, | ||
| String | senderName, | ||
| String | appName, | ||
| String | appVersion ) |
| target | the receiver's address |
| listener | receives the messages |
| config | times and sizes |
| clock | the time source (monotonic) |
| senderName | the name sent in Initial (displayName) |
| appName | sent in Initial |
| appVersion | sent in Initial |
| boolean de.yaacc.fcast.protocol.FCastConnection.awaitTermination | ( | long | millis | ) | throws InterruptedException |
For tests and for an orderly exit: waits until all threads of this connection ended.
| void de.yaacc.fcast.protocol.FCastConnection.close | ( | ) |
Closes the connection; the listener gets onClosed(CLOSED_BY_US).
Safe to call again.
| void de.yaacc.fcast.protocol.FCastConnection.connect | ( | ) | throws IOException |
Connects and starts the threads; the connection is usable when this returns.
Blocking: not for the main thread.
| IOException | if the receiver can not be reached within connectTimeoutMillis |
Referenced by de.yaacc.fcast.protocol.FCastSession.connectorFor().


| boolean de.yaacc.fcast.protocol.FCastConnection.send | ( | FCastOpcode | opcode, |
| String | body ) throws FCastProtocolException |
Queues a message for the receiver.
Never blocks.
| opcode | a command opcode (Play, Pause, Resume, Stop, Seek, SetVolume, SetSpeed, SetPlaylistItem, event subscriptions) of the negotiated version |
| body | the JSON text or null |
| FCastProtocolException | UNSUPPORTED if the receiver's version does not have the opcode (say a SetSpeed to a version 1 receiver), TOO_LARGE if the message does not fit into a packet |

| boolean de.yaacc.fcast.protocol.FCastConnection.sendV4 | ( | byte[] | message | ) | throws FCastProtocolException |
Queues a message that only version 4 has (tracks, subtitles).
Never blocks.
| message | a serialized Packet made by the v4 writer |
| FCastProtocolException | UNSUPPORTED on a connection that is not version 4 |
