руки переломаю
This commit is contained in:
@@ -190,6 +190,7 @@ Uint8List _lz4BlockDecompress(Uint8List src, int maxSize) {
|
||||
|
||||
if (pos >= src.length) break;
|
||||
|
||||
if (pos + 1 >= src.length) throw StateError('LZ4: unexpected end of input');
|
||||
final offset = src[pos] | (src[pos + 1] << 8);
|
||||
pos += 2;
|
||||
if (offset == 0) throw StateError('LZ4: offset = 0');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:komet/core/utils/logger.dart';
|
||||
@@ -72,10 +73,15 @@ class ProfileData {
|
||||
final profileOptionsStr = row['profile_options'] as String?;
|
||||
List<int>? profileOptions;
|
||||
if (profileOptionsStr != null && profileOptionsStr.isNotEmpty) {
|
||||
profileOptions = profileOptionsStr
|
||||
.split(',')
|
||||
.map((e) => int.parse(e.trim()))
|
||||
.toList();
|
||||
try {
|
||||
profileOptions = profileOptionsStr
|
||||
.split(',')
|
||||
.where((e) => e.trim().isNotEmpty)
|
||||
.map((e) => int.parse(e.trim()))
|
||||
.toList();
|
||||
} catch (_) {
|
||||
profileOptions = null;
|
||||
}
|
||||
}
|
||||
return ProfileData(
|
||||
id: row['id'] as int,
|
||||
@@ -130,8 +136,20 @@ class AppDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
static Completer<Database>? _initCompleter;
|
||||
|
||||
static Future<Database> get _instance async {
|
||||
_db ??= await _open();
|
||||
if (_db != null) return _db!;
|
||||
if (_initCompleter != null) return _initCompleter!.future;
|
||||
_initCompleter = Completer<Database>();
|
||||
try {
|
||||
_db = await _open();
|
||||
_initCompleter!.complete(_db!);
|
||||
} catch (e) {
|
||||
_initCompleter!.completeError(e);
|
||||
_initCompleter = null;
|
||||
rethrow;
|
||||
}
|
||||
return _db!;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class TokenStorage {
|
||||
static Future<String?> readActiveToken() async {
|
||||
final id = await getActiveAccountId();
|
||||
if (id == null) return null;
|
||||
return readToken(id);
|
||||
return await readToken(id);
|
||||
}
|
||||
|
||||
static Future<void> deleteAccount(int accountId) async {
|
||||
|
||||
@@ -99,7 +99,9 @@ class Connection {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (_) {}
|
||||
} catch (e) {
|
||||
logger.w('Ошибка при закрытии сокета: $e');
|
||||
}
|
||||
}
|
||||
|
||||
_setState(SocketState.disconnected);
|
||||
|
||||
@@ -60,8 +60,8 @@ class ProxyConnector {
|
||||
if (!useAuth) {
|
||||
throw SocketException('SOCKS5: прокси требует аутентификацию');
|
||||
}
|
||||
final usernameBytes = utf8.encode(settings.username!);
|
||||
final passwordBytes = utf8.encode(settings.password!);
|
||||
final usernameBytes = utf8.encode(settings.username ?? '');
|
||||
final passwordBytes = utf8.encode(settings.password ?? '');
|
||||
final authPacket = BytesBuilder()
|
||||
..addByte(0x01)
|
||||
..addByte(usernameBytes.length)
|
||||
@@ -175,7 +175,10 @@ class ProxyConnector {
|
||||
final responseStr = utf8.decode(headerBytes, allowMalformed: true);
|
||||
final statusLine = responseStr.split('\r\n').first;
|
||||
final parts = statusLine.split(' ');
|
||||
final statusCode = parts.length >= 2 ? int.tryParse(parts[1]) ?? 0 : 0;
|
||||
if (parts.length < 2) {
|
||||
throw SocketException('HTTP CONNECT: некорректный ответ: $statusLine');
|
||||
}
|
||||
final statusCode = int.tryParse(parts[1]) ?? 0;
|
||||
if (statusCode != 200) {
|
||||
throw SocketException(
|
||||
'HTTP CONNECT: прокси вернул статус $statusCode',
|
||||
@@ -201,10 +204,17 @@ class ProxyConnector {
|
||||
RawSocket proxySocket,
|
||||
_RawSocketIO io,
|
||||
) async {
|
||||
final server = await RawServerSocket.bind(
|
||||
InternetAddress.loopbackIPv4,
|
||||
0,
|
||||
);
|
||||
RawServerSocket? server;
|
||||
try {
|
||||
server = await RawServerSocket.bind(
|
||||
InternetAddress.loopbackIPv4,
|
||||
0,
|
||||
);
|
||||
} catch (e) {
|
||||
io.dispose();
|
||||
proxySocket.close();
|
||||
rethrow;
|
||||
}
|
||||
final clientSide = await RawSocket.connect(
|
||||
InternetAddress.loopbackIPv4,
|
||||
server.port,
|
||||
|
||||
@@ -8,7 +8,7 @@ class PacketSender {
|
||||
int get currentSeq => _seq;
|
||||
|
||||
int _nextSeq() {
|
||||
_seq = (_seq + 1) % 256;
|
||||
_seq = (_seq + 1) % 65536;
|
||||
return _seq;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user