Backend: abstract version information
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -62,4 +62,19 @@ public interface Backend {
|
||||
* @return The updated state of the tunnel.
|
||||
*/
|
||||
State setState(Tunnel tunnel, State state) throws Exception;
|
||||
|
||||
/**
|
||||
* Determine version of underlying backend.
|
||||
*
|
||||
* @return The version of the backend.
|
||||
* @throws Exception
|
||||
*/
|
||||
String getVersion() throws Exception;
|
||||
|
||||
/**
|
||||
* Determine type name of underlying backend.
|
||||
*
|
||||
* @return Type name
|
||||
*/
|
||||
String getTypeName();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,11 @@ public final class GoBackend implements Backend {
|
||||
|
||||
private static native String wgVersion();
|
||||
|
||||
public static String getVersion() { return wgVersion(); }
|
||||
@Override
|
||||
public String getVersion() { return wgVersion(); }
|
||||
|
||||
@Override
|
||||
public String getTypeName() { return "Go userspace"; }
|
||||
|
||||
@Override
|
||||
public Config applyConfig(final Tunnel tunnel, final Config config) throws Exception {
|
||||
|
||||
@@ -13,8 +13,6 @@ import com.wireguard.android.Application;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
import com.wireguard.android.model.Tunnel.State;
|
||||
import com.wireguard.android.model.Tunnel.Statistics;
|
||||
import com.wireguard.android.util.RootShell;
|
||||
import com.wireguard.android.util.ToolsInstaller;
|
||||
import com.wireguard.config.Config;
|
||||
|
||||
import java.io.File;
|
||||
@@ -41,6 +39,18 @@ public final class WgQuickBackend implements Backend {
|
||||
localTemporaryDir = new File(context.getCacheDir(), "tmp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() throws Exception {
|
||||
final List<String> output = new ArrayList<>();
|
||||
if (Application.getRootShell()
|
||||
.run(output, "cat /sys/module/wireguard/version") != 0 || output.isEmpty())
|
||||
throw new Exception("Unable to determine kernel module version");
|
||||
return output.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() { return "Kernel module"; }
|
||||
|
||||
@Override
|
||||
public Config applyConfig(final Tunnel tunnel, final Config config) throws Exception {
|
||||
if (tunnel.getState() == State.UP) {
|
||||
|
||||
Reference in New Issue
Block a user