Skip to content

Commit

Permalink
Merge pull request #876 from atsign-foundation/fix_pub_score
Browse files Browse the repository at this point in the history
fix: Fix pub score
  • Loading branch information
murali-shris authored Jan 10, 2023
2 parents efa077f + 4b2efd9 commit ce7b3eb
Show file tree
Hide file tree
Showing 23 changed files with 219 additions and 162 deletions.
2 changes: 1 addition & 1 deletion packages/at_client/lib/at_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export 'package:at_commons/at_commons.dart';
export 'package:at_client/src/listener/sync_progress_listener.dart';
@experimental
export 'package:at_client/src/telemetry/at_client_telemetry.dart';
export 'package:at_client/src/client/request_options.dart';
export 'package:at_client/src/client/request_options.dart';
79 changes: 41 additions & 38 deletions packages/at_client/lib/src/client/at_client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AtClientImpl implements AtClient {
RemoteSecondary? _remoteSecondary;

@override
// ignore: override_on_non_overriding_member
AtChops? _atChops;

EncryptionService? _encryptionService;
Expand Down Expand Up @@ -92,10 +93,10 @@ class AtClientImpl implements AtClient {
static Future<AtClient> create(
String currentAtSign, String? namespace, AtClientPreference preferences,
{AtClientManager? atClientManager,
RemoteSecondary? remoteSecondary,
EncryptionService? encryptionService,
SecondaryKeyStore? localSecondaryKeyStore,
AtChops? atChops}) async {
RemoteSecondary? remoteSecondary,
EncryptionService? encryptionService,
SecondaryKeyStore? localSecondaryKeyStore,
AtChops? atChops}) async {
currentAtSign = AtUtils.formatAtSign(currentAtSign)!;
if (atClientInstanceMap.containsKey(currentAtSign)) {
return atClientInstanceMap[currentAtSign];
Expand All @@ -118,9 +119,9 @@ class AtClientImpl implements AtClient {
AtClientImpl._(String atSign, String? namespace,
AtClientPreference preference, AtClientManager atClientManager,
{RemoteSecondary? remoteSecondary,
EncryptionService? encryptionService,
SecondaryKeyStore? localSecondaryKeyStore,
AtChops? atChops}) {
EncryptionService? encryptionService,
SecondaryKeyStore? localSecondaryKeyStore,
AtChops? atChops}) {
currentAtSign = AtUtils.formatAtSign(atSign);
_preference = preference;
_preference?.namespace ??= namespace;
Expand Down Expand Up @@ -223,17 +224,19 @@ class AtClientImpl implements AtClient {

Future<String?> getPrivateKey(String atSign) async {
var privateKeyData =
await getLocalSecondary()!.keyStore!.get(AT_PKAM_PRIVATE_KEY);
await getLocalSecondary()!.keyStore!.get(AT_PKAM_PRIVATE_KEY);
var privateKey = privateKeyData?.data;
return privateKey;
}

@override
Future<bool> delete(AtKey atKey, {bool isDedicated = false}) {
_telemetry?.controller.sink.add(AtTelemetryEvent('AtClient.delete called', {"key": atKey}));
_telemetry?.controller.sink
.add(AtTelemetryEvent('AtClient.delete called', {"key": atKey}));
// ignore: no_leading_underscores_for_local_identifiers
var _deleteResult = _delete(atKey);
_telemetry?.controller.sink.add(AtTelemetryEvent('AtClient.delete complete',{"key":atKey, "_deleteResult": _deleteResult}));
_telemetry?.controller.sink.add(AtTelemetryEvent('AtClient.delete complete',
{"key": atKey, "_deleteResult": _deleteResult}));
return _deleteResult;
}

Expand All @@ -251,7 +254,7 @@ class AtClientImpl implements AtClient {
..isLocal = atKey.isLocal
..isCached = atKey.metadata!.isCached
..isPublic =
(atKey.metadata!.isPublic == null) ? false : atKey.metadata!.isPublic!
(atKey.metadata!.isPublic == null) ? false : atKey.metadata!.isPublic!
..sharedWith = atKey.sharedWith
..atKey = keyWithNamespace
..sharedBy = atKey.sharedBy;
Expand Down Expand Up @@ -284,7 +287,7 @@ class AtClientImpl implements AtClient {
..two = (getResponse);
// Transform the response and return
var atValue =
await GetResponseTransformer(this).transform(getResponseTuple);
await GetResponseTransformer(this).transform(getResponseTuple);
return atValue;
} on AtException catch (e) {
var exceptionScenario = (secondary is LocalSecondary)
Expand All @@ -305,9 +308,9 @@ class AtClientImpl implements AtClient {
@override
Future<List<String>> getKeys(
{String? regex,
String? sharedBy,
String? sharedWith,
bool showHiddenKeys = false}) async {
String? sharedBy,
String? sharedWith,
bool showHiddenKeys = false}) async {
var builder = ScanVerbBuilder()
..sharedWith = sharedWith
..sharedBy = sharedBy
Expand All @@ -326,9 +329,9 @@ class AtClientImpl implements AtClient {
@override
Future<List<AtKey>> getAtKeys(
{String? regex,
String? sharedBy,
String? sharedWith,
bool showHiddenKeys = false}) async {
String? sharedBy,
String? sharedWith,
bool showHiddenKeys = false}) async {
var getKeysResult = await getKeys(
regex: regex,
sharedBy: sharedBy,
Expand Down Expand Up @@ -456,20 +459,20 @@ class AtClientImpl implements AtClient {
@override
Future<bool> notify(AtKey atKey, String value, OperationEnum operation,
{MessageTypeEnum? messageType,
PriorityEnum? priority,
StrategyEnum? strategy,
int? latestN,
String? notifier = SYSTEM,
bool isDedicated = false}) async {
PriorityEnum? priority,
StrategyEnum? strategy,
int? latestN,
String? notifier = SYSTEM,
bool isDedicated = false}) async {
AtKeyValidators.get().validate(
atKey.toString(),
ValidationContext()
..atSign = currentAtSign
..validateOwnership = true);
final notificationParams =
NotificationParams.forUpdate(atKey, value: value);
NotificationParams.forUpdate(atKey, value: value);
final notifyResult =
await _atClientManager!.notificationService.notify(notificationParams);
await _atClientManager!.notificationService.notify(notificationParams);
return notifyResult.notificationStatusEnum ==
NotificationStatusEnum.delivered;
}
Expand All @@ -482,12 +485,12 @@ class AtClientImpl implements AtClient {
for (var sharedWith in sharedWithList) {
atKey.sharedWith = sharedWith;
final notificationParams =
NotificationParams.forUpdate(atKey, value: value);
NotificationParams.forUpdate(atKey, value: value);
final notifyResult = await _atClientManager!.notificationService
.notify(notificationParams);
returnMap.putIfAbsent(
sharedWith,
() => (notifyResult.notificationStatusEnum ==
() => (notifyResult.notificationStatusEnum ==
NotificationStatusEnum.delivered));
}
return jsonEncode(returnMap);
Expand All @@ -503,9 +506,9 @@ class AtClientImpl implements AtClient {
@override
Future<String> notifyList(
{String? fromDate,
String? toDate,
String? regex,
bool isDedicated = false}) async {
String? toDate,
String? regex,
bool isDedicated = false}) async {
try {
var builder = NotifyListVerbBuilder()
..fromDate = fromDate
Expand Down Expand Up @@ -594,7 +597,7 @@ class AtClientImpl implements AtClient {
var fileName = basename(filePath);
fileName = base64.encode(utf8.encode(fileName));
var encryptedData =
await _encryptionService!.encryptStream(data, sharedWith);
await _encryptionService!.encryptStream(data, sharedWith);
var command =
'stream:init$sharedWith namespace:$namespace $streamId $fileName ${encryptedData.length}\n';
_logger.finer('sending stream init:$command');
Expand Down Expand Up @@ -679,12 +682,12 @@ class AtClientImpl implements AtClient {
..sharedWith = sharedWithAtSign
..metadata = Metadata()
..metadata!.ttr = -1
// file transfer key will be deleted after 30 days
// file transfer key will be deleted after 30 days
..metadata!.ttl = 2592000000
..sharedBy = currentAtSign;

var notificationResult =
await _atClientManager!.notificationService.notify(
await _atClientManager!.notificationService.notify(
NotificationParams.forUpdate(
atKey,
value: jsonEncode(fileTransferObject.toJson()),
Expand Down Expand Up @@ -719,7 +722,7 @@ class AtClientImpl implements AtClient {
final encryptedFile = await _encryptionService!.encryptFileInChunks(
file, encryptionKey, _preference!.fileEncryptionChunkSize);
var response =
await FileTransferService().uploadToFileBinWithStreamedRequest(
await FileTransferService().uploadToFileBinWithStreamedRequest(
encryptedFile,
transferId,
fileStatus.fileName!,
Expand All @@ -735,7 +738,7 @@ class AtClientImpl implements AtClient {
// storing sent files in a a directory.
if (preference?.downloadPath != null) {
var sentFilesDirectory = await Directory(
'${preference!.downloadPath!}${Platform.pathSeparator}sent-files')
'${preference!.downloadPath!}${Platform.pathSeparator}sent-files')
.create();
await File(file.path).copy(sentFilesDirectory.path +
Platform.pathSeparator +
Expand Down Expand Up @@ -776,7 +779,7 @@ class AtClientImpl implements AtClient {
error_codes['AtClientException'], 'FileTransferObject is null');
}
fileTransferObject =
FileTransferObject.fromJson(jsonDecode(result.value))!;
FileTransferObject.fromJson(jsonDecode(result.value))!;
} on Exception catch (e) {
throw Exception('json decode exception in download file ${e.toString()}');
}
Expand All @@ -787,7 +790,7 @@ class AtClientImpl implements AtClient {
throw Exception('download fail');
}
var encryptedFileList =
Directory(fileDownloadResponse.filePath!).listSync();
Directory(fileDownloadResponse.filePath!).listSync();
try {
for (var encryptedFile in encryptedFileList) {
var decryptedFile = await _encryptionService!.decryptFileInChunks(
Expand Down Expand Up @@ -973,4 +976,4 @@ class AtClientImpl implements AtClient {
_preference = preference;
_namespace = namespace;
}
}
}
4 changes: 2 additions & 2 deletions packages/at_client/lib/src/client/remote_secondary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class RemoteSecondary implements Secondary {
var port = secondaryInfo[1];
var internetAddress = await InternetAddress.lookup(host);
//TODO getting first ip for now. explore best solution
var addressCheckOptions =
AddressCheckOptions(internetAddress[0], port: int.parse(port));
var addressCheckOptions = AddressCheckOptions(
address: internetAddress[0], port: int.parse(port));
var addressCheckResult = await InternetConnectionChecker()
.isHostReachable(addressCheckOptions);
return addressCheckResult.isSuccess;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/secondary.dart';
import 'package:at_client/src/client/request_options.dart';
import 'package:at_commons/at_builders.dart';
import 'package:at_utils/at_utils.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SharedKeyDecryption implements AtKeyDecryption {
}
decryptedValue = EncryptionUtil.decryptValue(
encryptedValue,
// ignore: deprecated_member_use_from_same_package
EncryptionUtil.decryptKey(
encryptedSharedKey, currentAtSignPrivateKey));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ abstract class AbstractAtKeyEncryption implements AtKeyEncryption {
return decryptionResult.result;
} else {
try {
// ignore: deprecated_member_use_from_same_package
return EncryptionUtil.decryptKey(
encryptedSharedKey, encryptionPrivateKey!);
} on KeyNotFoundException catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class KeyStreamMixin<T> implements Stream<T> {
);

for (AtKey key in keys) {
atClient
await atClient
.get(key)
.then(
// ignore: unnecessary_cast
Expand Down
3 changes: 2 additions & 1 deletion packages/at_client/lib/src/manager/monitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ class Monitor {
_logger.info('Monitor error $e - calling the retryCallback');
_retryCallBack();
} else {
_logger.severe('Monitor error $e - but _keepAlive is false so monitor will NOT call the retryCallback');
_logger.severe(
'Monitor error $e - but _keepAlive is false so monitor will NOT call the retryCallback');
_onError(e);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/at_client/lib/src/manager/sync_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class SyncManager {
dynamic entryKey = message['entry_key'];
var entry = SyncUtil.getEntry(entryKey, _atSign!);
logger.info(
// ignore: unawaited_futures
'received remote push result: $entryKey $entry $entryKey');
await syncUtil.updateCommitEntry(
entry, int.parse(serverCommitId), _atSign!);
Expand Down
3 changes: 3 additions & 0 deletions packages/at_client/lib/src/service/encryption_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class EncryptionService {
var currentAtSignPrivateKey =
await localSecondary!.getEncryptionPrivateKey();
sharedKey =
// ignore: deprecated_member_use_from_same_package
EncryptionUtil.decryptKey(sharedKey, currentAtSignPrivateKey!);
}

Expand Down Expand Up @@ -297,6 +298,7 @@ class EncryptionService {
throw KeyNotFoundException('encryption private not found');
}
var sharedKey =
// ignore: deprecated_member_use_from_same_package
EncryptionUtil.decryptKey(encryptedSharedKey, currentAtSignPrivateKey);
return sharedKey;
}
Expand All @@ -316,6 +318,7 @@ class EncryptionService {
throw KeyNotFoundException('private encryption key not found');
}
var sharedKey =
// ignore: deprecated_member_use_from_same_package
EncryptionUtil.decryptKey(encryptedSharedKey, currentAtSignPrivateKey);
return sharedKey;
}
Expand Down
Loading

0 comments on commit ce7b3eb

Please sign in to comment.