YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.snapcast.discovery.SnapcastDirectory Class Reference

The snapservers YAACC knows: the ones found by mDNS and the ones the user typed in, merged by control endpoint (ServerKey). More...

Collaboration diagram for de.yaacc.snapcast.discovery.SnapcastDirectory:
Collaboration graph

Classes

class  Entry
 One server of the list.
 
interface  Listener
 Told when the list of servers changed; called on the thread that made the change, without a lock held. More...
 

Public Member Functions

 SnapcastDirectory (MonotonicClock clock, long graceMillis)
 
void addListener (Listener listener)
 
void removeListener (Listener listener)
 
boolean serviceFound (String serviceName, InetAddress address, int port)
 A service was found and resolved; its name is both its identity and its display text.
 
boolean serviceFound (String serviceId, String serviceName, InetAddress address, int port)
 A service was found and resolved, with an identity of its own: the same name under two service types (a server of Snapcast 0.32 announces its control port twice, see SnapcastServiceTypes) is two services, so the loss of one does not drop the server while the other is still announced.
 
void serviceLost (String serviceName)
 A service is gone (a "lost" event names only the service; the id is the one given to serviceFound).
 
void discoveryRestarted ()
 Discovery starts again (the receivers page came back): nothing is known to be announced until it is seen again, so every discovered entry that is not manual starts its grace period now.
 
void discoveryStopped ()
 Discovery is switched off (the setting, or no page is visible and it is not wanted): nothing is announced any more as far as this list can know.
 
int setManualServers (Collection< ServerEndpoint > endpoints)
 Replaces the manual servers.
 
int setRememberedServers (Collection< ServerEndpoint > endpoints)
 Replaces the remembered servers: the servers that hold a selected group, kept from an earlier run so that the selection can be reconnected.
 
boolean expire ()
 Removes the servers whose grace period is over.
 
List< Entry > servers ()
 The servers, sorted by key (a stable order).
 
List< Entry > snapshot ()
 Like servers(), but quiet: servers past their grace period are left out instead of being removed, and no listener is called.
 
Entry find (ServerKey key)
 

Static Public Attributes

static final int MAX_SERVERS = ManualServers.MAX_SERVERS
 The most servers listed (discovered and manual together).
 
static final int MAX_SERVICE_NAMES = 32
 The most service names remembered, so that a flood of names does not grow the directory.
 
static final long DEFAULT_GRACE_MILLIS = 30_000L
 How long a lost server stays listed.
 
static final int MIN_DISCOVERED_PORT = 1024
 The lowest port taken from an announcement.
 

Detailed Description

The snapservers YAACC knows: the ones found by mDNS and the ones the user typed in, merged by control endpoint (ServerKey).

Pure and thread safe; the clock is injected.

  • Merge. One endpoint is one entry, however often and under however many service names it is seen, and whether it was found or typed. (A manual entry written as a host name is a different endpoint from the address mDNS reports; to merge them, type the address.)
  • Loss. When the last service name of a discovered entry is lost, the entry stays for a grace period (so that a server that restarts, or an mDNS hiccup, does not make its receivers flicker out of the list and out of the stored selection) and is then removed. A sighting inside the grace period cancels the loss. A manual entry is never removed by what discovery does.
  • Remembered. The server of a selected group is remembered across a restart (setRememberedServers): it is listed from the start, without being announced, and is not aged out by time (nothing is scanned outside the page lifetime, so nothing could confirm it). When discovery starts again it gets the same grace as any discovered entry: seen in that time it stays, otherwise it goes.
  • Cap. At most MAX_SERVERS entries. A lost entry makes room first; manual entries may also take the place of a discovered one, never the other way round.
  • Trust. A discovered address must pass AddressFilter. Service names come from the network: they are kept to match "lost" events and as display text (cleaned and cut), never as an identity.

Member Function Documentation

◆ discoveryStopped()

void de.yaacc.snapcast.discovery.SnapcastDirectory.discoveryStopped ( )

Discovery is switched off (the setting, or no page is visible and it is not wanted): nothing is announced any more as far as this list can know.

A server that only discovery knew goes at once (its grace period is for a hiccup, not for a switch); a typed-in or remembered server stays, and stays for good: it is no longer waiting for a sighting that can not come, so the grace period it got when the scan began is cancelled.

◆ expire()

boolean de.yaacc.snapcast.discovery.SnapcastDirectory.expire ( )

Removes the servers whose grace period is over.

Returns
true if the list changed

◆ find()

Entry de.yaacc.snapcast.discovery.SnapcastDirectory.find ( ServerKey key)
Returns
the entry for the key, or null

◆ servers()

List< Entry > de.yaacc.snapcast.discovery.SnapcastDirectory.servers ( )

The servers, sorted by key (a stable order).

Servers past their grace period are not in it.

Referenced by de.yaacc.snapcast.SnapcastSelectedServers.selectionChanged().

Here is the caller graph for this function:

◆ serviceFound() [1/2]

boolean de.yaacc.snapcast.discovery.SnapcastDirectory.serviceFound ( String serviceId,
String serviceName,
InetAddress address,
int port )

A service was found and resolved, with an identity of its own: the same name under two service types (a server of Snapcast 0.32 announces its control port twice, see SnapcastServiceTypes) is two services, so the loss of one does not drop the server while the other is still announced.

The name is display text only.

Parameters
serviceIdwhat serviceLost(String) will be given; see SnapcastServiceTypes#serviceId
serviceNamethe name the network gave the service
Returns
as serviceFound(String, InetAddress, int)
Here is the call graph for this function:

◆ serviceFound() [2/2]

boolean de.yaacc.snapcast.discovery.SnapcastDirectory.serviceFound ( String serviceName,
InetAddress address,
int port )

A service was found and resolved; its name is both its identity and its display text.

Returns
true if the server is listed now (new or already known), false if it was refused: an address outside the local ranges, a port outside {@value MIN_DISCOVERED_PORT} to 65535, no or an oversized service name, or the list is full

Referenced by de.yaacc.snapcast.discovery.SnapcastDirectory.serviceFound().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setManualServers()

int de.yaacc.snapcast.discovery.SnapcastDirectory.setManualServers ( Collection< ServerEndpoint > endpoints)

Replaces the manual servers.

An entry that is no longer on the list but is still announced stays as a discovered one; otherwise it goes at once.

Returns
how many of the given servers are listed (the list may hold MAX_SERVERS at most)

Referenced by de.yaacc.snapcast.SnapcastHub.pageStarted(), and de.yaacc.snapcast.SnapcastHub.wake().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRememberedServers()

int de.yaacc.snapcast.discovery.SnapcastDirectory.setRememberedServers ( Collection< ServerEndpoint > endpoints)

Replaces the remembered servers: the servers that hold a selected group, kept from an earlier run so that the selection can be reconnected.

Only an endpoint with an address that passes AddressFilter is taken (a remembered server was discovered once, so it was filtered then; it is filtered again, a stored value is not trusted). A remembered server is listed at once and does not age out by time; when the list is full it takes only the place of a lost entry (a server that is announced or typed in is never pushed out). One that is no longer remembered goes unless it is announced or typed in.

Returns
how many of the given servers are remembered now

Referenced by de.yaacc.snapcast.SnapcastSelectedServers.forget(), de.yaacc.snapcast.SnapcastSelectedServers.restore(), and de.yaacc.snapcast.SnapcastSelectedServers.selectionChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ snapshot()

List< Entry > de.yaacc.snapcast.discovery.SnapcastDirectory.snapshot ( )

Like servers(), but quiet: servers past their grace period are left out instead of being removed, and no listener is called.

For code that holds a lock of its own and must not run foreign code under it; whoever calls servers(), expire() or any change later sweeps the left-out entries and tells the listeners.

Member Data Documentation

◆ MIN_DISCOVERED_PORT

final int de.yaacc.snapcast.discovery.SnapcastDirectory.MIN_DISCOVERED_PORT = 1024
static

The lowest port taken from an announcement.

Any host of the network (or an app on the phone) can announce a service, and a port below 1024 is never a Snapcast control port in practice (the default is 1705): the phone would be made to open connections to system services (security review S18). A server the user types in may use any port.

Referenced by de.yaacc.snapcast.discovery.SnapcastDirectory.serviceFound().


The documentation for this class was generated from the following file: