From baa755a1cc97b783c4d8378c58db6be0d981486b Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 23 May 2018 21:53:24 +1000 Subject: [PATCH] Experimental changes to mnet --- dist/config/mnet.cfg.example | 4 +- utils/mnetscan/mnetscan.c | 96 ++++++++++++++++++++++++++++-------- utils/mnettoss/mnettoss.c | 91 ++++++++++++++++++++++------------ 3 files changed, 138 insertions(+), 53 deletions(-) diff --git a/dist/config/mnet.cfg.example b/dist/config/mnet.cfg.example index 2dce938..f55991b 100644 --- a/dist/config/mnet.cfg.example +++ b/dist/config/mnet.cfg.example @@ -1,9 +1,9 @@ MYNODE 1 IMHUB TRUE +;UPLINK 1 INDIR /home/andrew/MagickaBBS/mnet/in OUTDIR /home/andrew/MagickaBBS/mnet/out -MSGAREA 1, /home/andrew/MagickaBBS/msgs/mnet_general, 2, 3, 4 - +MSGAREA 1, 1, /home/andrew/MagickaBBS/msgs/mnet_general, 2, 3, 4 diff --git a/utils/mnetscan/mnetscan.c b/utils/mnetscan/mnetscan.c index 48e0570..2f4c88a 100644 --- a/utils/mnetscan/mnetscan.c +++ b/utils/mnetscan/mnetscan.c @@ -11,6 +11,7 @@ char *baseoutdir = NULL; struct msgarea_t { int id; + int hub; char *basedir; int *links; int link_count; @@ -29,6 +30,9 @@ struct msg_t { struct msgarea_t **areas; int area_count; +int mynode = 0; +int hubnode = 0; +int imhub = 0; s_JamBase *open_jam_base(char *path) { int ret; @@ -102,7 +106,18 @@ int parse_config_file(char *filename) { if (buffer[strlen(buffer) - 1] == '\n'){ buffer[strlen(buffer) - 1] = '\0'; - if (strncasecmp(buffer, "OUTDIR", 6) == 0) { + if (strncasecmp(buffer, "MYNODE", 6) == 0) { + trimwhitespace(bufferw, 256, &buffer[7]); + mynode = atoi(bufferw); + } else if (strncasecmp, "IMHUB", 5 == 0) { + trimwhitespace(bufferw, 256, &buffer[7]); + if (strcasecmp(bufferw, "TRUE")) { + imhub = 1; + } + } else if (strncasecmp(buffer, "UPLINK", 6) == 0) { + trimwhitespace(bufferw, 256, &buffer[7]); + hubnode = atoi(bufferw); + } else if (strncasecmp(buffer, "OUTDIR", 6) == 0) { trimwhitespace(bufferw, 256, &buffer[7]); baseoutdir = strdup(bufferw); } else if (strncasecmp(buffer, "MSGAREA", 7) == 0) { @@ -115,20 +130,27 @@ int parse_config_file(char *filename) { newarea->id = atoi(bufferw); newarea->link_count = 0; ptr = strtok(NULL, ","); + if (ptr != NULL) { trimwhitespace(bufferw, 256, ptr); - newarea->basedir = strdup(bufferw); + newarea->hub = atoi(bufferw); ptr = strtok(NULL, ","); - while (ptr != NULL) { + if (ptr != NULL) { + trimwhitespace(bufferw, 256, ptr); - if (newarea->link_count == 0) { - newarea->links = (int *)malloc(sizeof(int)); - } else { - newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1)); - } - newarea->links[newarea->link_count] = atoi(bufferw); - newarea->link_count++; + newarea->basedir = strdup(bufferw); ptr = strtok(NULL, ","); + while (ptr != NULL) { + trimwhitespace(bufferw, 256, ptr); + if (newarea->link_count == 0) { + newarea->links = (int *)malloc(sizeof(int)); + } else { + newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1)); + } + newarea->links[newarea->link_count] = atoi(bufferw); + newarea->link_count++; + ptr = strtok(NULL, ","); + } } } } @@ -225,12 +247,6 @@ int export_messages(int area) { } memcpy(msg.to, jsp->Fields[z]->Buffer, len); } - if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) { - msg.daddr = atoi(jsp->Fields[z]->Buffer); - } - if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) { - msg.oaddr = atoi(jsp->Fields[z]->Buffer); - } if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) { memset(msgid, 0, 37); memcpy(msgid, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen)); @@ -239,6 +255,7 @@ int export_messages(int area) { memcpy(msg.reply, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen)); } } + msg.oaddr = mynode; msg.timedate = jmh.DateWritten; body = (char *)malloc(jmh.TxtLen + 1); memset(body, 0, jmh.TxtLen + 1); @@ -270,15 +287,54 @@ int export_messages(int area) { msg.area = areas[area]->id; - for (n = 0; n < areas[area]->link_count; n++) { - snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->links[n]); + if (areas[area]->hub == mynode) { + for (n = 0; n < areas[area]->link_count; n++) { + if (imhub) { + snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->links[n]); + } else { + snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, hubnode); + } + if (stat(buffer, &st) != 0) { + if (mkdir(buffer, 0755) != 0) { + fprintf(stderr, "Error making directory %s\n", buffer); + continue; + } + } + if (imhub) { + snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, areas[area]->links[n], areas[area]->links[n], msgid); + } else { + snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, hubnode, areas[area]->links[n], msgid); + } + msg.daddr = areas[area]->links[n]; + fptr = fopen(buffer, "wb"); + if (fptr == NULL) { + fprintf(stderr, "Error creating file %s\n", buffer); + continue; + } + + fwrite(&msg, sizeof(struct msg_t), 1, fptr); + fwrite(body, strlen(body), 1, fptr); + fclose(fptr); + } + } else { + if (imhub) { + snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->hub); + } else { + snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, hubnode); + } if (stat(buffer, &st) != 0) { if (mkdir(buffer, 0755) != 0) { fprintf(stderr, "Error making directory %s\n", buffer); continue; } } - snprintf(buffer, PATH_MAX, "%s/%d/%s.message", baseoutdir, areas[area]->links[n], msgid); + if (imhub) { + snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, areas[area]->hub, areas[area]->hub, msgid); + } else { + snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, hubnode, areas[area]->hub, msgid); + } + + msg.daddr = areas[area]->hub; fptr = fopen(buffer, "wb"); if (fptr == NULL) { fprintf(stderr, "Error creating file %s\n", buffer); @@ -287,7 +343,7 @@ int export_messages(int area) { fwrite(&msg, sizeof(struct msg_t), 1, fptr); fwrite(body, strlen(body), 1, fptr); - fclose(fptr); + fclose(fptr); } scanned++; } diff --git a/utils/mnettoss/mnettoss.c b/utils/mnettoss/mnettoss.c index df0e977..9910016 100644 --- a/utils/mnettoss/mnettoss.c +++ b/utils/mnettoss/mnettoss.c @@ -14,6 +14,7 @@ int imhub = 0; struct msgarea_t { int id; + int hub; char *basedir; int *links; int link_count; @@ -33,6 +34,7 @@ struct msg_t { struct msgarea_t **areas; int area_count; int mynode = 0; +int hubnode = 0; int copy_file(char *src, char *dest) { FILE *src_file; @@ -140,6 +142,9 @@ int parse_config_file(char *filename) { if (strcasecmp(bufferw, "TRUE") == 0) { imhub = 1; } + } else if (strncasecmp(buffer, "UPLINK", 6) == 0) { + trimwhitespace(bufferw, 256, &buffer[7]); + hubnode = atoi(bufferw); } else if (strncasecmp(buffer, "INDIR", 5) == 0) { trimwhitespace(bufferw, 256, &buffer[6]); baseindir = strdup(bufferw); @@ -159,20 +164,27 @@ int parse_config_file(char *filename) { newarea->id = atoi(bufferw); newarea->link_count = 0; ptr = strtok(NULL, ","); + if (ptr != NULL) { trimwhitespace(bufferw, 256, ptr); - newarea->basedir = strdup(bufferw); + newarea->hub = atoi(bufferw); ptr = strtok(NULL, ","); - while (ptr != NULL) { + if (ptr != NULL) { + trimwhitespace(bufferw, 256, ptr); - if (newarea->link_count == 0) { - newarea->links = (int *)malloc(sizeof(int)); - } else { - newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1)); - } - newarea->links[newarea->link_count] = atoi(bufferw); - newarea->link_count++; + newarea->basedir = strdup(bufferw); ptr = strtok(NULL, ","); + while (ptr != NULL) { + trimwhitespace(bufferw, 256, ptr); + if (newarea->link_count == 0) { + newarea->links = (int *)malloc(sizeof(int)); + } else { + newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1)); + } + newarea->links[newarea->link_count] = atoi(bufferw); + newarea->link_count++; + ptr = strtok(NULL, ","); + } } } } @@ -265,7 +277,7 @@ int import(char *filename) { s_JamSubfield jsf; snprintf(buffer, PATH_MAX, "%s/%s", baseindir, filename); - strncpy(uuid, filename, 36); + strncpy(uuid, strchr(filename, '-') + 1, 36); uuid[36] = '\0'; @@ -289,29 +301,46 @@ int import(char *filename) { fclose(fptr); - for (i=0;iid) { - areaid = i; - break; - } - } - - if (imhub) { - for (i=0;ilink_count;i++) { - if (areas[areaid]->links[i] == msg.oaddr) { - continue; - } - snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, areas[areaid]->links[i]); - if (stat(buffer2, &st) != 0) { - if (mkdir(buffer2, 0755) != 0) { - fprintf(stderr, "Error making directory %s\n", buffer2); - continue; - } - } - snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, areas[areaid]->links[i], filename); + if (msg.daddr != mynode) { + if (imhub) { + snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, msg.daddr, filename); copy_file(buffer, buffer2); } - } + return 1; + } else { + for (i=0;iid) { + areaid = i; + break; + } + } + + if (areas[areaid]->hub == mynode) { + for (i=0;ilink_count;i++) { + if (areas[areaid]->links[i] == msg.oaddr) { + continue; + } + + if (imhub) { + snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, areas[areaid]->links[i]); + } else { + snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, hubnode); + } + if (stat(buffer2, &st) != 0) { + if (mkdir(buffer2, 0755) != 0) { + fprintf(stderr, "Error making directory %s\n", buffer2); + continue; + } + } + if (imhub) { + snprintf(buffer2, PATH_MAX, "%s/%d/%d-%s", baseoutdir, areas[areaid]->links[i], areas[areaid]->links[i], filename); + } else { + snprintf(buffer2, PATH_MAX, "%s/%d/%d-%s", baseoutdir, hubnode, areas[areaid]->links[i], filename); + } + copy_file(buffer, buffer2); + } + } + } ret = isdupe(&msg, uuid); if (ret == -1) {