mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Last code cleanup before submitting merge request
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
package org.briarproject.bramble.account;
|
||||
|
||||
import org.briarproject.bramble.api.account.AccountManager;
|
||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
class HeadlessAccountManager extends AccountManagerImpl
|
||||
implements AccountManager {
|
||||
|
||||
@Inject
|
||||
HeadlessAccountManager(DatabaseConfig databaseConfig,
|
||||
CryptoComponent crypto, IdentityManager identityManager) {
|
||||
super(databaseConfig, crypto, identityManager);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.briarproject.bramble.account;
|
||||
|
||||
import org.briarproject.bramble.api.account.AccountManager;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class HeadlessAccountModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
AccountManager provideAccountManager(HeadlessAccountManager accountManager) {
|
||||
return accountManager;
|
||||
}
|
||||
}
|
||||
@@ -15,3 +15,7 @@ data class OutputAuthor(
|
||||
publicKey = author.publicKey
|
||||
)
|
||||
}
|
||||
|
||||
fun Author.output() = OutputAuthor(this)
|
||||
|
||||
fun Author.Status.output() = name.toLowerCase()
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package org.briarproject.briar.headless;
|
||||
|
||||
import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
||||
import org.briarproject.bramble.BrambleCoreModule;
|
||||
import org.briarproject.bramble.account.HeadlessAccountModule;
|
||||
import org.briarproject.bramble.system.DesktopSecureRandomModule;
|
||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||
import org.briarproject.briar.BriarCoreModule;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
|
||||
@Component(modules = {
|
||||
BrambleCoreModule.class,
|
||||
BriarCoreModule.class,
|
||||
DesktopSecureRandomModule.class,
|
||||
HeadlessAccountModule.class,
|
||||
HeadlessModule.class
|
||||
})
|
||||
@Singleton
|
||||
public interface BriarHeadlessApp
|
||||
extends BrambleCoreEagerSingletons, BriarCoreEagerSingletons {
|
||||
Router router();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.briar.headless
|
||||
|
||||
import dagger.Component
|
||||
import org.briarproject.bramble.BrambleCoreEagerSingletons
|
||||
import org.briarproject.bramble.BrambleCoreModule
|
||||
import org.briarproject.bramble.account.AccountModule
|
||||
import org.briarproject.bramble.system.DesktopSecureRandomModule
|
||||
import org.briarproject.briar.BriarCoreEagerSingletons
|
||||
import org.briarproject.briar.BriarCoreModule
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Component(
|
||||
modules = [
|
||||
BrambleCoreModule::class,
|
||||
BriarCoreModule::class,
|
||||
DesktopSecureRandomModule::class,
|
||||
AccountModule::class,
|
||||
HeadlessModule::class
|
||||
]
|
||||
)
|
||||
@Singleton
|
||||
internal interface BriarHeadlessApp : BrambleCoreEagerSingletons, BriarCoreEagerSingletons {
|
||||
fun router(): Router
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import javax.inject.Singleton
|
||||
|
||||
@Immutable
|
||||
@Singleton
|
||||
class BriarService @Inject
|
||||
internal class BriarService @Inject
|
||||
constructor(
|
||||
private val accountManager: AccountManager,
|
||||
private val lifecycleManager: LifecycleManager,
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.briarproject.briar.headless
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author
|
||||
import org.briarproject.bramble.identity.OutputAuthor
|
||||
import org.briarproject.briar.api.blog.MessageType
|
||||
|
||||
fun Author.output() = OutputAuthor(this)
|
||||
|
||||
fun Author.Status.output() = name.toLowerCase()
|
||||
|
||||
fun MessageType.output() = name.toLowerCase()
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.briarproject.briar.headless;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@NotNullByDefault
|
||||
class HeadlessDatabaseConfig implements DatabaseConfig {
|
||||
|
||||
private final File dbDir, keyDir;
|
||||
|
||||
HeadlessDatabaseConfig(File dbDir, File keyDir) {
|
||||
this.dbDir = dbDir;
|
||||
this.keyDir = keyDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDatabaseDirectory() {
|
||||
return dbDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDatabaseKeyDirectory() {
|
||||
return keyDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxSize() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.headless
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig
|
||||
import java.io.File
|
||||
import java.lang.Long.MAX_VALUE
|
||||
|
||||
internal class HeadlessDatabaseConfig(private val dbDir: File, private val keyDir: File) :
|
||||
DatabaseConfig {
|
||||
|
||||
override fun getDatabaseDirectory(): File {
|
||||
return dbDir
|
||||
}
|
||||
|
||||
override fun getDatabaseKeyDirectory(): File {
|
||||
return keyDir
|
||||
}
|
||||
|
||||
override fun getMaxSize(): Long {
|
||||
return MAX_VALUE
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ import javax.net.SocketFactory
|
||||
MessagingModule::class
|
||||
]
|
||||
)
|
||||
class HeadlessModule(private val appDir: File) {
|
||||
internal class HeadlessModule(private val appDir: File) {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.logging.LogManager
|
||||
private const val DEFAULT_PORT = 7000
|
||||
private val DEFAULT_DATA_DIR = getProperty("user.home") + separator + ".briar"
|
||||
|
||||
class Main : CliktCommand(
|
||||
private class Main : CliktCommand(
|
||||
name = "briar-headless",
|
||||
help = "A Briar client without GUI that exposes a REST and Websocket API"
|
||||
) {
|
||||
@@ -61,7 +61,7 @@ class Main : CliktCommand(
|
||||
1 -> INFO
|
||||
else -> ALL
|
||||
}
|
||||
setProperty(DEFAULT_LOG_LEVEL_KEY, levelSlf4j);
|
||||
setProperty(DEFAULT_LOG_LEVEL_KEY, levelSlf4j)
|
||||
LogManager.getLogManager().getLogger("").level = level
|
||||
|
||||
val dataDir = getDataDir()
|
||||
@@ -84,11 +84,11 @@ class Main : CliktCommand(
|
||||
} else if (!file.isDirectory) {
|
||||
throw IOException("Data dir is not a directory: ${file.absolutePath}")
|
||||
}
|
||||
val perms = HashSet<PosixFilePermission>();
|
||||
perms.add(OWNER_READ);
|
||||
perms.add(OWNER_WRITE);
|
||||
perms.add(OWNER_EXECUTE);
|
||||
setPosixFilePermissions(file.toPath(), perms);
|
||||
val perms = HashSet<PosixFilePermission>()
|
||||
perms.add(OWNER_READ)
|
||||
perms.add(OWNER_WRITE)
|
||||
perms.add(OWNER_EXECUTE)
|
||||
setPosixFilePermissions(file.toPath(), perms)
|
||||
return file
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import kotlin.system.exitProcess
|
||||
|
||||
@Immutable
|
||||
@Singleton
|
||||
class Router @Inject
|
||||
internal class Router @Inject
|
||||
constructor(
|
||||
private val briarService: BriarService,
|
||||
private val webSocketController: WebSocketController,
|
||||
|
||||
@@ -24,7 +24,6 @@ internal class WebSocketControllerImpl @Inject constructor() : WebSocketControll
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@Suppress("unused")
|
||||
internal class OutputEvent(val name: String, val data: Any) {
|
||||
val type = "event"
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package org.briarproject.briar.headless.blogs
|
||||
|
||||
import org.briarproject.briar.api.blog.BlogPostHeader
|
||||
|
||||
internal fun BlogPostHeader.output(body: String) = OutputBlogPost(this, body)
|
||||
@@ -1,8 +1,9 @@
|
||||
package org.briarproject.briar.headless.blogs
|
||||
|
||||
import org.briarproject.bramble.identity.OutputAuthor
|
||||
import org.briarproject.bramble.identity.output
|
||||
import org.briarproject.briar.api.blog.BlogPostHeader
|
||||
import org.briarproject.briar.headless.output
|
||||
import org.briarproject.briar.api.blog.MessageType
|
||||
import javax.annotation.concurrent.Immutable
|
||||
|
||||
@Immutable
|
||||
@@ -31,3 +32,7 @@ internal data class OutputBlogPost(
|
||||
timestampReceived = header.timeReceived
|
||||
)
|
||||
}
|
||||
|
||||
internal fun BlogPostHeader.output(body: String) = OutputBlogPost(this, body)
|
||||
|
||||
internal fun MessageType.output() = name.toLowerCase()
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package org.briarproject.briar.headless.contact
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact
|
||||
|
||||
internal fun Contact.output() = OutputContact(this)
|
||||
@@ -2,7 +2,7 @@ package org.briarproject.briar.headless.contact
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact
|
||||
import org.briarproject.bramble.identity.OutputAuthor
|
||||
import org.briarproject.briar.headless.output
|
||||
import org.briarproject.bramble.identity.output
|
||||
import javax.annotation.concurrent.Immutable
|
||||
|
||||
@Immutable
|
||||
@@ -17,3 +17,5 @@ internal data class OutputContact(
|
||||
verified = c.isVerified
|
||||
)
|
||||
}
|
||||
|
||||
internal fun Contact.output() = OutputContact(this)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.briarproject.briar.headless.forums
|
||||
|
||||
import org.briarproject.briar.api.forum.Forum
|
||||
|
||||
internal fun Forum.output() = OutputForum(this)
|
||||
|
||||
internal fun Collection<Forum>.output() = map { it.output() }
|
||||
@@ -13,3 +13,7 @@ internal data class OutputForum(
|
||||
id = forum.id.bytes
|
||||
)
|
||||
}
|
||||
|
||||
internal fun Forum.output() = OutputForum(this)
|
||||
|
||||
internal fun Collection<Forum>.output() = map { it.output() }
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.briarproject.briar.headless.messaging
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId
|
||||
import org.briarproject.briar.api.introduction.IntroductionRequest
|
||||
import org.briarproject.briar.api.introduction.IntroductionResponse
|
||||
import org.briarproject.briar.api.messaging.PrivateMessage
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader
|
||||
import org.briarproject.briar.api.messaging.PrivateRequest
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse
|
||||
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
|
||||
import org.briarproject.briar.api.sharing.InvitationRequest
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse
|
||||
|
||||
internal fun PrivateMessageHeader.output(
|
||||
contactId: ContactId,
|
||||
body: String?
|
||||
) = OutputPrivateMessageHeader(this, contactId, body)
|
||||
|
||||
internal fun PrivateMessage.output(contactId: ContactId, body: String) =
|
||||
OutputPrivateMessageHeader(this, contactId, body)
|
||||
|
||||
internal fun PrivateMessageReceivedEvent<*>.output(body: String) =
|
||||
messageHeader.output(contactId, body)
|
||||
|
||||
internal fun IntroductionRequest.output(contactId: ContactId) =
|
||||
OutputIntroductionRequest(this, contactId)
|
||||
|
||||
internal fun PrivateRequest<*>.output(contactId: ContactId): OutputPrivateMessage {
|
||||
return when (this) {
|
||||
is IntroductionRequest -> OutputIntroductionRequest(this, contactId)
|
||||
is InvitationRequest -> OutputInvitationRequest(this, contactId)
|
||||
else -> throw AssertionError("Unknown PrivateRequest")
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PrivateResponse.output(contactId: ContactId): OutputPrivateMessage {
|
||||
return when (this) {
|
||||
is IntroductionResponse -> OutputIntroductionResponse(this, contactId)
|
||||
is InvitationResponse -> OutputInvitationResponse(this, contactId)
|
||||
else -> throw AssertionError("Unknown PrivateResponse")
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.headless.messaging
|
||||
import org.briarproject.bramble.api.contact.ContactId
|
||||
import org.briarproject.briar.api.messaging.PrivateMessage
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader
|
||||
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
|
||||
import javax.annotation.concurrent.Immutable
|
||||
|
||||
@Immutable
|
||||
@@ -48,3 +49,14 @@ internal data class OutputPrivateMessageHeader(
|
||||
), contactId, body
|
||||
)
|
||||
}
|
||||
|
||||
internal fun PrivateMessageHeader.output(
|
||||
contactId: ContactId,
|
||||
body: String?
|
||||
) = OutputPrivateMessageHeader(this, contactId, body)
|
||||
|
||||
internal fun PrivateMessage.output(contactId: ContactId, body: String) =
|
||||
OutputPrivateMessageHeader(this, contactId, body)
|
||||
|
||||
internal fun PrivateMessageReceivedEvent<*>.output(body: String) =
|
||||
messageHeader.output(contactId, body)
|
||||
|
||||
@@ -46,3 +46,14 @@ internal data class OutputInvitationRequest(
|
||||
val canBeOpened get() = iHeader.canBeOpened()
|
||||
|
||||
}
|
||||
|
||||
internal fun PrivateRequest<*>.output(contactId: ContactId): OutputPrivateMessage {
|
||||
return when (this) {
|
||||
is IntroductionRequest -> OutputIntroductionRequest(this, contactId)
|
||||
is InvitationRequest -> OutputInvitationRequest(this, contactId)
|
||||
else -> throw AssertionError("Unknown PrivateRequest")
|
||||
}
|
||||
}
|
||||
|
||||
internal fun IntroductionRequest.output(contactId: ContactId) =
|
||||
OutputIntroductionRequest(this, contactId)
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
package org.briarproject.briar.headless.messaging
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId
|
||||
import org.briarproject.bramble.identity.output
|
||||
import org.briarproject.briar.api.blog.BlogInvitationResponse
|
||||
import org.briarproject.briar.api.forum.ForumInvitationResponse
|
||||
import org.briarproject.briar.api.introduction.IntroductionResponse
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse
|
||||
import org.briarproject.briar.headless.output
|
||||
import javax.annotation.concurrent.Immutable
|
||||
|
||||
@Immutable
|
||||
@@ -45,3 +45,11 @@ internal data class OutputInvitationResponse(
|
||||
}
|
||||
val shareableId: ByteArray get() = iHeader.shareableId.bytes
|
||||
}
|
||||
|
||||
internal fun PrivateResponse.output(contactId: ContactId): OutputPrivateMessage {
|
||||
return when (this) {
|
||||
is IntroductionResponse -> OutputIntroductionResponse(this, contactId)
|
||||
is InvitationResponse -> OutputInvitationResponse(this, contactId)
|
||||
else -> throw AssertionError("Unknown PrivateResponse")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user