mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-21 22:58:49 +00:00
add a status getter to the tor service and document it
This commit is contained in:
parent
6b76696edf
commit
5cf202efc0
1 changed files with 32 additions and 2 deletions
|
@ -10,12 +10,29 @@ final pTorService = Provider((_) => TorService.sharedInstance);
|
||||||
|
|
||||||
class TorService {
|
class TorService {
|
||||||
final _tor = Tor();
|
final _tor = Tor();
|
||||||
|
|
||||||
|
/// Flag to indicate that a Tor circuit is thought to have been established.
|
||||||
bool _enabled = false;
|
bool _enabled = false;
|
||||||
|
|
||||||
|
/// Getter for the enabled flag.
|
||||||
|
bool get enabled => _enabled;
|
||||||
|
|
||||||
|
/// The current status of the Tor connection.
|
||||||
|
TorConnectionStatus _status = TorConnectionStatus.disconnected;
|
||||||
|
|
||||||
|
/// Getter for the status.
|
||||||
|
///
|
||||||
|
/// Used mostly to indicate "Connected" status in the UI.
|
||||||
|
TorConnectionStatus get status => _status;
|
||||||
|
|
||||||
TorService._();
|
TorService._();
|
||||||
|
|
||||||
|
/// Singleton instance of the TorService.
|
||||||
|
///
|
||||||
|
/// Use this to access the TorService and its properties.
|
||||||
static final sharedInstance = TorService._();
|
static final sharedInstance = TorService._();
|
||||||
|
|
||||||
|
/// Getter for the proxyInfo.
|
||||||
({
|
({
|
||||||
InternetAddress host,
|
InternetAddress host,
|
||||||
int port,
|
int port,
|
||||||
|
@ -24,9 +41,17 @@ class TorService {
|
||||||
port: _tor.port,
|
port: _tor.port,
|
||||||
);
|
);
|
||||||
|
|
||||||
bool get enabled => _enabled;
|
/// Start the Tor service.
|
||||||
|
///
|
||||||
|
/// This will start the Tor service and establish a Tor circuit.
|
||||||
|
///
|
||||||
|
/// Throws an exception if the Tor service fails to start.
|
||||||
|
///
|
||||||
|
/// Returns a Future that completes when the Tor service has started.
|
||||||
Future<void> start() async {
|
Future<void> start() async {
|
||||||
|
// Set the status to connecting.
|
||||||
|
_status = TorConnectionStatus.connecting;
|
||||||
|
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
// already started so just return
|
// already started so just return
|
||||||
// could throw an exception here or something so the caller
|
// could throw an exception here or something so the caller
|
||||||
|
@ -35,6 +60,7 @@ class TorService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start the Tor service.
|
||||||
try {
|
try {
|
||||||
GlobalEventBus.instance.fire(
|
GlobalEventBus.instance.fire(
|
||||||
TorConnectionStatusChangedEvent(
|
TorConnectionStatusChangedEvent(
|
||||||
|
@ -69,6 +95,9 @@ class TorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> stop() async {
|
Future<void> stop() async {
|
||||||
|
// Set the status to disconnected.
|
||||||
|
_status = TorConnectionStatus.disconnected;
|
||||||
|
|
||||||
if (!_enabled) {
|
if (!_enabled) {
|
||||||
// already stopped so just return
|
// already stopped so just return
|
||||||
// could throw an exception here or something so the caller
|
// could throw an exception here or something so the caller
|
||||||
|
@ -77,6 +106,7 @@ class TorService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop the Tor service.
|
||||||
try {
|
try {
|
||||||
await _tor.disable();
|
await _tor.disable();
|
||||||
// no exception or error so we can (probably?) assume tor
|
// no exception or error so we can (probably?) assume tor
|
||||||
|
|
Loading…
Reference in a new issue