From: Wilfried Goesgens Date: Thu, 3 May 2012 20:44:33 +0000 (+0200) Subject: NTTList: move into networking module X-Git-Tag: v8.11~46 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=9caef44a2f42ab81b2489ae19859f1bbc25d4430 NTTList: move into networking module - use session logout hook to free the NTTList entry instead of adding a dependency to user_ops.c - make logging of NTT configurable - move ntt locking code into serv_network.c --- diff --git a/citadel/file_ops.c b/citadel/file_ops.c index 460e2a85b..d1b529d57 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -45,59 +45,6 @@ #include "ctdl_module.h" #include "user_ops.h" -/* - * network_talking_to() -- concurrency checker - */ -static HashList *nttlist = NULL; -int network_talking_to(const char *nodename, long len, int operation) { - - int retval = 0; - HashPos *Pos = NULL; - void *vdata; - - begin_critical_section(S_NTTLIST); - - switch(operation) { - - case NTT_ADD: - if (nttlist == NULL) - nttlist = NewHash(1, NULL); - Put(nttlist, nodename, len, NewStrBufPlain(nodename, len), HFreeStrBuf); - syslog(LOG_DEBUG, "nttlist: added <%s>\n", nodename); - break; - case NTT_REMOVE: - if ((nttlist == NULL) || - (GetCount(nttlist) == 0)) - break; - Pos = GetNewHashPos(nttlist, 1); - if (GetHashPosFromKey (nttlist, nodename, len, Pos)) - DeleteEntryFromHash(nttlist, Pos); - DeleteHashPos(&Pos); - syslog(LOG_DEBUG, "nttlist: removed <%s>\n", nodename); - - break; - - case NTT_CHECK: - if ((nttlist == NULL) || - (GetCount(nttlist) == 0)) - break; - if (GetHash(nttlist, nodename, len, &vdata)) - retval ++; - syslog(LOG_DEBUG, "nttlist: have [%d] <%s>\n", retval, nodename); - break; - } - - end_critical_section(S_NTTLIST); - return(retval); -} - -void cleanup_nttlist(void) -{ - begin_critical_section(S_NTTLIST); - DeleteHash(&nttlist); - end_critical_section(S_NTTLIST); -} - /* @@ -811,6 +758,7 @@ void cmd_nuop(char *cmdbuf) CTDL_MODULE_INIT(file_ops) { if (!threading) { + CtdlRegisterProtoHook(cmd_delf, "DELF", "Delete a file"); CtdlRegisterProtoHook(cmd_movf, "MOVF", "Move a file"); CtdlRegisterProtoHook(cmd_open, "OPEN", "Open a download file transfer"); @@ -823,7 +771,6 @@ CTDL_MODULE_INIT(file_ops) CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Open a network spool file for upload"); CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Open an image file for download"); CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Upload an image file"); - CtdlRegisterCleanupHook(cleanup_nttlist); } /* return our Subversion id for the Log */ return "file_ops"; diff --git a/citadel/file_ops.h b/citadel/file_ops.h index a2483a126..080c83e76 100644 --- a/citadel/file_ops.h +++ b/citadel/file_ops.h @@ -6,15 +6,5 @@ void OpenCmdResult (char *, const char *); void abort_upl (CitContext *who); -int network_talking_to(const char *nodename, long len, int operation); - -/* - * Operations that can be performed by network_talking_to() - */ -enum { - NTT_ADD, - NTT_REMOVE, - NTT_CHECK -}; #endif /* FILE_OPS_H */ diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index dc61feb47..7ac84729c 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -618,14 +618,90 @@ int network_room_handler (struct ctdlroom *room) return 0; } +int NTTDebugEnabled = 0; + +/* + * network_talking_to() -- concurrency checker + */ +static HashList *nttlist = NULL; +int network_talking_to(const char *nodename, long len, int operation) { + + int retval = 0; + HashPos *Pos = NULL; + void *vdata; + + begin_critical_section(S_NTTLIST); + + switch(operation) { + + case NTT_ADD: + if (nttlist == NULL) + nttlist = NewHash(1, NULL); + Put(nttlist, nodename, len, NewStrBufPlain(nodename, len), HFreeStrBuf); + if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: added <%s>\n", nodename); + break; + case NTT_REMOVE: + if ((nttlist == NULL) || + (GetCount(nttlist) == 0)) + break; + Pos = GetNewHashPos(nttlist, 1); + if (GetHashPosFromKey (nttlist, nodename, len, Pos)) + DeleteEntryFromHash(nttlist, Pos); + DeleteHashPos(&Pos); + if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: removed <%s>\n", nodename); + + break; + + case NTT_CHECK: + if ((nttlist == NULL) || + (GetCount(nttlist) == 0)) + break; + if (GetHash(nttlist, nodename, len, &vdata)) + retval ++; + if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: have [%d] <%s>\n", retval, nodename); + break; + } + + end_critical_section(S_NTTLIST); + return(retval); +} + +void cleanup_nttlist(void) +{ + begin_critical_section(S_NTTLIST); + DeleteHash(&nttlist); + end_critical_section(S_NTTLIST); +} + + + +void network_logout_hook(void) +{ + CitContext *CCC = MyContext(); + + /* + * If we were talking to a network node, we're not anymore... + */ + if (!IsEmptyStr(CCC->net_node)) { + network_talking_to(CCC->net_node, strlen(CCC->net_node), NTT_REMOVE); + } +} /* * Module entry point */ +void SetNTTDebugEnabled(const int n) +{ + NTTDebugEnabled = n; +} + CTDL_MODULE_INIT(network) { if (!threading) { + CtdlRegisterDebugFlagHook(HKEY("networktalkingto"), SetNTTDebugEnabled, &NTTDebugEnabled); + CtdlRegisterCleanupHook(cleanup_nttlist); + CtdlRegisterSessionHook(network_logout_hook, EVT_LOGOUT); CtdlRegisterProtoHook(cmd_nsyn, "NSYN", "Synchronize room to node"); CtdlRegisterRoomHook(network_room_handler); CtdlRegisterCleanupHook(destroy_network_queue_room_locked); diff --git a/citadel/modules/network/serv_network.h b/citadel/modules/network/serv_network.h index 549959079..d0cba74ef 100644 --- a/citadel/modules/network/serv_network.h +++ b/citadel/modules/network/serv_network.h @@ -17,3 +17,13 @@ void network_queue_room(struct ctdlroom *, void *); void network_bounce(struct CtdlMessage *msg, char *reason); int network_usetable(struct CtdlMessage *msg); +int network_talking_to(const char *nodename, long len, int operation); + +/* + * Operations that can be performed by network_talking_to() + */ +enum { + NTT_ADD, + NTT_REMOVE, + NTT_CHECK +}; diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 7f72befa7..2ca3b4220 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -799,13 +799,6 @@ void CtdlUserLogout(void) abort_upl(CCC); } - /* - * If we were talking to a network node, we're not anymore... - */ - if (!IsEmptyStr(CCC->net_node)) { - network_talking_to(CCC->net_node, strlen(CCC->net_node), NTT_REMOVE); - } - /* Run any hooks registered by modules... */ PerformSessionHooks(EVT_LOGOUT);