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