Skip to content

Commit

Permalink
changed relay set used
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalxl committed Dec 24, 2022
1 parent f913f97 commit 2e48c07
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
18 changes: 16 additions & 2 deletions bin/nostr_console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Future<void> main(List<String> arguments) async {
// get events from channels of user; gets public as well as encrypted channels
Set<String> userChannels = getUserChannels(initialEvents, userPublicKey);
//printSet(userChannels, "user channels: \n", "\n");
//getIdAndMentionEvents(gListRelayUrls2, userChannels, limitPerSubscription, 0, getSecondsDaysAgo(limitOthersEvents), "#e", "ids");
//getIdAndMentionEvents(gListRelayUrls1, userChannels, limitPerSubscription, 0, getSecondsDaysAgo(limitOthersEvents), "#e", "ids");

getKindEvents([40, 41], gListRelayUrls1, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents));
getKindEvents([42], gListRelayUrls1, 3 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents));
Expand Down Expand Up @@ -373,14 +373,26 @@ Future<void> main(List<String> arguments) async {
contacts.retainWhere((element) => i++ > maxContactsFetched); // retain only first 200, whichever they may be
}

getMultiUserEvents(gListRelayUrls1, contacts.union(gDefaultFollows).union(pTags).difference(usersFetched), 4 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents));
getMultiUserEvents(gListRelayUrls2, contacts.union(gDefaultFollows).union(pTags).difference(usersFetched), 4 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents));
usersFetched = usersFetched.union(gDefaultFollows).union(contacts).union(pTags);

// get meta events of all users fetched
getMultiUserEvents(gListRelayUrls1, usersFetched, 4 * limitPerSubscription, getSecondsDaysAgo(limitSelfEvents*2), {0,3});
//print("fetched meta of ${usersFetched.length}");



void resetRelays() {
relays.closeAll();

getMultiUserEvents(gListRelayUrls1, usersFetched, 4 * limitPerSubscription, getTimeSecondsAgo(1), {0,3});
getMultiUserEvents(gListRelayUrls1, contacts.union(gDefaultFollows).union(pTags).difference(usersFetched), 4 * limitPerSubscription, getTimeSecondsAgo(1));
getKindEvents([40, 41], gListRelayUrls1, limitPerSubscription, getTimeSecondsAgo(1));
getKindEvents([42], gListRelayUrls1, 3 * limitPerSubscription, getTimeSecondsAgo(1));
getUserEvents(gListRelayUrls1, userPublicKey, limitPerSubscription, getTimeSecondsAgo(1));
getMentionEvents(gListRelayUrls1, {userPublicKey}, limitPerSubscription, getTimeSecondsAgo(1), "#p");
}

stdout.write('Waiting for feed to come in..............');
Future.delayed(Duration(milliseconds: gDefaultNumWaitSeconds * 1), () {

Expand All @@ -390,6 +402,8 @@ Future<void> main(List<String> arguments) async {
stdout.write("done\n");
if( gDebug > 0) log.info("Received ptag events events.");

//resetRelays();

// Creat tree from all events read form file
Store node = getTree(initialEvents);
gStore = node;
Expand Down
8 changes: 7 additions & 1 deletion lib/event_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1217,11 +1217,17 @@ Set<String> getPublicKeyFromName(String inquiredName) {
return pubkeys;
}

// returns the seconds since eponch N days ago
// returns the seconds since epoch N days ago
int getSecondsDaysAgo( int N) {
return DateTime.now().subtract(Duration(days: N)).millisecondsSinceEpoch ~/ 1000;
}

// returns the seconds since epoch S seconds ago
int getTimeSecondsAgo( int S) {
return DateTime.now().subtract(Duration(seconds: S)).millisecondsSinceEpoch ~/ 1000;
}


// will write d tabs worth of space ( where tab width is in settings)
void printDepth(int d) {
for( int i = 0; i < gSpacesPerDepth * d + gNumLeftMarginSpaces; i++) {
Expand Down
12 changes: 12 additions & 0 deletions lib/relays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Relay {
int numRequestsSent;
Relay(this.url, this.socket, this.users, this.numReceived, this.numRequestsSent);

void close() {
socket.sink.close().onError((error, stackTrace) => null);
}

void printInfo() {
print("$url ${getNumSpaces(45 - url.length)} $numReceived ${users.length}");
}
Expand All @@ -27,6 +31,14 @@ class Relays {
Set<String> uniqueIdsRecieved = {} ; // id of events received. only for internal usage, so that duplicate events are rejected
Relays(this.relays, this.rEvents, this.uniqueIdsRecieved);

void closeAll() {
relays.forEach((url, relay) {
relay.close();
});

relays.clear();
}

void printInfo() {
printUnderlined("Server connection info");
print(" Server Url Num events received: Num users requested");
Expand Down
4 changes: 2 additions & 2 deletions lib/tree_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1751,8 +1751,8 @@ class Store {
}

// do partial match in ids
if( room.chatRoomName.length >= channelId.length) {
if( listChannels[i].channelId.length >= channelId.length && listChannels[i].channelId.substring(0, channelId.length).toLowerCase() == channelId.toLowerCase() ) {
if( listChannels[i].channelId.length >= channelId.length) {
if( listChannels[i].channelId.substring(0, channelId.length).toLowerCase() == channelId.toLowerCase() ) {
// otherwise add it to list
fullChannelId.add(room.channelId.toLowerCase());
}
Expand Down

0 comments on commit 2e48c07

Please sign in to comment.