Make TunnelManager the point of asynchronicity

Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
Samuel Holland
2018-01-07 00:24:56 -06:00
parent 5a2f692d73
commit be8b6017d5
6 changed files with 125 additions and 154 deletions
@@ -7,61 +7,53 @@ import com.wireguard.config.Config;
import java.util.Set;
import java9.util.concurrent.CompletionStage;
/**
* Interface for implementations of the WireGuard secure network tunnel.
*/
public interface Backend {
/**
* Update the volatile configuration of a running tunnel, asynchronously, and return the
* resulting configuration. If the tunnel is not up, return the configuration that would result
* (if known), or else simply return the given configuration.
* Update the volatile configuration of a running tunnel and return the resulting configuration.
* If the tunnel is not up, return the configuration that would result (if known), or else
* simply return the given configuration.
*
* @param tunnel The tunnel to apply the configuration to.
* @param config The new configuration for this tunnel.
* @return A future completed when the configuration of the tunnel has been updated, and the new
* volatile configuration has been determined. This future will always be completed on the main
* thread.
* @return The updated configuration of the tunnel.
*/
CompletionStage<Config> applyConfig(Tunnel tunnel, Config config);
Config applyConfig(Tunnel tunnel, Config config) throws Exception;
/**
* Enumerate the names of currently-running tunnels.
*
* @return A future completed when the set of running tunnel names is available. This future
* will always be completed on the main thread.
* @return The set of running tunnel names.
*/
CompletionStage<Set<String>> enumerate();
Set<String> enumerate() throws Exception;
/**
* Get the actual state of a tunnel, asynchronously.
* Get the actual state of a tunnel.
*
* @param tunnel The tunnel to examine the state of.
* @return A future completed when the state of the tunnel has been determined. This future will
* always be completed on the main thread.
* @return The state of the tunnel.
*/
CompletionStage<State> getState(Tunnel tunnel);
State getState(Tunnel tunnel) throws Exception;
/**
* Get statistics about traffic and errors on this tunnel, asynchronously. If the tunnel is not
* running, the statistics object will be filled with zero values.
* Get statistics about traffic and errors on this tunnel. If the tunnel is not running, the
* statistics object will be filled with zero values.
*
* @param tunnel The tunnel to retrieve statistics for.
* @return A future completed when statistics for the tunnel are available. This future will
* always be completed on the main thread.
* @return The statistics for the tunnel.
*/
CompletionStage<Statistics> getStatistics(Tunnel tunnel);
Statistics getStatistics(Tunnel tunnel) throws Exception;
/**
* Set the state of a tunnel, asynchronously.
* Set the state of a tunnel.
*
* @param tunnel The tunnel to control the state of.
* @param state The new state for this tunnel. Must be {@code UP}, {@code DOWN}, or
* {@code TOGGLE}.
* @return A future completed when the state of the tunnel has changed, containing the new state
* of the tunnel. This future will always be completed on the main thread.
* @return The updated state of the tunnel.
*/
CompletionStage<State> setState(Tunnel tunnel, State state);
State setState(Tunnel tunnel, State state) throws Exception;
}