* Finished the concurrency check for network polling. (Now works both for
authorArt Cancro <ajc@citadel.org>
Sat, 6 Oct 2001 21:32:29 +0000 (21:32 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 6 Oct 2001 21:32:29 +0000 (21:32 +0000)
  polling and being polled.  Severe UUCP deja vu.)

citadel/ChangeLog
citadel/file_ops.c
citadel/file_ops.h
citadel/serv_network.c
citadel/serv_network.h
citadel/user_ops.c

index 32ae52f1dcbcd350fbc1d838f3b1b49052fe7793..025964627c6567e358d5f166f4fae0d794e3f7d5 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 580.53  2001/10/06 21:32:29  ajc
+ * Finished the concurrency check for network polling.  (Now works both for
+   polling and being polled.  Severe UUCP deja vu.)
+
  Revision 580.52  2001/10/06 20:28:06  ajc
  * Began implementing some concurrency stuff for the networker
 
@@ -2778,4 +2782,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 98f67994b61951b686fd75053168baf1a6a4721b..a04dc32c9b38ab312e02ba1ef8bb34ba0eb9827c 100644 (file)
 #include "citserver.h"
 
 
+/*
+ * network_talking_to()  --  concurrency checker
+ */
+int network_talking_to(char *nodename, int operation) {
+
+       static char *nttlist = NULL;
+       char *ptr = NULL;
+       int i;
+       char buf[SIZ];
+       int retval = 0;
+
+       begin_critical_section(S_NTTLIST);
+
+       switch(operation) {
+
+               case NTT_ADD:
+                       if (nttlist == NULL) nttlist = strdoop("");
+                       if (nttlist == NULL) break;
+                       nttlist = (char *)reallok(nttlist,
+                               (strlen(nttlist) + strlen(nodename) + 3) );
+                       strcat(nttlist, "|");
+                       strcat(nttlist, nodename);
+                       break;
+
+               case NTT_REMOVE:
+                       if (nttlist == NULL) break;
+                       if (strlen(nttlist) == 0) break;
+                       ptr = mallok(strlen(nttlist));
+                       if (ptr == NULL) break;
+                       strcpy(ptr, "");
+                       for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
+                               extract(buf, nttlist, i);
+                               if ( (strlen(buf) > 0)
+                                    && (strcasecmp(buf, nodename)) ) {
+                                               strcat(ptr, buf);
+                                               strcat(ptr, "|");
+                               }
+                       }
+                       phree(nttlist);
+                       nttlist = ptr;
+                       break;
+
+               case NTT_CHECK:
+                       if (nttlist == NULL) break;
+                       if (strlen(nttlist) == 0) break;
+                       for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
+                               extract(buf, nttlist, i);
+                               if (!strcasecmp(buf, nodename)) ++retval;
+                       }
+                       break;
+       }
+
+       if (nttlist != NULL) lprintf(9, "nttlist=<%s>\n", nttlist);
+       end_critical_section(S_NTTLIST);
+       return(retval);
+}
+
+
+
+
 /*
  * Server command to delete a file from a room's directory
  */
index f6c9c9d55e171abe4645e4b35ee74f1b013ce8ef..9b3c47be77bb0b037cbf75eb343f59290f65bc93 100644 (file)
@@ -14,3 +14,13 @@ void cmd_read (char *cmdbuf);
 void cmd_writ (char *cmdbuf);
 void cmd_ndop (char *cmdbuf);
 void cmd_nuop (char *cmdbuf);
+int network_talking_to(char *nodename, int operation);
+
+/*
+ * Operations that can be performed by network_talking_to()
+ */
+enum {
+        NTT_ADD,
+        NTT_REMOVE,
+        NTT_CHECK
+};
index a92789124361ccc7cf0ce93b21f960e3988c6255..b0dc2e75a71c14e7114b394ce31c2db33b5c123c 100644 (file)
  */
 
 /*
- * FIXME do something about concurrency issues:
- * 1. Don't allow the two nodes to poll each other at the same time
- * 2. Don't allow polls during network processing
- * 3. Kill Bill Gates using either a chainsaw or a wood chipper
+ * FIXME
+ * Don't allow polls during network processing
  */
 
 #include "sysdep.h"
@@ -56,6 +54,7 @@
 #include "internet_addressing.h"
 #include "serv_network.h"
 #include "clientsocket.h"
+#include "file_ops.h"
 
 
 /*
@@ -86,69 +85,6 @@ struct NetMap *the_netmap = NULL;
 
 
 
-/*
- * network_talking_to()  --  concurrency checker
- */
-int network_talking_to(char *nodename, int operation) {
-
-       static char *nttlist = NULL;
-       char *ptr = NULL;
-       int i;
-       char buf[SIZ];
-       int retval = 0;
-
-       begin_critical_section(S_NTTLIST);
-
-       switch(operation) {
-
-               case NTT_ADD:
-                       if (nttlist == NULL) nttlist = strdoop("");
-                       if (nttlist == NULL) break;
-                       nttlist = (char *)reallok(nttlist,
-                               (strlen(nttlist) + strlen(nodename) + 3) );
-                       strcat(nttlist, "|");
-                       strcat(nttlist, nodename);
-                       break;
-
-               case NTT_REMOVE:
-                       if (nttlist == NULL) break;
-                       if (strlen(nttlist) == 0) break;
-                       ptr = mallok(strlen(nttlist));
-                       if (ptr == NULL) break;
-                       strcpy(ptr, "");
-                       for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
-                               extract(buf, nttlist, i);
-                               if ( (strlen(buf) > 0)
-                                    && (strcasecmp(buf, nodename)) ) {
-                                               strcat(ptr, buf);
-                                               strcat(ptr, "|");
-                               }
-                       }
-                       phree(nttlist);
-                       nttlist = ptr;
-                       break;
-
-               case NTT_CHECK:
-                       if (nttlist == NULL) break;
-                       if (strlen(nttlist) == 0) break;
-                       for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
-                               extract(buf, nttlist, i);
-                               if (!strcasecmp(buf, nodename)) ++retval;
-                       }
-                       break;
-       }
-
-       if (nttlist != NULL) lprintf(9, "nttlist=<%s>\n", nttlist);
-       end_critical_section(S_NTTLIST);
-       return(retval);
-}
-
-
-
-
-
-
-
 /* 
  * Read the network map from its configuration file into memory.
  */
@@ -1310,7 +1246,13 @@ void cmd_netp(char *cmdbuf)
                return;
        }
 
+       if (network_talking_to(node, NTT_CHECK)) {
+               cprintf("%d Already talking to %s right now\n", ERROR);
+               return;
+       }
+
        safestrncpy(CC->net_node, node, sizeof CC->net_node);
+       network_talking_to(node, NTT_ADD);
        cprintf("%d authenticated as network node '%s'\n", OK,
                CC->net_node);
 }
index 91a9afb1802ad5546111002362a3ce18524f0563..60ebce1e589d69a296e86fb9dbd59010e320a534 100644 (file)
@@ -8,12 +8,3 @@ struct SpoolControl {
        struct namelist *listrecps;
        struct namelist *ignet_push_shares;
 };
-
-/*
- * Operations that can be performed by network_talking_to()
- */
-enum {
-       NTT_ADD,
-       NTT_REMOVE,
-       NTT_CHECK
-};
index a246e00e4813e253f81adaccd1dee75646f02554..cedb01e4af5d403db8a9b2441aadf388f313e148 100644 (file)
@@ -425,13 +425,29 @@ void logged_in_response(void)
 void logout(struct CitContext *who)
 {
        who->logged_in = 0;
+
+       /*
+        * If there is a download in progress, abort it.
+        */
        if (who->download_fp != NULL) {
                fclose(who->download_fp);
                who->download_fp = NULL;
        }
+
+       /*
+        * If there is an upload in progress, abort it.
+        */
        if (who->upload_fp != NULL) {
                abort_upl(who);
        }
+
+       /*
+        * If we were talking to a network node, we're not anymore...
+        */
+       if (strlen(who->net_node) > 0) {
+               network_talking_to(who->net_node, NTT_REMOVE);
+       }
+
        /* Do modular stuff... */
        PerformSessionHooks(EVT_LOGOUT);
 }