made map out of bytesecret and do look up second time

speeds up a lot . each takes 0.05 secs to calculate.
This commit is contained in:
Vishal 2022-09-07 03:53:15 +05:30
parent 11972d5328
commit 9558197cac
4 changed files with 36 additions and 6 deletions

View File

@ -240,6 +240,8 @@ Future<void> main(List<String> arguments) async {
getUserEvents(gListRelayUrls1, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor));
getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor)); // from relay group 2
getKindEvents([0,3], gListRelayUrls1, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor* 10));
// TODO get all 40 events, and then get all #e for them ( responses to them)
// the default in case no arguments are given is:
// get a user's events, and get all kind 0, 3 events
@ -286,7 +288,7 @@ Future<void> main(List<String> arguments) async {
// Creat tree from all events read form file
Store node = getTree(initialEvents);
clearEvents();
mainMenuUi(node);
});

View File

@ -200,6 +200,7 @@ class EventData {
break;
case 4:
if( userPrivateKey == ""){ // cant process if private key not given
break;
}
@ -919,17 +920,32 @@ String myPrivateDecrypt( String privateString,
String publicString,
String b64encoded,
[String b64IV = ""]) {
Uint8List encdData = convert.base64.decode(b64encoded);
final rawData = myPrivateDecryptRaw(privateString, publicString, encdData, b64IV);
return convert.Utf8Decoder().convert(rawData.toList());
}
Map<String, List<List<int>>> gMapByteSecret = {};
Uint8List myPrivateDecryptRaw( String privateString,
String publicString,
Uint8List cipherText,
[String b64IV = ""]) {
try {
final secretIV = Kepler.byteSecret(privateString, publicString);
List<List<int>> byteSecret = [];
if( gMapByteSecret.containsKey(publicString)) {
byteSecret = gMapByteSecret[publicString]??[];
}
if( byteSecret.isEmpty) {
byteSecret = Kepler.byteSecret(privateString, publicString);;
gMapByteSecret[publicString] = byteSecret;
}
final secretIV = byteSecret;
final key = Uint8List.fromList(secretIV[0]);
@ -937,12 +953,14 @@ try {
? convert.base64.decode(b64IV)
: Uint8List.fromList(secretIV[1]);
CipherParameters params = new PaddedBlockCipherParameters(
new ParametersWithIV(new KeyParameter(key), iv), null);
PaddedBlockCipherImpl cipherImpl = new PaddedBlockCipherImpl(
new PKCS7Padding(), new CBCBlockCipher(new AESEngine()));
cipherImpl.init(false,
params as PaddedBlockCipherParameters<CipherParameters?,
CipherParameters?>);
@ -957,7 +975,6 @@ try {
//remove padding
offset += cipherImpl.doFinal(cipherText, offset, finalPlainText, offset);
assert(offset == cipherText.length);
return finalPlainText.sublist(0, offset);
} catch(e) {
//print("cannot open file $gEventsFilename");

View File

@ -14,6 +14,7 @@ bool gDontWriteOldEvents = true;
const int gDontSaveBeforeDays = 100; // dont save events older than this many days if gDontWriteOldEvents flag is true
bool gOverWriteFile = false; // overwrite the file, and don't just append. Will write all events in memory.
const int gDontAddToStoreBeforeDays = 60; // events older than this are not added to the Store of all events
const int gDaysToGetEventsFor = 70; // when getting events, this is the since field (unless a fully formed request is given in command line)
const int gLimitPerSubscription = 5000;
@ -73,6 +74,10 @@ List<String> gDefaultFollows = [
"47bae3a008414e24b4d91c8c170f7fce777dedc6780a462d010761dca6482327", // slaninas
"c7eda660a6bc8270530e82b4a7712acdea2e31dc0a56f8dc955ac009efd97c86", // shawn
"b2d670de53b27691c0c3400225b65c35a26d06093bcc41f48ffc71e0907f9d4a", // 0xtr
"f43c1f9bff677b8f27b602725ea0ad51af221344f69a6b352a74991a4479bac3", // manfromhighcastle
"80482e60178c2ce996da6d67577f56a2b2c47ccb1c84c81f2b7960637cb71b78", // Leo
"42a0825e980b9f97943d2501d99c3a3859d4e68cd6028c02afe58f96ba661a9d", // zerosequioso
"e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f7e0a02c29388180", // nostr_console test
"3235036bd0957dfb27ccda02d452d7c763be40c91a1ac082ba6983b25238388c"]; // vishalxl ];

View File

@ -1450,13 +1450,15 @@ Store getTree(Set<Event> events) {
events.forEach( (event) => processKind0Event(event)? totalKind0Processed++: notProcessed++);
if( gDebug > 0) print("In getTree: totalKind0Processed = $totalKind0Processed notProcessed = $notProcessed gKindONames.length = ${gKindONames.length}");
if( gDebug > 0) log.info("kind 0 finished.");
// process kind 3 events which is contact list. Update global info about the user (with meta data)
int totalKind3Processed = 0, notProcessed3 = 0;
events.forEach( (event) => processKind3Event(event)? totalKind3Processed++: notProcessed3++);
if( gDebug > 0) print("In getTree: totalKind3Processed = $totalKind3Processed notProcessed = $notProcessed3 gKindONames.length = ${gKindONames.length}");
// process kind 7 events or reactions
//processReactions(events);
if( gDebug > 0) log.info("kind 3 finished.");
// remove bot events
events.removeWhere( (event) => gBots.contains(event.eventData.pubkey));
@ -1468,12 +1470,16 @@ Store getTree(Set<Event> events) {
// translate and expand mentions for all
events.forEach( (event) => event.eventData.translateAndExpandMentions());
if( gDebug > 0) log.info("expand mentions finished.");
if( gDebug > 0) print("In getTree: after removing unwanted kind, number of events remaining: ${events.length}");
if( gDebug > 0) log.info("Calling fromEvents for ${events.length} events.");
// create tree from events
Store node = Store.fromEvents(events);
if(gDebug != 0) print("total number of posts/replies in main tree = ${node.count()}");
if(gDebug > 0) print("total number of posts/replies in main tree = ${node.count()}");
return node;
}