aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
blob: 9b57233e37f4d590c6b6a9f4352711981700ac69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package org.pacien.tincapp.commands

import org.pacien.tincapp.context.AppPaths
import java.io.IOException

/**
 * @author pacien
 */
object Tinc {

    private fun newCommand(netName: String): Command =
            Command(AppPaths.tinc().absolutePath)
                    .withOption("config", AppPaths.confDir(netName).absolutePath)
                    .withOption("pidfile", AppPaths.pidFile(netName).absolutePath)

    @Throws(IOException::class)
    fun stop(netName: String) {
        Executor.call(newCommand(netName).withArguments("stop"))
    }

    @Throws(IOException::class)
    fun dumpNodes(netName: String, reachable: Boolean = false): List<String> =
            Executor.call(
                    if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes")
                    else newCommand(netName).withArguments("dump", "nodes"))

    @Throws(IOException::class)
    fun info(netName: String, node: String): String =
            Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n")

}