briar-headless: Address first round of review comments

This commit is contained in:
Torsten Grote
2018-09-20 17:32:32 -03:00
parent 4b5e9bd64f
commit c12cedc371
5 changed files with 26 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ or to develop your own user interface for it.
## How to use ## How to use
The REST API client comes as a `jar` file 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. It currently works only on GNU/Linux operating systems.
You can start the client (and its API server) like this: 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" \ --header "Sec-WebSocket-Version: 13" \
http://DZbfoUie8sjap7CSDR9y6cgJCojV+xUITTIFbgtAgqk=@127.0.0.1:7000/v1/ws 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 ### Receiving new private messages
When the Briar client receives a new private message, When the Briar client receives a new private message,

View File

@@ -26,7 +26,7 @@ constructor(
if (!accountManager.accountExists()) { if (!accountManager.accountExists()) {
createAccount() createAccount()
} else { } else {
val password = prompt("Password") val password = prompt("Password", hideInput = true)
?: throw UsageError("Could not get password. Is STDIN connected?") ?: throw UsageError("Could not get password. Is STDIN connected?")
if (!accountManager.signIn(password)) { if (!accountManager.signIn(password)) {
echo("Error: Password invalid") echo("Error: Password invalid")
@@ -49,11 +49,12 @@ constructor(
throw UsageError("Please choose a shorter nickname!") throw UsageError("Please choose a shorter nickname!")
nickname nickname
} }
val password = prompt("Password") { password -> val password =
if (passwordStrengthEstimator.estimateStrength(password) < QUITE_WEAK) prompt("Password", hideInput = true, requireConfirmation = true) { password ->
throw UsageError("Please enter a stronger password!") if (passwordStrengthEstimator.estimateStrength(password) < QUITE_WEAK)
password throw UsageError("Please enter a stronger password!")
} password
}
if (nickname == null || password == null) if (nickname == null || password == null)
throw UsageError("Could not get account information. Is STDIN connected?") throw UsageError("Could not get account information. Is STDIN connected?")
accountManager.createAccount(nickname, password) accountManager.createAccount(nickname, password)

View File

@@ -109,7 +109,7 @@ internal class HeadlessModule(private val appDir: File) {
@Provides @Provides
@Singleton @Singleton
internal fun provideWebSocketHandler( internal fun provideWebSocketController(
webSocketController: WebSocketControllerImpl webSocketController: WebSocketControllerImpl
): WebSocketController { ): WebSocketController {
return webSocketController return webSocketController

View File

@@ -40,7 +40,6 @@ constructor(
.port(port) .port(port)
.disableStartupBanner() .disableStartupBanner()
.enableCaseSensitiveUrls() .enableCaseSensitiveUrls()
.enableRouteOverview("/")
.event(SERVER_START_FAILED) { stop() } .event(SERVER_START_FAILED) { stop() }
.event(SERVER_STOPPED) { stop() } .event(SERVER_STOPPED) { stop() }
if (debug) app.enableDebugLogging() if (debug) app.enableDebugLogging()

View File

@@ -2,7 +2,12 @@ package org.briarproject.briar.headless.event
import io.javalin.json.JavalinJson.toJson import io.javalin.json.JavalinJson.toJson
import io.javalin.websocket.WsSession 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.concurrent.ConcurrentHashMap
import java.util.logging.Level
import java.util.logging.Logger
import javax.annotation.concurrent.Immutable import javax.annotation.concurrent.Immutable
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@@ -12,12 +17,20 @@ import javax.inject.Singleton
internal class WebSocketControllerImpl @Inject constructor() : internal class WebSocketControllerImpl @Inject constructor() :
WebSocketController { WebSocketController {
private val logger: Logger = Logger.getLogger(this.javaClass.name)
override val sessions: MutableSet<WsSession> = ConcurrentHashMap.newKeySet<WsSession>() override val sessions: MutableSet<WsSession> = ConcurrentHashMap.newKeySet<WsSession>()
override fun sendEvent(name: String, obj: Any) { override fun sendEvent(name: String, obj: Any) {
sessions.forEach { session -> sessions.forEach { session ->
val event = OutputEvent(name, obj) 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)
}
} }
} }