summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2025-05-04 15:09:55 +0200
committerJesper Jensen <jesper@jnsn.dev>2025-05-04 15:09:55 +0200
commit222bd168e7be37a662ed8281db1a9b32f0cca7d2 (patch)
treeaaafa88c8c79baaf69fbaad5b08b7d00482db6f5
parentce69e3e5bf0c6188fa7bc70021b7dde0e7752c9a (diff)
Add some check for expiry time
-rw-r--r--src/main.c1
-rw-r--r--src/peers.c9
-rw-r--r--src/peers.h1
-rw-r--r--src/routing.c7
4 files changed, 16 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 9371510..937e151 100644
--- a/src/main.c
+++ b/src/main.c
@@ -159,6 +159,7 @@ int main(int argc, char** argv) {
metric_init();
routing_update_metrics();
+ peer_update_metrics();
size_t outLen;
const char *id = base64_encode((unsigned char*)myID.inner_b, 20, &outLen);
diff --git a/src/peers.c b/src/peers.c
index f278be2..d320e30 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -115,7 +115,6 @@ int add_peer(struct infohash* infohash, struct addr* peer, time_t now) {
if(!entry->set) {
entry->set = true;
entry->key = *infohash;
- entry->last_seen = now;
peer_table_load++;
peer_status.hashes++;
prom_counter_inc(hashes, NULL);
@@ -191,3 +190,11 @@ void expire_hashes(time_t now) {
check_duplicates();
prom_gauge_set(current_hashes, (double)peer_table_load, NULL);
}
+
+void peer_update_metrics() {
+ time_t now = time(NULL);
+ for(size_t i = 0; i < peer_table_size; i++) {
+ if(peer_table[i].set) continue;
+ if(now < peer_table[i].last_seen) dbg("%d was seen after now? (%ld < %ld)", i, now, peer_table[i].last_seen);
+ }
+}
diff --git a/src/peers.h b/src/peers.h
index 8bd6b44..2c7845b 100644
--- a/src/peers.h
+++ b/src/peers.h
@@ -37,3 +37,4 @@ int add_peer(struct infohash* infohash, struct addr* peer, time_t now);
void get_peers(struct infohash* infohash, struct addr **peers, size_t *peers_len);
void expire_hashes(time_t now);
+void peer_update_metrics();
diff --git a/src/routing.c b/src/routing.c
index 7c10e16..30f0deb 100644
--- a/src/routing.c
+++ b/src/routing.c
@@ -73,7 +73,12 @@ void routing_update_metrics() {
prom_gauge_set(routing_table_occupied, filled, (const char*[]){buf});
}
- dbg("Update metrics!!");
+
+ time_t reasonable = time(NULL) + 120;
+ for(size_t i = 0; i < RT_SIZE; i++) {
+ if(pTable->table[i].set) continue;
+ if(reasonable < pTable->table[i].expire) dbg("%d will expire quite far into the future after now? (%ld < %ld)", i, reasonable, pTable->table[i].expire);
+ }
}
void routing_flush() {