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

@@ -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)

View File

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

View File

@@ -40,7 +40,6 @@ constructor(
.port(port)
.disableStartupBanner()
.enableCaseSensitiveUrls()
.enableRouteOverview("/")
.event(SERVER_START_FAILED) { stop() }
.event(SERVER_STOPPED) { stop() }
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.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)
}
}
}