Experimental changes to mnet

This commit is contained in:
Andrew Pamment 2018-05-23 21:53:24 +10:00
parent b6f328ffa3
commit baa755a1cc
3 changed files with 138 additions and 53 deletions

View File

@ -1,9 +1,9 @@
MYNODE 1 MYNODE 1
IMHUB TRUE IMHUB TRUE
;UPLINK 1
INDIR /home/andrew/MagickaBBS/mnet/in INDIR /home/andrew/MagickaBBS/mnet/in
OUTDIR /home/andrew/MagickaBBS/mnet/out 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

View File

@ -11,6 +11,7 @@ char *baseoutdir = NULL;
struct msgarea_t { struct msgarea_t {
int id; int id;
int hub;
char *basedir; char *basedir;
int *links; int *links;
int link_count; int link_count;
@ -29,6 +30,9 @@ struct msg_t {
struct msgarea_t **areas; struct msgarea_t **areas;
int area_count; int area_count;
int mynode = 0;
int hubnode = 0;
int imhub = 0;
s_JamBase *open_jam_base(char *path) { s_JamBase *open_jam_base(char *path) {
int ret; int ret;
@ -102,7 +106,18 @@ int parse_config_file(char *filename) {
if (buffer[strlen(buffer) - 1] == '\n'){ if (buffer[strlen(buffer) - 1] == '\n'){
buffer[strlen(buffer) - 1] = '\0'; 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]); trimwhitespace(bufferw, 256, &buffer[7]);
baseoutdir = strdup(bufferw); baseoutdir = strdup(bufferw);
} else if (strncasecmp(buffer, "MSGAREA", 7) == 0) { } else if (strncasecmp(buffer, "MSGAREA", 7) == 0) {
@ -115,7 +130,13 @@ int parse_config_file(char *filename) {
newarea->id = atoi(bufferw); newarea->id = atoi(bufferw);
newarea->link_count = 0; newarea->link_count = 0;
ptr = strtok(NULL, ","); ptr = strtok(NULL, ",");
if (ptr != NULL) { if (ptr != NULL) {
trimwhitespace(bufferw, 256, ptr);
newarea->hub = atoi(bufferw);
ptr = strtok(NULL, ",");
if (ptr != NULL) {
trimwhitespace(bufferw, 256, ptr); trimwhitespace(bufferw, 256, ptr);
newarea->basedir = strdup(bufferw); newarea->basedir = strdup(bufferw);
ptr = strtok(NULL, ","); ptr = strtok(NULL, ",");
@ -132,6 +153,7 @@ int parse_config_file(char *filename) {
} }
} }
} }
}
if (newarea != NULL) { if (newarea != NULL) {
if (area_count == 0) { if (area_count == 0) {
areas = (struct msgarea_t **)malloc(sizeof(struct msgarea_t *)); areas = (struct msgarea_t **)malloc(sizeof(struct msgarea_t *));
@ -225,12 +247,6 @@ int export_messages(int area) {
} }
memcpy(msg.to, jsp->Fields[z]->Buffer, len); 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) { if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) {
memset(msgid, 0, 37); memset(msgid, 0, 37);
memcpy(msgid, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen)); 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)); memcpy(msg.reply, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen));
} }
} }
msg.oaddr = mynode;
msg.timedate = jmh.DateWritten; msg.timedate = jmh.DateWritten;
body = (char *)malloc(jmh.TxtLen + 1); body = (char *)malloc(jmh.TxtLen + 1);
memset(body, 0, jmh.TxtLen + 1); memset(body, 0, jmh.TxtLen + 1);
@ -270,15 +287,54 @@ int export_messages(int area) {
msg.area = areas[area]->id; msg.area = areas[area]->id;
if (areas[area]->hub == mynode) {
for (n = 0; n < areas[area]->link_count; n++) { for (n = 0; n < areas[area]->link_count; n++) {
if (imhub) {
snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->links[n]); 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 (stat(buffer, &st) != 0) {
if (mkdir(buffer, 0755) != 0) { if (mkdir(buffer, 0755) != 0) {
fprintf(stderr, "Error making directory %s\n", buffer); fprintf(stderr, "Error making directory %s\n", buffer);
continue; 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]->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;
}
}
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"); fptr = fopen(buffer, "wb");
if (fptr == NULL) { if (fptr == NULL) {
fprintf(stderr, "Error creating file %s\n", buffer); fprintf(stderr, "Error creating file %s\n", buffer);

View File

@ -14,6 +14,7 @@ int imhub = 0;
struct msgarea_t { struct msgarea_t {
int id; int id;
int hub;
char *basedir; char *basedir;
int *links; int *links;
int link_count; int link_count;
@ -33,6 +34,7 @@ struct msg_t {
struct msgarea_t **areas; struct msgarea_t **areas;
int area_count; int area_count;
int mynode = 0; int mynode = 0;
int hubnode = 0;
int copy_file(char *src, char *dest) { int copy_file(char *src, char *dest) {
FILE *src_file; FILE *src_file;
@ -140,6 +142,9 @@ int parse_config_file(char *filename) {
if (strcasecmp(bufferw, "TRUE") == 0) { if (strcasecmp(bufferw, "TRUE") == 0) {
imhub = 1; imhub = 1;
} }
} else if (strncasecmp(buffer, "UPLINK", 6) == 0) {
trimwhitespace(bufferw, 256, &buffer[7]);
hubnode = atoi(bufferw);
} else if (strncasecmp(buffer, "INDIR", 5) == 0) { } else if (strncasecmp(buffer, "INDIR", 5) == 0) {
trimwhitespace(bufferw, 256, &buffer[6]); trimwhitespace(bufferw, 256, &buffer[6]);
baseindir = strdup(bufferw); baseindir = strdup(bufferw);
@ -159,7 +164,13 @@ int parse_config_file(char *filename) {
newarea->id = atoi(bufferw); newarea->id = atoi(bufferw);
newarea->link_count = 0; newarea->link_count = 0;
ptr = strtok(NULL, ","); ptr = strtok(NULL, ",");
if (ptr != NULL) { if (ptr != NULL) {
trimwhitespace(bufferw, 256, ptr);
newarea->hub = atoi(bufferw);
ptr = strtok(NULL, ",");
if (ptr != NULL) {
trimwhitespace(bufferw, 256, ptr); trimwhitespace(bufferw, 256, ptr);
newarea->basedir = strdup(bufferw); newarea->basedir = strdup(bufferw);
ptr = strtok(NULL, ","); ptr = strtok(NULL, ",");
@ -176,6 +187,7 @@ int parse_config_file(char *filename) {
} }
} }
} }
}
if (newarea != NULL) { if (newarea != NULL) {
if (area_count == 0) { if (area_count == 0) {
areas = (struct msgarea_t **)malloc(sizeof(struct msgarea_t *)); areas = (struct msgarea_t **)malloc(sizeof(struct msgarea_t *));
@ -265,7 +277,7 @@ int import(char *filename) {
s_JamSubfield jsf; s_JamSubfield jsf;
snprintf(buffer, PATH_MAX, "%s/%s", baseindir, filename); snprintf(buffer, PATH_MAX, "%s/%s", baseindir, filename);
strncpy(uuid, filename, 36); strncpy(uuid, strchr(filename, '-') + 1, 36);
uuid[36] = '\0'; uuid[36] = '\0';
@ -289,6 +301,13 @@ int import(char *filename) {
fclose(fptr); fclose(fptr);
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;i<area_count;i++) { for (i=0;i<area_count;i++) {
if (msg.area == areas[i]->id) { if (msg.area == areas[i]->id) {
areaid = i; areaid = i;
@ -296,22 +315,32 @@ int import(char *filename) {
} }
} }
if (imhub) { if (areas[areaid]->hub == mynode) {
for (i=0;i<areas[areaid]->link_count;i++) { for (i=0;i<areas[areaid]->link_count;i++) {
if (areas[areaid]->links[i] == msg.oaddr) { if (areas[areaid]->links[i] == msg.oaddr) {
continue; continue;
} }
if (imhub) {
snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, areas[areaid]->links[i]); 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 (stat(buffer2, &st) != 0) {
if (mkdir(buffer2, 0755) != 0) { if (mkdir(buffer2, 0755) != 0) {
fprintf(stderr, "Error making directory %s\n", buffer2); fprintf(stderr, "Error making directory %s\n", buffer2);
continue; continue;
} }
} }
snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, areas[areaid]->links[i], filename); 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); copy_file(buffer, buffer2);
} }
} }
}
ret = isdupe(&msg, uuid); ret = isdupe(&msg, uuid);
if (ret == -1) { if (ret == -1) {