diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-05-10 11:43:31 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-05-10 11:43:31 +0200 |
| commit | f93e2d4de6e8140276ce84d173bfb80acaf45830 (patch) | |
| tree | 82b9f434842e785b76b0df1b482d8c469cb5ec71 /src/routing.c | |
| parent | d230c01c0609529332eb72ae1b65f0ddddd515a0 (diff) | |
Rebuild the rounting table on startup
Diffstat (limited to 'src/routing.c')
| -rw-r--r-- | src/routing.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/routing.c b/src/routing.c index 02b2f03..3ef418f 100644 --- a/src/routing.c +++ b/src/routing.c @@ -80,6 +80,23 @@ void routing_update_metrics() { } } +void routing_rebuild_table() { + struct entry table_swap[RT_SIZE]; + memcpy(table_swap, pTable->table, sizeof(pTable->table)); + routing_flush(); + + for(size_t i = 0; i < RT_SIZE; i++) { + if(!table_swap[i].set) continue; + + struct entry *entry; + if(routing_offer(&table_swap[i].id, &entry)) { + *entry = table_swap[i]; + } else { + dbg("Dropping a client since we already have enough in that bucket"); + } + } +} + void routing_flush() { memset(pTable->table, 0, sizeof(pTable->table)); } |
