* network_talking_to()
authorArt Cancro <ajc@citadel.org>
Sat, 6 Oct 2001 20:20:25 +0000 (20:20 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 6 Oct 2001 20:20:25 +0000 (20:20 +0000)
citadel/serv_network.c
citadel/serv_network.h
citadel/server.h

index 134ff2559d5c07e54ef312fcd685ca4dfe6b803c..81dd1aed916875072535e48193a0f9f98693aab7 100644 (file)
@@ -86,6 +86,68 @@ struct NetMap *the_netmap = NULL;
 
 
 
+/*
+ * network_talking_to()  --  concurrency checker
+ */
+int network_talking_to(char *nodename, int oper) {
+
+       static char *nttlist = NULL;
+       char *ptr = NULL;
+       int i;
+       char buf[SIZ];
+       int retval = 0;
+
+       begin_critical_section(S_NTTLIST);
+
+       switch(oper) {
+
+               case NTT_ADD:
+                       if (nttlist == NULL) nttlist = stdroop("");
+                       if (nttlist == NULL) return;
+                       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;
+       }
+
+       lprintf(9, "nttlist=<%s>\n", nttlist);
+       end_critical_section(S_NTTLIST);
+       return(retval);
+}
+
+
+
+
+
+
+
 /* 
  * Read the network map from its configuration file into memory.
  */
index 60ebce1e589d69a296e86fb9dbd59010e320a534..91a9afb1802ad5546111002362a3ce18524f0563 100644 (file)
@@ -8,3 +8,12 @@ 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 1163899cfca03e0e8ca5d2ab7f22c360b2b5baf4..c30b95254fd9981946905f28ffb738a337438fa4 100644 (file)
@@ -191,6 +191,7 @@ enum {
        S_CONFIG,
        S_WORKER_LIST,
        S_HOUSEKEEPING,
+       S_NTTLIST,
        MAX_SEMAPHORES
 };