mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-09 12:19:24 +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;
|
Socket? _socket;
|
||||||
SOCKSSocket? _socksSocket;
|
SOCKSSocket? _socksSocket;
|
||||||
StreamSubscription<Uint8List>? _subscription;
|
StreamSubscription<Uint8List>? _subscription;
|
||||||
|
StreamSubscription<Uint8List>? get subscription => _subscription;
|
||||||
|
|
||||||
void _dataHandler(List<int> data) {
|
void _dataHandler(List<int> data) {
|
||||||
_requestQueue.nextIncompleteReq.then((req) {
|
_requestQueue.nextIncompleteReq.then((req) {
|
||||||
|
@ -85,6 +86,7 @@ class JsonRPC {
|
||||||
_socket!.write('${req.jsonRequest}\r\n');
|
_socket!.write('${req.jsonRequest}\r\n');
|
||||||
}
|
}
|
||||||
if (_socksSocket != null) {
|
if (_socksSocket != null) {
|
||||||
|
print(33333333);
|
||||||
_socksSocket!.write('${req.jsonRequest}\r\n');
|
_socksSocket!.write('${req.jsonRequest}\r\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +187,13 @@ class JsonRPC {
|
||||||
timeout: connectionTimeout,
|
timeout: connectionTimeout,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_subscription = _socket!.listen(
|
||||||
|
_dataHandler,
|
||||||
|
onError: _errorHandler,
|
||||||
|
onDone: _doneHandler,
|
||||||
|
cancelOnError: true,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (proxyInfo == null) {
|
if (proxyInfo == null) {
|
||||||
// TODO await tor / make sure it's running
|
// TODO await tor / make sure it's running
|
||||||
|
@ -210,29 +219,7 @@ class JsonRPC {
|
||||||
// } else {
|
// } else {
|
||||||
final sock = await RawSocket.connect(
|
final sock = await RawSocket.connect(
|
||||||
InternetAddress.loopbackIPv4, proxyInfo!.port);
|
InternetAddress.loopbackIPv4, proxyInfo!.port);
|
||||||
|
_socksSocket = SOCKSSocket(sock);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
|
@ -253,14 +240,24 @@ class JsonRPC {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"JsonRPC.connect(): failed to connect to tor proxy, $e");
|
"JsonRPC.connect(): failed to connect to tor proxy, $e");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_subscription = _socket!.listen(
|
// _subscription = _socksSocket!.socket.listen(
|
||||||
_dataHandler,
|
// _dataHandler,
|
||||||
onError: _errorHandler,
|
// onError: _errorHandler,
|
||||||
onDone: _doneHandler,
|
// onDone: _doneHandler,
|
||||||
cancelOnError: true,
|
// 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 {
|
class SOCKSSocket {
|
||||||
late List<AuthMethods> _auth;
|
late List<AuthMethods> _auth;
|
||||||
late RawSocket _sock;
|
late RawSocket _sock;
|
||||||
|
RawSocket get socket => _sock;
|
||||||
late SOCKSRequest _request;
|
late SOCKSRequest _request;
|
||||||
|
|
||||||
late StreamSubscription<RawSocketEvent> _sockSub;
|
late StreamSubscription<RawSocketEvent> _sockSub;
|
||||||
|
@ -380,15 +381,16 @@ class SOCKSSocket {
|
||||||
req.port & 0xF0,
|
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);
|
_sock.write(data);
|
||||||
} else {
|
} else {
|
||||||
throw "Must be in RequestReady state, current state $_state";
|
throw "Must be in RequestReady state, current state $_state";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(Object? object) {
|
void write(String data) {
|
||||||
_sock.write(utf8.encode(object.toString()));
|
_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
|
// 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