briar-headless: Address first round of review comments

parent 4b5e9bd6
......@@ -8,7 +8,7 @@ or to develop your own user interface for it.
## How to use
The REST API client comes as a `jar` file
and needs a Java Runtime Environment (JRE).
and needs a Java Runtime Environment (JRE) that supports at least Java 8.
It currently works only on GNU/Linux operating systems.
You can start the client (and its API server) like this:
......@@ -152,6 +152,9 @@ You can test connecting to the websocket with curl:
--header "Sec-WebSocket-Version: 13" \
http://DZbfoUie8sjap7CSDR9y6cgJCojV+xUITTIFbgtAgqk=@127.0.0.1:7000/v1/ws
The headers are only required when testing with curl.
Your websocket client will most likely add these headers automatically.
### Receiving new private messages
When the Briar client receives a new private message,
......
......@@ -26,7 +26,7 @@ constructor(
if (!accountManager.accountExists()) {
createAccount()
} else {
val password = prompt("Password")
val password = prompt("Password", hideInput = true)
?: throw UsageError("Could not get password. Is STDIN connected?")
if (!accountManager.signIn(password)) {
echo("Error: Password invalid")
......@@ -49,11 +49,12 @@ constructor(
throw UsageError("Please choose a shorter nickname!")
nickname
}
val password = prompt("Password") { password ->
if (passwordStrengthEstimator.estimateStrength(password) < QUITE_WEAK)
throw UsageError("Please enter a stronger password!")
password
}
val password =
prompt("Password", hideInput = true, requireConfirmation = true) { password ->
if (passwordStrengthEstimator.estimateStrength(password) < QUITE_WEAK)
throw UsageError("Please enter a stronger password!")
password
}
if (nickname == null || password == null)
throw UsageError("Could not get account information. Is STDIN connected?")
accountManager.createAccount(nickname, password)
......
......@@ -109,7 +109,7 @@ internal class HeadlessModule(private val appDir: File) {
@Provides
@Singleton
internal fun provideWebSocketHandler(
internal fun provideWebSocketController(
webSocketController: WebSocketControllerImpl
): WebSocketController {
return webSocketController
......
......@@ -40,7 +40,6 @@ constructor(
.port(port)
.disableStartupBanner()
.enableCaseSensitiveUrls()
.enableRouteOverview("/")
.event(SERVER_START_FAILED) { stop() }
.event(SERVER_STOPPED) { stop() }
if (debug) app.enableDebugLogging()
......
......@@ -2,7 +2,12 @@ package org.briarproject.briar.headless.event
import io.javalin.json.JavalinJson.toJson
import io.javalin.websocket.WsSession
import org.briarproject.bramble.util.LogUtils.logException
import org.eclipse.jetty.websocket.api.WebSocketException
import java.io.IOException
import java.util.concurrent.ConcurrentHashMap
import java.util.logging.Level
import java.util.logging.Logger
import javax.annotation.concurrent.Immutable
import javax.inject.Inject
import javax.inject.Singleton
......@@ -12,12 +17,20 @@ import javax.inject.Singleton
internal class WebSocketControllerImpl @Inject constructor() :
WebSocketController {
private val logger: Logger = Logger.getLogger(this.javaClass.name)
override val sessions: MutableSet<WsSession> = ConcurrentHashMap.newKeySet<WsSession>()
override fun sendEvent(name: String, obj: Any) {
sessions.forEach { session ->
val event = OutputEvent(name, obj)
session.send(toJson(event))
try {
session.send(toJson(event))
} catch (e: WebSocketException) {
logException(logger, Level.WARNING, e)
} catch (e: IOException) {
logException(logger, Level.WARNING, e)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment