dwrtc / ch.hsr.dsl.dwrtc.util

Package ch.hsr.dsl.dwrtc.util

Various bits and pieces

TomP2P Extension Classes

To easier work with TomP2P's Futures in Kotlin, this projects includes a few extension classes.

They are documented in place, but need this bit of documentation to tie them all together

Note, that all these classes employ TomP2P semantics. Think of these as a very thin layer upon TomP2P. E.g., a failure is only raised when no connection can be made. An empty response is no failure to TomP2P. To work more nicely with those responses, have a look at the higher-level Future classes.

BaseFuture extension classes: these work on all Futures that TomP2P returns

FutureGet extension classes work on all Get operations that TomP2P returns. Also includes all BaseFuture extensions.

These fire on BaseFuture's onComplete. Therefore, the success status still needs to be checked.

These methods differ by these orthogonal concepts:

Extensions for External Classes

net.tomp2p.dht.FutureGet

net.tomp2p.futures.BaseFuture

Properties

BOOTSTRAP_PEER

val BOOTSTRAP_PEER: Key<List<String>>

The list of peers to bootstrap to. Comma-separated list of "HOST:PORT"

PACKED_RESOURCES

val PACKED_RESOURCES: Key<Boolean>

Build variable. Pack the resources in the JAR (otherwise, load from file system)

PEER_PORT

val PEER_PORT: Key<Int>

The port the TomP2P peer runs on

WEBSERVER_IP

val WEBSERVER_IP: Key<String>

The IP the Webserver binds to

WEBSERVER_PORT

val WEBSERVER_PORT: Key<Int>

The port the Webserver runs on

config

val config: Configuration

The configuration object, defining the priorities in which configuration is read

Functions

buildNewPeer

fun buildNewPeer(id: String = UUID.randomUUID().toString(), port: Int = findFreePort()): PeerDHT

Build a new peer

findFreePort

fun findFreePort(): Int

Find a free port

jsonTo

fun <OutputType> jsonTo(jsonString: String): OutputType

Convert JSON to OutputType

toJson

fun toJson(message: Any): String

Convert to JSON