new: add tunnel service for windows and linux

This commit is contained in:
Hiddify
2024-02-02 17:35:32 +01:00
parent c344191293
commit e56e67bd44
6 changed files with 188 additions and 22 deletions

View File

@@ -159,11 +159,16 @@ class ConnectionRepositoryImpl
await $(
TaskEither(() async {
if (options.enableTun) {
final hasPrivilege = await platformSource.checkPrivilege();
if (!hasPrivilege) {
loggy.warning("missing privileges for tun mode");
final active = await platformSource.activateTunnel();
if (!active) {
loggy.warning("Possiblity missing privileges for tun mode");
return left(const MissingPrivilege());
}
// final hasPrivilege = await platformSource.checkPrivilege();
// if (!hasPrivilege) {
// loggy.warning("missing privileges for tun mode");
// return left(const MissingPrivilege());
// }
}
return right(unit);
}),
@@ -185,10 +190,35 @@ class ConnectionRepositoryImpl
@override
TaskEither<ConnectionFailure, Unit> disconnect() {
return exceptionHandler(
() => singbox.stop().mapLeft(UnexpectedConnectionFailure.new).run(),
UnexpectedConnectionFailure.new,
);
return TaskEither<ConnectionFailure, Unit>.Do(
($) async {
final options = await $(getConfigOption());
await $(
TaskEither(() async {
if (options.enableTun) {
final active = await platformSource.deactivateTunnel();
if (!active) {
loggy.warning("Possiblity missing privileges for tun mode");
return left(const MissingPrivilege());
}
// final hasPrivilege = await platformSource.checkPrivilege();
// if (!hasPrivilege) {
// loggy.warning("missing privileges for tun mode");
// return left(const MissingPrivilege());
// }
}
return right(unit);
}),
);
return await $(
singbox.stop()
.mapLeft(UnexpectedConnectionFailure.new),
);
},
).handleExceptions(UnexpectedConnectionFailure.new);
}
@override