jcs
/subtext
/amendments
/560
board: For new FTN messages posted locally, just toss them
Instead of writing the bile object ourself, use the toss function
which will do all of that along with the important bit of putting
the message id into the msgid cache. Previously we weren't doing
that so if the hub sent us back a copy of our own message, our
duplicate detection wasn't finding the existing msgid in our cache,
causing duplicate copies of all locally posted messages.
We still need to update this msgid cache when deleting FTN messages,
but we'll do that later.
jcs made amendment 560 about 1 year ago
--- binkp.c Thu Nov 16 13:11:33 2023
+++ binkp.c Tue Nov 21 21:23:01 2023
@@ -890,7 +890,7 @@ binkp_fidopkt_processor(char *filename, unsigned char
goto next_message;
}
- ret = board_toss_ftn_message(board, msg);
+ ret = board_toss_ftn_message(board, msg, false);
} else
ret = mail_toss_ftn_message(msg);
--- board.c Tue Sep 19 21:09:07 2023
+++ board.c Tue Nov 21 21:19:45 2023
@@ -1277,24 +1277,13 @@ board_post_create(struct board *board, struct board_th
post->id = 0;
goto done;
}
-
- ret = bile_marshall_object(board->bile,
- board_ftn_post_object_fields, nboard_ftn_post_object_fields,
- &ftn_post, &data, &size);
- if (ret != 0 || size == 0) {
- logger_printf("[board] Failed to marshall new FTN post object");
+
+ if (board_toss_ftn_message(board, &fidomsg, true) != 1) {
+ logger_printf("[board] Failed tossing new FTN message being "
+ "posted");
post->id = 0;
goto done;
}
- if (bile_write(board->bile, BOARD_FTN_POST_RTYPE, ftn_post.id,
- data, size) != size) {
- warn("bile_write of new post failed! %d",
- bile_error(board->bile));
- post->id = 0;
- xfree(&data);
- goto done;
- }
- xfree(&data);
} else {
if (!post->id)
post->id = bile_next_id(board->bile, BOARD_POST_RTYPE);
@@ -1378,15 +1367,15 @@ board_post_create(struct board *board, struct board_th
goto done;
}
xfree(&data);
- }
- /* it would be nice not to have to rebuild this every time... */
- board_delete_cached_index(board);
- bile_flush(board->bile, true);
+ /* it would be nice not to have to rebuild this every time... */
+ board_delete_cached_index(board);
+ bile_flush(board->bile, true);
- if (post->time > board->last_post_at)
- board->last_post_at = post->time;
-
+ if (post->time > board->last_post_at)
+ board->last_post_at = post->time;
+ }
+
done:
return (post->id == 0 ? -1 : 0);
}
@@ -1533,6 +1522,8 @@ board_delete_ftn_post(struct board *board, struct boar
else
bile_write(board->bile, BOARD_SORTED_ID_MAP_RTYPE, 1, id_map,
sizeof(struct board_id_time_map) * npost_ids);
+
+ /* TODO: delete from msgid cache too */
}
size_t
@@ -1692,7 +1683,7 @@ write_out:
short
board_toss_ftn_message(struct board *board,
- struct fidopkt_message *fidomsg)
+ struct fidopkt_message *fidomsg, bool local)
{
struct board_ftn_msgid_cache {
unsigned long id;
@@ -1747,16 +1738,19 @@ board_toss_ftn_message(struct board *board,
uthread_yield();
- for (n = 0; n < npost_ids; n++) {
- if (memcmp(&msgid_cache[n].msgid, &msgid, sizeof(msgid)) == 0) {
- logger_printf("[board] Already have %s EchoMail %s in %s "
- "(%ld), skipping", db->config.ftn_network,
- fidomsg->msgid_orig, board->name, msgid_cache[n].id);
- ret = 0;
- goto done;
+ if (!local) {
+ for (n = 0; n < npost_ids; n++) {
+ if (memcmp(&msgid_cache[n].msgid, &msgid,
+ sizeof(msgid)) == 0) {
+ logger_printf("[board] Already have %s EchoMail %s in %s "
+ "(%ld), skipping", db->config.ftn_network,
+ fidomsg->msgid_orig, board->name, msgid_cache[n].id);
+ ret = 0;
+ goto done;
+ }
}
}
-
+
memset(&post, 0, sizeof(post));
post.time = fidomsg->time;
post.body_size = fidomsg->body_len + 1;
@@ -1769,7 +1763,8 @@ board_toss_ftn_message(struct board *board,
strlcpy(post.msgid_orig, fidomsg->msgid_orig, sizeof(post.msgid_orig));
post.msgid = msgid;
- post.id = bile_next_id(board->bile, BOARD_FTN_POST_RTYPE);
+ if (!local || !post.id)
+ post.id = bile_next_id(board->bile, BOARD_FTN_POST_RTYPE);
if (!post.id) {
logger_printf("[board] Failed get next id for %s", board->name);
ret = -1;
@@ -1808,8 +1803,9 @@ board_toss_ftn_message(struct board *board,
if (post.time > board->last_post_at)
board->last_post_at = post.time;
- logger_printf("[board] Tossed %s EchoMail %s as %ld",
- fidomsg->area, fidomsg->msgid_orig, post.id);
+ if (!local)
+ logger_printf("[board] Tossed %s EchoMail %s as %ld",
+ fidomsg->area, fidomsg->msgid_orig, post.id);
uthread_yield();
done:
--- board.h Thu Apr 6 17:09:27 2023
+++ board.h Tue Nov 21 21:22:45 2023
@@ -97,7 +97,7 @@ void board_delete_ftn_post(struct board *board,
size_t board_index_sorted_post_ids(struct board *board,
struct board_id_time_map **sorted_id_map);
short board_toss_ftn_message(struct board *board,
- struct fidopkt_message *fidomsg);
+ struct fidopkt_message *fidomsg, bool local);
void board_prune_old_posts(struct board *board);
#endif