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

@ -241,6 +241,8 @@ Future<void> main(List<String> arguments) async {
getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor)); // from relay group 2 getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor)); // from relay group 2
getKindEvents([0,3], gListRelayUrls1, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor* 10)); 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: // the default in case no arguments are given is:
// get a user's events, and get all kind 0, 3 events // get a user's events, and get all kind 0, 3 events
// then get the events of user-id's mentioned in p-tags of received events and the contact list // then get the events of user-id's mentioned in p-tags of received events and the contact list

View File

@ -200,6 +200,7 @@ class EventData {
break; break;
case 4: case 4:
if( userPrivateKey == ""){ // cant process if private key not given if( userPrivateKey == ""){ // cant process if private key not given
break; break;
} }
@ -919,17 +920,32 @@ String myPrivateDecrypt( String privateString,
String publicString, String publicString,
String b64encoded, String b64encoded,
[String b64IV = ""]) { [String b64IV = ""]) {
Uint8List encdData = convert.base64.decode(b64encoded); Uint8List encdData = convert.base64.decode(b64encoded);
final rawData = myPrivateDecryptRaw(privateString, publicString, encdData, b64IV); final rawData = myPrivateDecryptRaw(privateString, publicString, encdData, b64IV);
return convert.Utf8Decoder().convert(rawData.toList()); return convert.Utf8Decoder().convert(rawData.toList());
} }
Map<String, List<List<int>>> gMapByteSecret = {};
Uint8List myPrivateDecryptRaw( String privateString, Uint8List myPrivateDecryptRaw( String privateString,
String publicString, String publicString,
Uint8List cipherText, Uint8List cipherText,
[String b64IV = ""]) { [String b64IV = ""]) {
try { 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]); final key = Uint8List.fromList(secretIV[0]);
@ -937,12 +953,14 @@ try {
? convert.base64.decode(b64IV) ? convert.base64.decode(b64IV)
: Uint8List.fromList(secretIV[1]); : Uint8List.fromList(secretIV[1]);
CipherParameters params = new PaddedBlockCipherParameters( CipherParameters params = new PaddedBlockCipherParameters(
new ParametersWithIV(new KeyParameter(key), iv), null); new ParametersWithIV(new KeyParameter(key), iv), null);
PaddedBlockCipherImpl cipherImpl = new PaddedBlockCipherImpl( PaddedBlockCipherImpl cipherImpl = new PaddedBlockCipherImpl(
new PKCS7Padding(), new CBCBlockCipher(new AESEngine())); new PKCS7Padding(), new CBCBlockCipher(new AESEngine()));
cipherImpl.init(false, cipherImpl.init(false,
params as PaddedBlockCipherParameters<CipherParameters?, params as PaddedBlockCipherParameters<CipherParameters?,
CipherParameters?>); CipherParameters?>);
@ -957,7 +975,6 @@ try {
//remove padding //remove padding
offset += cipherImpl.doFinal(cipherText, offset, finalPlainText, offset); offset += cipherImpl.doFinal(cipherText, offset, finalPlainText, offset);
assert(offset == cipherText.length); assert(offset == cipherText.length);
return finalPlainText.sublist(0, offset); return finalPlainText.sublist(0, offset);
} catch(e) { } catch(e) {
//print("cannot open file $gEventsFilename"); //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 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. 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 gDaysToGetEventsFor = 70; // when getting events, this is the since field (unless a fully formed request is given in command line)
const int gLimitPerSubscription = 5000; const int gLimitPerSubscription = 5000;
@ -73,6 +74,10 @@ List<String> gDefaultFollows = [
"47bae3a008414e24b4d91c8c170f7fce777dedc6780a462d010761dca6482327", // slaninas "47bae3a008414e24b4d91c8c170f7fce777dedc6780a462d010761dca6482327", // slaninas
"c7eda660a6bc8270530e82b4a7712acdea2e31dc0a56f8dc955ac009efd97c86", // shawn "c7eda660a6bc8270530e82b4a7712acdea2e31dc0a56f8dc955ac009efd97c86", // shawn
"b2d670de53b27691c0c3400225b65c35a26d06093bcc41f48ffc71e0907f9d4a", // 0xtr "b2d670de53b27691c0c3400225b65c35a26d06093bcc41f48ffc71e0907f9d4a", // 0xtr
"f43c1f9bff677b8f27b602725ea0ad51af221344f69a6b352a74991a4479bac3", // manfromhighcastle
"80482e60178c2ce996da6d67577f56a2b2c47ccb1c84c81f2b7960637cb71b78", // Leo
"42a0825e980b9f97943d2501d99c3a3859d4e68cd6028c02afe58f96ba661a9d", // zerosequioso
"e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f7e0a02c29388180", // nostr_console test
"3235036bd0957dfb27ccda02d452d7c763be40c91a1ac082ba6983b25238388c"]; // vishalxl ]; "3235036bd0957dfb27ccda02d452d7c763be40c91a1ac082ba6983b25238388c"]; // vishalxl ];

View File

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