From dc56ca4c678006a3930caa42688b2f02a9535270 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 5 Apr 2017 12:22:17 -0400 Subject: [PATCH] Completed the rewrite of the network poller. Again I'm not terribly happy with this one. All of the Gen 3 pollers have libcurl do all the work, but this one doesn't. I intend to replace IGnet protocol completely with something else (probably NNTP or IGnet-over-SMTP) in the not too distant future. --- citadel/citadel.h | 2 +- citadel/configure.ac | 2 +- citadel/modules/ctdlproto/serv_file.c | 18 ++--- citadel/modules/network/serv_netmail.c | 2 +- citadel/modules/network/serv_netspool.c | 4 - .../networkclient/serv_networkclient.c | 77 ++++++++++++++++--- 6 files changed, 77 insertions(+), 28 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index d728af6ec..3c5eb47fa 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -45,7 +45,7 @@ extern "C" { * usually more strict because you're not really supposed to dump/load and * upgrade at the same time. */ -#define REV_LEVEL 907 /* This version */ +#define REV_LEVEL 908 /* This version */ #define REV_MIN 591 /* Oldest compatible database */ #define EXPORT_REV_MIN 760 /* Oldest compatible export files */ #define LIBCITADEL_MIN 903 /* Minimum required version of libcitadel */ diff --git a/citadel/configure.ac b/citadel/configure.ac index 39fe88db2..497ce907a 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.52) -AC_INIT([Citadel], [907], [http://www.citadel.org/]) +AC_INIT([Citadel], [908], [http://www.citadel.org/]) AC_REVISION([$Revision: 5108 $]) AC_CONFIG_SRCDIR([citserver.c]) AC_CONFIG_HEADER(sysdep.h) diff --git a/citadel/modules/ctdlproto/serv_file.c b/citadel/modules/ctdlproto/serv_file.c index 92dd92d49..f412b259e 100644 --- a/citadel/modules/ctdlproto/serv_file.c +++ b/citadel/modules/ctdlproto/serv_file.c @@ -415,11 +415,11 @@ void cmd_ucls(char *cmd) snprintf(final_filename, sizeof final_filename, "%s/%s.%04lx.%04x", ctdl_netin_dir, CCC->net_node, (long)getpid(), ++seq); if (link(CCC->upl_path, final_filename) == 0) { - syslog(LOG_INFO, "UCLS: updoaded %s", final_filename); + syslog(LOG_INFO, "serv_file: ucls updoaded %s", final_filename); unlink(CCC->upl_path); } else { - syslog(LOG_INFO, "Cannot link %s to %s: %s", + syslog(LOG_INFO, "serv_file: cannot link %s to %s: %s", CCC->upl_path, final_filename, strerror(errno) ); } @@ -487,11 +487,11 @@ void cmd_read(char *cmdbuf) rc = fseek(CC->download_fp, start_pos, 0); if (rc < 0) { - cprintf("%d your file is smaller then %ld.\n", ERROR + ILLEGAL_VALUE, start_pos); - syslog(LOG_ERR, "your file %s is smaller then %ld. [%s]", - CC->upl_path, - start_pos, - strerror(errno) + cprintf("%d your file is smaller than %ld.\n", ERROR + ILLEGAL_VALUE, start_pos); + syslog(LOG_ERR, "serv_file: your file %s is smaller than %ld [%s]", + CC->upl_path, + start_pos, + strerror(errno) ); return; @@ -540,7 +540,7 @@ void cmd_writ(char *cmdbuf) client_read(buf, bytes); rv = fwrite(buf, bytes, 1, CCC->upload_fp); if (rv == -1) { - syslog(LOG_EMERG, "Couldn't write: %s", strerror(errno)); + syslog(LOG_ERR, "serv_file: %s", strerror(errno)); } free(buf); } @@ -741,7 +741,7 @@ void cmd_mesg(char *mname) ERROR + FILE_NOT_FOUND, targ, strerror(errno)); return; } - cprintf("%d %s\n", LISTING_FOLLOWS,buf); + cprintf("%d %s\n", LISTING_FOLLOWS, buf); while (fgets(buf, (sizeof buf - 1), mfp) != NULL) { buf[strlen(buf)-1] = 0; diff --git a/citadel/modules/network/serv_netmail.c b/citadel/modules/network/serv_netmail.c index ddd3ba19d..941a2590e 100644 --- a/citadel/modules/network/serv_netmail.c +++ b/citadel/modules/network/serv_netmail.c @@ -536,7 +536,7 @@ void network_process_ignetpush(SpoolControl *sc, struct CtdlMessage *omsg, long /* write it to a spool file */ snprintf(filename, sizeof(filename), - "%s/%s@%lx%x", + "%s/%s@%lx%x-mail", ctdl_netout_dir, ChrPtr(Recipient), time(NULL), diff --git a/citadel/modules/network/serv_netspool.c b/citadel/modules/network/serv_netspool.c index a17980ece..7ca9edcd8 100644 --- a/citadel/modules/network/serv_netspool.c +++ b/citadel/modules/network/serv_netspool.c @@ -913,10 +913,6 @@ void network_consolidate_spoolout(HashList *working_ignetcfg, HashList *the_netm int nFailed = 0; int d_type = 0; - - - return; // FIXME still trying to figure this out - /* Step 1: consolidate files in the outbound queue into one file per neighbor node */ d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1); if (d == NULL) return; diff --git a/citadel/modules/networkclient/serv_networkclient.c b/citadel/modules/networkclient/serv_networkclient.c index 66bcae45b..d213fbd04 100644 --- a/citadel/modules/networkclient/serv_networkclient.c +++ b/citadel/modules/networkclient/serv_networkclient.c @@ -11,13 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * ** NOTE ** A word on the S_NETCONFIGS semaphore: - * This is a fairly high-level type of critical section. It ensures that no - * two threads work on the netconfigs files at the same time. Since we do - * so many things inside these, here are the rules: - * 1. begin_critical_section(S_NETCONFIGS) *before* begin_ any others. - * 2. Do *not* perform any I/O with the client during these sections. - * + * Implementation note: + * I'm not really happy with this. It looks more like a Gen 1 poller + * than a Gen 3 poller, because libcurl (understandably) does not have + * support for Citadel protocol. In the not too distant future I would + * like to remove Citadel-to-Citadel protocol entirely, and replace it + * with NNTP. */ @@ -86,6 +85,7 @@ void network_poll_node(StrBuf *node, StrBuf *host, StrBuf *port, StrBuf *secret) int bytes_total = 0; int this_block = 0; StrBuf *SpoolFileName = NULL; + FILE *netoutfp = NULL; syslog(LOG_DEBUG, "netpoll: polling %s at %s:%s", ChrPtr(node), ChrPtr(host), ChrPtr(port)); @@ -186,20 +186,72 @@ void network_poll_node(StrBuf *node, StrBuf *host, StrBuf *port, StrBuf *secret) // Now get ready to send our network data to the other node. SpoolFileName = NewStrBuf(); - StrBufPrintf(SpoolFileName, // Outgoing packets come from the "spoolout/" directory + StrBufPrintf(SpoolFileName, // Outgoing packets come from the "spoolout/" directory "%s/%s", ctdl_netout_dir, ChrPtr(node) ); - FILE *netoutfp = fopen(ChrPtr(SpoolFileName), "w"); - FreeStrBuf(&SpoolFileName); + netoutfp = fopen(ChrPtr(SpoolFileName), "r"); if (!netoutfp) { goto bail; } - fclose(netoutfp); - //unlink(netoutfp); + + /* Tell it we want to upload. */ + sock_puts(&sock, "NUOP"); + if (sock_getln(&sock, buf, sizeof buf) < 0) { + goto bail; + } + if (buf[0] != '2') { + CtdlAideMessage(buf, "NUOP error"); + syslog(LOG_ERR, "netpoll: NUOP error talking to <%s> : %s", ChrPtr(node), buf); + goto bail; + } + + fseek(netoutfp, 0, SEEK_END); + long total_to_send = ftell(netoutfp); + rewind(netoutfp); + + syslog(LOG_DEBUG, "netpoll: I want to send %ld bytes to %s", total_to_send, ChrPtr(node)); + long bytes_sent = 0; + while (bytes_sent < total_to_send) { + if (server_shutting_down) { + goto bail; + } + + this_block = total_to_send - bytes_sent; + if (this_block > sizeof(buf)) { + this_block = sizeof(buf); + } + + snprintf(buf, sizeof buf, "WRIT %d", this_block); + sock_puts(&sock, buf); + if (sock_getln(&sock, buf, sizeof buf) < 0) { + goto bail; + } + if (buf[0] != '7') { + goto bail; + } + this_block = atol(&buf[4]); + fread(buf, this_block, 1, netoutfp); + if (sock_write(&sock, buf, this_block) != this_block) { + goto bail; + } + bytes_sent += this_block; + syslog(LOG_DEBUG, "netpoll: sent %ld of %ld bytes to %s", bytes_sent, total_to_send, ChrPtr(node)); + } + + /* Tell them we're done. */ + sock_puts(&sock, "UCLS 1"); // UCLS 1 causes it to close *and delete* on the other node + if (sock_getln(&sock, buf, sizeof buf) < 0) { + goto bail; + } + if (buf[0] == '2') { + unlink(ChrPtr(SpoolFileName)); + } bail: close(sock); + if (SpoolFileName != NULL) FreeStrBuf(&SpoolFileName); + if (netoutfp != NULL) fclose(netoutfp); FreeStrBuf(&CC->SBuf.Buf); FreeStrBuf(&CC->sMigrateBuf); } @@ -303,6 +355,7 @@ void network_do_clientqueue(void) DeleteHash(&working_ignetcfg); } + /* * Module entry point */ -- 2.30.2