mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
remove _socksSocket
This commit is contained in:
parent
0522d2a0ee
commit
d8f41cccaf
1 changed files with 13 additions and 48 deletions
|
@ -79,11 +79,7 @@ class JsonRPC {
|
||||||
_requestQueue.nextIncompleteReq.then((req) {
|
_requestQueue.nextIncompleteReq.then((req) {
|
||||||
if (req != null) {
|
if (req != null) {
|
||||||
// \r\n required by electrumx server
|
// \r\n required by electrumx server
|
||||||
if (_socksSocket != null) {
|
_socket!.write('${req.jsonRequest}\r\n');
|
||||||
_socksSocket!.write('${req.jsonRequest}\r\n');
|
|
||||||
} else {
|
|
||||||
_socket!.write('${req.jsonRequest}\r\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO different timeout length?
|
// TODO different timeout length?
|
||||||
req.initiateTimeout(
|
req.initiateTimeout(
|
||||||
|
@ -100,7 +96,7 @@ class JsonRPC {
|
||||||
Duration requestTimeout,
|
Duration requestTimeout,
|
||||||
) async {
|
) async {
|
||||||
await _requestMutex.protect(() async {
|
await _requestMutex.protect(() async {
|
||||||
if (_socket == null && _socksSocket == null) {
|
if (_socket == null) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"JsonRPC request: opening socket $host:$port",
|
"JsonRPC request: opening socket $host:$port",
|
||||||
level: LogLevel.Info,
|
level: LogLevel.Info,
|
||||||
|
@ -154,49 +150,11 @@ class JsonRPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> connect() async {
|
Future<void> connect() async {
|
||||||
if (Prefs.instance.useTor) {
|
if (_socket != null) {
|
||||||
if (_socksSocket != null) {
|
throw Exception(
|
||||||
Logging.instance.log(
|
"JsonRPC attempted to connect to an already existing socket!",
|
||||||
"JsonRPC.connect(): JsonRPC attempted to connect to an already existing tor socket!",
|
|
||||||
level: LogLevel.Error);
|
|
||||||
throw Exception(
|
|
||||||
"JsonRPC attempted to connect to an already existing tor socket!",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (proxyInfo == null) {
|
|
||||||
// TODO await tor / make sure it's running
|
|
||||||
proxyInfo = (
|
|
||||||
host: InternetAddress.loopbackIPv4.address,
|
|
||||||
port: TorService.sharedInstance.port
|
|
||||||
);
|
|
||||||
Logging.instance.log(
|
|
||||||
"ElectrumX.connect(): no tor proxy info, read $proxyInfo",
|
|
||||||
level: LogLevel.Warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
final InternetAddress _host =
|
|
||||||
await InternetAddress.lookup(host).then((value) => value.first);
|
|
||||||
_socksSocket = await SocksTCPClient.connect(
|
|
||||||
[
|
|
||||||
ProxySettings(
|
|
||||||
InternetAddress.loopbackIPv4,
|
|
||||||
proxyInfo!.port,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
_host,
|
|
||||||
port,
|
|
||||||
);
|
);
|
||||||
if (_socksSocket == null) {
|
}
|
||||||
Logging.instance.log(
|
|
||||||
"JsonRPC.connect(): failed to connect to $host over tor proxy at $proxyInfo",
|
|
||||||
level: LogLevel.Error);
|
|
||||||
throw Exception("JsonRPC.connect(): failed to connect to tor proxy");
|
|
||||||
} else {
|
|
||||||
Logging.instance.log(
|
|
||||||
"JsonRPC.connect(): connected to $host over tor proxy at $proxyInfo",
|
|
||||||
level: LogLevel.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Prefs.instance.useTor) {
|
if (Prefs.instance.useTor) {
|
||||||
if (proxyInfo == null) {
|
if (proxyInfo == null) {
|
||||||
|
@ -269,6 +227,13 @@ class JsonRPC {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_subscription = _socket!.listen(
|
||||||
|
_dataHandler,
|
||||||
|
onError: _errorHandler,
|
||||||
|
onDone: _doneHandler,
|
||||||
|
cancelOnError: true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue