diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands/Tinc.java')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tinc.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.java b/app/src/main/java/org/pacien/tincapp/commands/Tinc.java new file mode 100644 index 0000000..ca11698 --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.java | |||
@@ -0,0 +1,60 @@ | |||
1 | package org.pacien.tincapp.commands; | ||
2 | |||
3 | import android.content.Context; | ||
4 | |||
5 | import com.annimon.stream.Stream; | ||
6 | |||
7 | import org.pacien.tincapp.context.AppPaths; | ||
8 | |||
9 | import java.io.IOException; | ||
10 | import java.util.List; | ||
11 | |||
12 | /** | ||
13 | * @author pacien | ||
14 | */ | ||
15 | final public class Tinc { | ||
16 | |||
17 | private Tinc() { | ||
18 | // static class | ||
19 | } | ||
20 | |||
21 | static private Command newCommand(Context ctx, String netName) { | ||
22 | return new Command(AppPaths.tinc(ctx).getAbsolutePath()) | ||
23 | .withOption("config", AppPaths.confDir(ctx, netName).getAbsolutePath()) | ||
24 | .withOption("pidfile", AppPaths.pidFile(ctx, netName).getAbsolutePath()); | ||
25 | } | ||
26 | |||
27 | // independently runnable commands | ||
28 | |||
29 | static public List<String> network(Context ctx) throws IOException { | ||
30 | return Executor.call(new Command(AppPaths.tinc(ctx).getAbsolutePath()) | ||
31 | .withOption("config", AppPaths.confDir(ctx).getAbsolutePath()) | ||
32 | .withArguments("network")); | ||
33 | } | ||
34 | |||
35 | static public List<String> fsck(Context ctx, String netName, Boolean fix) throws IOException { | ||
36 | Command cmd = newCommand(ctx, netName).withArguments("fsck"); | ||
37 | if (fix) cmd = cmd.withOption("force"); | ||
38 | return Executor.call(cmd); | ||
39 | } | ||
40 | |||
41 | // commands requiring a running tinc daemon | ||
42 | |||
43 | static public void stop(Context ctx, String netName) throws IOException { | ||
44 | Executor.call(newCommand(ctx, netName).withArguments("stop")); | ||
45 | } | ||
46 | |||
47 | static public List<String> dumpNodes(Context ctx, String netName, Boolean reachable) throws IOException { | ||
48 | Command cmd = reachable | ||
49 | ? newCommand(ctx, netName).withArguments("dump", "reachable", "nodes") | ||
50 | : newCommand(ctx, netName).withArguments("dump", "nodes"); | ||
51 | |||
52 | return Executor.call(cmd); | ||
53 | } | ||
54 | |||
55 | static public String info(Context ctx, String netName, String node) throws IOException { | ||
56 | List<String> output = Executor.call(newCommand(ctx, netName).withArguments("info", node)); | ||
57 | return Stream.of(output).reduce((l, r) -> l + '\n' + r).get(); | ||
58 | } | ||
59 | |||
60 | } | ||