WgQuickBackend: Inline resolveState()

Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
Samuel Holland 2018-01-08 23:14:07 -06:00
parent 1cfb938dd1
commit ba30d46e08

View File

@ -35,12 +35,6 @@ public final class WgQuickBackend implements Backend {
this.rootShell = rootShell; this.rootShell = rootShell;
} }
private static State resolveState(final State currentState, State requestedState) {
if (requestedState == State.TOGGLE)
requestedState = currentState == State.UP ? State.DOWN : State.UP;
return requestedState;
}
@Override @Override
public Config applyConfig(final Tunnel tunnel, final Config config) { public Config applyConfig(final Tunnel tunnel, final Config config) {
if (tunnel.getState() == State.UP) if (tunnel.getState() == State.UP)
@ -74,14 +68,15 @@ public final class WgQuickBackend implements Backend {
} }
@Override @Override
public State setState(final Tunnel tunnel, final State state) throws Exception { public State setState(final Tunnel tunnel, State state) throws Exception {
Log.v(TAG, "Requested state change to " + state + " for tunnel " + tunnel.getName()); Log.v(TAG, "Requested state change to " + state + " for tunnel " + tunnel.getName());
final State originalState = getState(tunnel); final State originalState = getState(tunnel);
final State resolvedState = resolveState(originalState, state); if (state == State.TOGGLE)
if (resolvedState == originalState) state = originalState == State.UP ? State.DOWN : State.UP;
if (state == originalState)
return originalState; return originalState;
final int result; final int result;
if (resolvedState == State.UP) { if (state == State.UP) {
if (!new File("/sys/module/wireguard").exists()) if (!new File("/sys/module/wireguard").exists())
throw new ErrnoException("WireGuard module not loaded", OsConstants.ENODEV); throw new ErrnoException("WireGuard module not loaded", OsConstants.ENODEV);
// FIXME: Assumes file layout from FileConfigStore. Use a temporary file. // FIXME: Assumes file layout from FileConfigStore. Use a temporary file.