diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands/Tinc.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index 9b57233..120525d 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -1,7 +1,7 @@ | |||
1 | package org.pacien.tincapp.commands | 1 | package org.pacien.tincapp.commands |
2 | 2 | ||
3 | import java8.util.concurrent.CompletableFuture | ||
3 | import org.pacien.tincapp.context.AppPaths | 4 | import org.pacien.tincapp.context.AppPaths |
4 | import java.io.IOException | ||
5 | 5 | ||
6 | /** | 6 | /** |
7 | * @author pacien | 7 | * @author pacien |
@@ -13,19 +13,29 @@ object Tinc { | |||
13 | .withOption("config", AppPaths.confDir(netName).absolutePath) | 13 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) | 14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) |
15 | 15 | ||
16 | @Throws(IOException::class) | 16 | fun stop(netName: String): CompletableFuture<Unit> = |
17 | fun stop(netName: String) { | 17 | Executor.call(newCommand(netName).withArguments("stop")) |
18 | Executor.call(newCommand(netName).withArguments("stop")) | 18 | .thenApply { } |
19 | } | ||
20 | 19 | ||
21 | @Throws(IOException::class) | 20 | fun dumpNodes(netName: String, reachable: Boolean = false): CompletableFuture<List<String>> = |
22 | fun dumpNodes(netName: String, reachable: Boolean = false): List<String> = | ||
23 | Executor.call( | 21 | Executor.call( |
24 | if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") | 22 | if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") |
25 | else newCommand(netName).withArguments("dump", "nodes")) | 23 | else newCommand(netName).withArguments("dump", "nodes")) |
26 | 24 | ||
27 | @Throws(IOException::class) | 25 | fun info(netName: String, node: String): CompletableFuture<String> = |
28 | fun info(netName: String, node: String): String = | 26 | Executor.call(newCommand(netName).withArguments("info", node)) |
29 | Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n") | 27 | .thenApply<String> { it.joinToString("\n") } |
28 | |||
29 | fun init(netName: String): CompletableFuture<String> = | ||
30 | Executor.call(Command(AppPaths.tinc().absolutePath) | ||
31 | .withOption("config", AppPaths.confDir(netName).absolutePath) | ||
32 | .withArguments("init", netName)) | ||
33 | .thenApply<String> { it.joinToString("\n") } | ||
34 | |||
35 | fun join(netName: String, invitationUrl: String): CompletableFuture<String> = | ||
36 | Executor.call(Command(AppPaths.tinc().absolutePath) | ||
37 | .withOption("config", AppPaths.confDir(netName).absolutePath) | ||
38 | .withArguments("join", invitationUrl)) | ||
39 | .thenApply<String> { it.joinToString("\n") } | ||
30 | 40 | ||
31 | } | 41 | } |