mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-08 19:59:29 +00:00
simplify WIP code
removing unneeded logging. may as well be printing at this point
This commit is contained in:
parent
5cccd3e4a3
commit
1a59a1a577
2 changed files with 32 additions and 33 deletions
|
@ -39,6 +39,7 @@ class JsonRPC {
|
|||
Socket? _socket;
|
||||
SOCKSSocket? _socksSocket;
|
||||
StreamSubscription<Uint8List>? _subscription;
|
||||
StreamSubscription<Uint8List>? get subscription => _subscription;
|
||||
|
||||
void _dataHandler(List<int> data) {
|
||||
_requestQueue.nextIncompleteReq.then((req) {
|
||||
|
@ -85,6 +86,7 @@ class JsonRPC {
|
|||
_socket!.write('${req.jsonRequest}\r\n');
|
||||
}
|
||||
if (_socksSocket != null) {
|
||||
print(33333333);
|
||||
_socksSocket!.write('${req.jsonRequest}\r\n');
|
||||
}
|
||||
|
||||
|
@ -185,6 +187,13 @@ class JsonRPC {
|
|||
timeout: connectionTimeout,
|
||||
);
|
||||
}
|
||||
|
||||
_subscription = _socket!.listen(
|
||||
_dataHandler,
|
||||
onError: _errorHandler,
|
||||
onDone: _doneHandler,
|
||||
cancelOnError: true,
|
||||
);
|
||||
} else {
|
||||
if (proxyInfo == null) {
|
||||
// TODO await tor / make sure it's running
|
||||
|
@ -210,29 +219,7 @@ class JsonRPC {
|
|||
// } else {
|
||||
final sock = await RawSocket.connect(
|
||||
InternetAddress.loopbackIPv4, proxyInfo!.port);
|
||||
|
||||
if (_socksSocket == null) {
|
||||
Logging.instance.log(
|
||||
"JsonRPC.connect(): creating SOCKS socket at $proxyInfo",
|
||||
level: LogLevel.Info);
|
||||
_socksSocket = SOCKSSocket(sock);
|
||||
if (_socksSocket == null) {
|
||||
Logging.instance.log(
|
||||
"JsonRPC.connect(): failed to create SOCKS socket at $proxyInfo",
|
||||
level: LogLevel.Error);
|
||||
throw Exception(
|
||||
"JsonRPC.connect(): failed to create SOCKS socket at $proxyInfo");
|
||||
} else {
|
||||
Logging.instance.log(
|
||||
"JsonRPC.connect(): created SOCKS socket at $proxyInfo",
|
||||
level: LogLevel.Info);
|
||||
}
|
||||
} else {
|
||||
// TODO also check if sock == previous sock, eg. if RawSocket is different
|
||||
Logging.instance.log(
|
||||
"JsonRPC.connect(): using pre-existing SOCKS socket at $proxyInfo",
|
||||
level: LogLevel.Info);
|
||||
}
|
||||
_socksSocket = SOCKSSocket(sock);
|
||||
|
||||
try {
|
||||
Logging.instance.log(
|
||||
|
@ -253,14 +240,24 @@ class JsonRPC {
|
|||
throw Exception(
|
||||
"JsonRPC.connect(): failed to connect to tor proxy, $e");
|
||||
}
|
||||
}
|
||||
|
||||
_subscription = _socket!.listen(
|
||||
_dataHandler,
|
||||
onError: _errorHandler,
|
||||
onDone: _doneHandler,
|
||||
cancelOnError: true,
|
||||
);
|
||||
// _subscription = _socksSocket!.socket.listen(
|
||||
// _dataHandler,
|
||||
// onError: _errorHandler,
|
||||
// onDone: _doneHandler,
|
||||
// cancelOnError: true,
|
||||
// ) as StreamSubscription<Uint8List>?;
|
||||
|
||||
_socksSocket!.subscription.onData((RawSocketEvent event) {
|
||||
/// [RawSocketEvent] messages are here
|
||||
/// read from here..
|
||||
if (event == RawSocketEvent.read) {
|
||||
final data = sock.read(sock.available());
|
||||
print(11111);
|
||||
print(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ class SOCKSRequest {
|
|||
class SOCKSSocket {
|
||||
late List<AuthMethods> _auth;
|
||||
late RawSocket _sock;
|
||||
RawSocket get socket => _sock;
|
||||
late SOCKSRequest _request;
|
||||
|
||||
late StreamSubscription<RawSocketEvent> _sockSub;
|
||||
|
@ -380,15 +381,16 @@ class SOCKSSocket {
|
|||
req.port & 0xF0,
|
||||
];
|
||||
|
||||
//print(">> Version: ${req.version}, Command: ${req.command}, AddrType: ${req.addressType}, Addr: ${req.getAddressString()}, Port: ${req.port}");
|
||||
print(
|
||||
">> Version: ${req.version}, Command: ${req.command}, AddrType: ${req.addressType}, Addr: ${req.getAddressString()}, Port: ${req.port}");
|
||||
_sock.write(data);
|
||||
} else {
|
||||
throw "Must be in RequestReady state, current state $_state";
|
||||
}
|
||||
}
|
||||
|
||||
void write(Object? object) {
|
||||
_sock.write(utf8.encode(object.toString()));
|
||||
void write(String data) {
|
||||
_sock.write(utf8.encode(data));
|
||||
// TODO make sure the is correct; see _writeRequest above, may need to construct a SOCKSRequest from the data coming in
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue