Completed the rewrite of the network poller. Again I'm not terribly happy with this...
authorArt Cancro <ajc@citadel.org>
Wed, 5 Apr 2017 16:22:17 +0000 (12:22 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 5 Apr 2017 16:22:17 +0000 (12:22 -0400)
citadel/citadel.h
citadel/configure.ac
citadel/modules/ctdlproto/serv_file.c
citadel/modules/network/serv_netmail.c
citadel/modules/network/serv_netspool.c
citadel/modules/networkclient/serv_networkclient.c

index d728af6ecbc5b6f34924ac7682efe40fd0955ff5..3c5eb47fa600e91ada9292218170112a04bc0b7e 100644 (file)
@@ -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 */
index 39fe88db2f51ce661ec8bfb5aa30ede4249fd632..497ce907aa031f3b5df9be3a46ac044e9c734806 100644 (file)
@@ -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)
index 92dd92d49af37e046e916305dc92518c794b486a..f412b259e221644433565381f442180409dfa5e3 100644 (file)
@@ -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;
index ddd3ba19d9182b009dd55ced4198015b46e97f9d..941a2590e26fdef302c19f9354feeb91636c80d4 100644 (file)
@@ -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),
index a17980ece213938799cc1a10800be83b1d9afb05..7ca9edcd8422f7936ae7d8ecfb321f9ad652e179 100644 (file)
@@ -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;
index 66bcae45b4d9da6a678c6f3a47b60400cba2215e..d213fbd0414260a4b36258fb89e07153b0d22f38 100644 (file)
  * 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
  */