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 | 33 |
1 files changed, 16 insertions, 17 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 eb5689a..91a2678 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -1,6 +1,5 @@ | |||
1 | package org.pacien.tincapp.commands | 1 | package org.pacien.tincapp.commands |
2 | 2 | ||
3 | import android.content.Context | ||
4 | import org.pacien.tincapp.context.AppPaths | 3 | import org.pacien.tincapp.context.AppPaths |
5 | import java.io.IOException | 4 | import java.io.IOException |
6 | 5 | ||
@@ -9,22 +8,22 @@ import java.io.IOException | |||
9 | */ | 8 | */ |
10 | object Tinc { | 9 | object Tinc { |
11 | 10 | ||
12 | private fun newCommand(ctx: Context, netName: String): Command = | 11 | private fun newCommand(netName: String): Command = |
13 | Command(AppPaths.tinc(ctx).absolutePath) | 12 | Command(AppPaths.tinc().absolutePath) |
14 | .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) | 13 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
15 | .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) | 14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) |
16 | 15 | ||
17 | // independently runnable commands | 16 | // independently runnable commands |
18 | 17 | ||
19 | @Throws(IOException::class) | 18 | @Throws(IOException::class) |
20 | fun network(ctx: Context): List<String> = | 19 | fun network(): List<String> = |
21 | Executor.call(Command(AppPaths.tinc(ctx).absolutePath) | 20 | Executor.call(Command(AppPaths.tinc().absolutePath) |
22 | .withOption("config", AppPaths.confDir(ctx).absolutePath) | 21 | .withOption("config", AppPaths.confDir().absolutePath) |
23 | .withArguments("network")) | 22 | .withArguments("network")) |
24 | 23 | ||
25 | @Throws(IOException::class) | 24 | @Throws(IOException::class) |
26 | fun fsck(ctx: Context, netName: String, fix: Boolean): List<String> { | 25 | fun fsck(netName: String, fix: Boolean): List<String> { |
27 | var cmd = newCommand(ctx, netName).withArguments("fsck") | 26 | var cmd = newCommand(netName).withArguments("fsck") |
28 | if (fix) cmd = cmd.withOption("force") | 27 | if (fix) cmd = cmd.withOption("force") |
29 | return Executor.call(cmd) | 28 | return Executor.call(cmd) |
30 | } | 29 | } |
@@ -32,18 +31,18 @@ object Tinc { | |||
32 | // commands requiring a running tinc daemon | 31 | // commands requiring a running tinc daemon |
33 | 32 | ||
34 | @Throws(IOException::class) | 33 | @Throws(IOException::class) |
35 | fun stop(ctx: Context, netName: String) { | 34 | fun stop(netName: String) { |
36 | Executor.call(newCommand(ctx, netName).withArguments("stop")) | 35 | Executor.call(newCommand(netName).withArguments("stop")) |
37 | } | 36 | } |
38 | 37 | ||
39 | @Throws(IOException::class) | 38 | @Throws(IOException::class) |
40 | fun dumpNodes(ctx: Context, netName: String, reachable: Boolean): List<String> = | 39 | fun dumpNodes(netName: String, reachable: Boolean): List<String> = |
41 | Executor.call( | 40 | Executor.call( |
42 | if (reachable) newCommand(ctx, netName).withArguments("dump", "reachable", "nodes") | 41 | if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") |
43 | else newCommand(ctx, netName).withArguments("dump", "nodes")) | 42 | else newCommand(netName).withArguments("dump", "nodes")) |
44 | 43 | ||
45 | @Throws(IOException::class) | 44 | @Throws(IOException::class) |
46 | fun info(ctx: Context, netName: String, node: String): String = | 45 | fun info(netName: String, node: String): String = |
47 | Executor.call(newCommand(ctx, netName).withArguments("info", node)).joinToString("\n") | 46 | Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n") |
48 | 47 | ||
49 | } | 48 | } |