NTT: add a debug facility to dump all currently locked peers
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 25 Mar 2013 13:56:49 +0000 (14:56 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 25 Mar 2013 13:56:49 +0000 (14:56 +0100)
citadel/nttlist.c

index 5831d4a7db4117a0a82f8873c08b5a21edf31b07..a38cd35db49d83216a367652595398f4d880418b 100644 (file)
@@ -23,6 +23,7 @@
  *                 Network maps: evaluate other nodes                          *
  *-----------------------------------------------------------------------------*/
 int NTTDebugEnabled = 0;
+int NTTDumpEnabled = 0;
 
 /*
  * network_talking_to()  --  concurrency checker
@@ -67,6 +68,29 @@ int CtdlNetworkTalkingTo(const char *nodename, long len, int operation)
                        break;
        }
 
+       if (NTTDumpEnabled)
+       {
+               HashPos *It;
+               StrBuf *NTTDump;
+               long len;
+               const char *Key;
+               void *v;
+               NTTDump = NewStrBuf ();
+
+               It = GetNewHashPos(nttlist, 0);
+               while (GetNextHashPos(nttlist, It, &len, &Key, &v))
+               {
+                       if (StrLength(NTTDump) > 0)
+                               StrBufAppendBufPlain(NTTDump, HKEY("|"), 0);
+                       StrBufAppendBuf(NTTDump, (StrBuf*) v, 0);
+               }
+               DeleteHashPos(&It);
+
+               syslog(LOG_DEBUG, "nttlist: Dump: [%d] <%s>\n", 
+                      GetCount(nttlist),
+                      ChrPtr(NTTDump));
+               FreeStrBuf(&NTTDump);
+       }
        end_critical_section(S_NTTLIST);
        return(retval);
 }
@@ -88,6 +112,11 @@ void SetNTTDebugEnabled(const int n)
        NTTDebugEnabled = n;
 }
 
+void SetNTTDumpEnabled(const int n)
+{
+       NTTDumpEnabled = n;
+}
+
 
 
 /*
@@ -98,6 +127,7 @@ CTDL_MODULE_INIT(nttlist)
        if (!threading)
        {
                CtdlRegisterDebugFlagHook(HKEY("networktalkingto"), SetNTTDebugEnabled, &NTTDebugEnabled);
+               CtdlRegisterDebugFlagHook(HKEY("dumpnetworktalkingto"), SetNTTDumpEnabled, &NTTDumpEnabled);
 
                CtdlRegisterCleanupHook(cleanup_nttlist);
        }