Session

class Session

The entry point to the ouisync library.

Example usage

// Create a session and initialize networking:
val session = Session.create("path/to/config/dir")
session.initNetwork()
session.bind(quicV4 = "0.0.0.0:0", quicV6 = "[::]:0")

// ...

// When done, close it:
session.close()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun addUserProvidedPeer(addr: String)

Adds a peer to connect to.

Link copied to clipboard
suspend fun bindNetwork(quicV4: String? = null, quicV6: String? = null, tcpV4: String? = null, tcpV6: String? = null)

Binds the network listeners to the specified interfaces.

Link copied to clipboard
suspend fun close()

Closes the session.

Link copied to clipboard

Returns our Ouisync protocol version.

Link copied to clipboard

Returns the highest protocol version of all known peers. If this is higher than our version it likely means we are using an outdated version of Ouisync. When a peer with higher protocol version is found, a NetworkEvent.PROTOCOL_VERSION_MISMATCH is emitted.

Link copied to clipboard
suspend fun initNetwork(defaultPortForwardingEnabled: Boolean, defaultLocalDiscoveryEnabled: Boolean)

Initializes the network according to the stored config. If no config exists, falls back to the given parameters.

Link copied to clipboard

Is local discovery enabled?

Link copied to clipboard

Is port forwarding (UPnP) enabled?

Link copied to clipboard
suspend fun peers(): List<PeerInfo>

Returns info about all known peers (both discovered and explicitly added).

Link copied to clipboard

Returns the interface the QUIC IPv4 listener is bound to, if any.

Link copied to clipboard

Returns the interface the QUIC IPv6 listener is bound to, if any.

Link copied to clipboard
suspend fun removeUserProvidedPeer(addr: String)

Removes a peer previously added with addUserProvidedPeer

Link copied to clipboard
suspend fun setLocalDiscoveryEnabled(enabled: Boolean): Any?

Enable/disable local discovery

Link copied to clipboard
suspend fun setPortForwardingEnabled(enabled: Boolean): Any?

Enable/disable port forwarding (UPnP)

Link copied to clipboard

Subscribe to the network events.

Link copied to clipboard

Returns the interface the TCP IPv4 listener is bound to, if any.

Link copied to clipboard

Returns the interface the TCP IPv6 listener is bound to, if any.

Link copied to clipboard
suspend fun thisRuntimeId(): String

Returns the runtime id of this Ouisync instance.