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 | 70 |
1 files changed, 35 insertions, 35 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 6acd4f2..0b1240a 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -8,40 +8,40 @@ import org.pacien.tincapp.context.AppPaths | |||
8 | */ | 8 | */ |
9 | object Tinc { | 9 | object Tinc { |
10 | 10 | ||
11 | private fun newCommand(netName: String): Command = | 11 | private fun newCommand(netName: String): Command = |
12 | Command(AppPaths.tinc().absolutePath) | 12 | Command(AppPaths.tinc().absolutePath) |
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 | fun stop(netName: String): CompletableFuture<Unit> = | 16 | fun stop(netName: String): CompletableFuture<Unit> = |
17 | Executor.call(newCommand(netName).withArguments("stop")) | 17 | Executor.call(newCommand(netName).withArguments("stop")) |
18 | .thenApply { } | 18 | .thenApply { } |
19 | 19 | ||
20 | fun dumpNodes(netName: String, reachable: Boolean = false): CompletableFuture<List<String>> = | 20 | fun dumpNodes(netName: String, reachable: Boolean = false): CompletableFuture<List<String>> = |
21 | Executor.call( | 21 | Executor.call( |
22 | if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") | 22 | if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") |
23 | else newCommand(netName).withArguments("dump", "nodes")) | 23 | else newCommand(netName).withArguments("dump", "nodes")) |
24 | 24 | ||
25 | fun info(netName: String, node: String): CompletableFuture<String> = | 25 | fun info(netName: String, node: String): CompletableFuture<String> = |
26 | Executor.call(newCommand(netName).withArguments("info", node)) | 26 | Executor.call(newCommand(netName).withArguments("info", node)) |
27 | .thenApply<String> { it.joinToString("\n") } | 27 | .thenApply<String> { it.joinToString("\n") } |
28 | 28 | ||
29 | fun init(netName: String, nodeName: String): CompletableFuture<String> = | 29 | fun init(netName: String, nodeName: String): CompletableFuture<String> = |
30 | if (netName.isBlank()) | 30 | if (netName.isBlank()) |
31 | CompletableFuture.failedFuture(IllegalArgumentException("Network name cannot be blank.")) | 31 | CompletableFuture.failedFuture(IllegalArgumentException("Network name cannot be blank.")) |
32 | else | 32 | else |
33 | Executor.call(Command(AppPaths.tinc().absolutePath) | 33 | Executor.call(Command(AppPaths.tinc().absolutePath) |
34 | .withOption("config", AppPaths.confDir(netName).absolutePath) | 34 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
35 | .withArguments("init", nodeName)) | 35 | .withArguments("init", nodeName)) |
36 | .thenApply<String> { it.joinToString("\n") } | 36 | .thenApply<String> { it.joinToString("\n") } |
37 | 37 | ||
38 | fun join(netName: String, invitationUrl: String): CompletableFuture<String> = | 38 | fun join(netName: String, invitationUrl: String): CompletableFuture<String> = |
39 | if (netName.isBlank()) | 39 | if (netName.isBlank()) |
40 | CompletableFuture.failedFuture(IllegalArgumentException("Network name cannot be blank.")) | 40 | CompletableFuture.failedFuture(IllegalArgumentException("Network name cannot be blank.")) |
41 | else | 41 | else |
42 | Executor.call(Command(AppPaths.tinc().absolutePath) | 42 | Executor.call(Command(AppPaths.tinc().absolutePath) |
43 | .withOption("config", AppPaths.confDir(netName).absolutePath) | 43 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
44 | .withArguments("join", invitationUrl)) | 44 | .withArguments("join", invitationUrl)) |
45 | .thenApply<String> { it.joinToString("\n") } | 45 | .thenApply<String> { it.joinToString("\n") } |
46 | 46 | ||
47 | } | 47 | } |