Belle II Software development
nsm2.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#ifndef __nsm2_h__
10#define __nsm2_h__
11
12#if defined(__cplusplus)
13extern "C" {
14#endif
15
16/* -- version info */
17
18#define NSM_REQUIRED_VERSION 1999 /* required version */
19#define NSM_LIBRARY_VERSION 2008 /* library version */
20#define NSM_PACKAGE_VERSION 2008 /* package version */
21
22/*
23 20120723 1900 file created
24 20121115 1903 queue based message sending starts working
25 20121117 1904 queue based touchsys working for newclient
26 20121218 1905 fix delclient
27 (next is to implement hash)
28 20130116 1906 hash implemented
29 20130117 1907 hash fix1 (***hash not in network-byte order yet)
30 20130117 1908 hash fix (***hash in network-byte order)
31 20130219 1909 first version with usrcpymem (still many bugs)
32 20130303 1910 alpha version release candidate
33 20131218 1914 merged with Konno veresion
34 20131219 1915 uid/gid for MEM shm
35 20131222 1916 printlog infinite loop fix
36 20131229 1917 no change in nsmd2, update in nsminfo2 and b2lib
37 20131230 1918 libs: strerror fix, initnet fix, stdint fix, bridge fix
38 20140104 1919 b2libs: b2nsm_ok text, nsmd2: disid fix
39 20140105 1920 nsminfo2 from nsmd2
40 20140106 1921 destroyconn fix, etc
41 20140107 1922 fixing the case when both master/deputy are killed
42 20140107 1923 fixing priority passing
43 20140114 1924 rewrite of nsmd_do_newmaster
44 20140117 1924 nsmd2 check error before going background, many crucial bug
45 fixes on nsmd master/deputy switching, color nsminfo2
46 20140124 1925 anonymous node
47 20140304 1926 new parser, 20 byte smaller chunk size for IP header
48 20140305 1927 freeq fix for sending a long packet
49 20140305 1928 fix to 1927, DoS vulnerability test, still far from OK
50 20140306 1929 no fprintf for DoS vulnerability trial tests, in vain
51 20140306 1930 restore logfp and cleanup (but still write instead of fwrite)
52 20140516 1931 corelib: ip address from shm if not specified
53 20140614 1932 corelib: sprintf ip address if host is missing
54 20140614 1933 corelib: use nodhash for nsmlib_nodeid
55 20140902 1934 static bsizbuf pollution fix, broken tcprecv debug
56 20140902 1935 memset fix
57 20140903 1936 debug message fix
58 20140903 1937 nsmparse fix (see nsmparse.c)
59 20140917 1938 newclient error return fix / shm cleanup fix
60 20140917 1939 skip revision check by -1
61 20140921 1940 bytes in nsmparse_t, flushmem, less DBG in nsmd2
62 20140922 1941 nsmget is added
63 20140922 1942 nodtim fix
64 20150520 1943 destroyconn fix [for anonymous and for sys.ready]
65 20150521 1944 new protocol version, master reconnect fix
66 20150808 1945 updates for PNNL summer school tutorial
67 20160420 1946 suppress debug output of nsmd2 and b2lib
68 20170613 1947 nsmd2 update for USRCPYMEM protection
69 20180326 1959 based on 1947, just change the handling of -o option
70 20180327 1960 delconn/touchsys fix, better log, nsminfo2 hostname
71 20180328 1961 limit syscpymem.pos in uint16 range
72 20180329 1962 nsmlib.h fix for nsmlib_parsefile type
73 20180404 1963 nsminfo2 no hostname resolving by default
74 20180412 1964 one more nsminfo2 update on hostname cache
75 20180417 1965 suppress "bad" in usrcpymem if not ready
76 20180423 1966 destroyconn when write error at tcpwriteq
77 20180430 1967 src/dest at command and lastmsg at delconn for debug
78 20180502 1968 fix nsmd_dbg of 1967 printing all DBG messages
79 20180504 1969 b2nsm_nodename restored from 1957
80 20180515 1970 int16_t fix for owner in usrcpymem
81 20180519 1971 tcprecv static buffer shift upon delcon
82 20180521 1972 further debug of 1971
83 20180523 1973 nsminfo2 usage print
84 20180709 1974 nsmlib memory leak fix, etc, nsmd2 is rolled back to 1970
85 20180711 1975 nsmlib update again
86 20180801 1976 nsmd2 for better shm handling, b2nsm_term (experimental)
87 20180802 1977 example update, shmget fix, pipe close, USRCPYMEM delay
88 20180811 1978 fix prio, ready, forward, etc for master switch
89 20180815 1979 nsmd2 fix conid on master, nsminfo2 -X fix
90 20180815 1980 nsmd2 partial fix of node already exists
91 20180815 1981 nsmd2 hopefully final fix of node already exists
92 20180820 1982 nsmd2 kill HUP when connection is closed
93 20180820 1983 nsmd2 tcprecv local conid shift upon delcon, c++example added
94 20180822 1984 nsmd2 quick patch to avoid kill 0 HUP
95 20180823 1985 nsmd2 debug for tcprecv assert
96 20180824 1986 nsmd2 tcprecv debug continue, localtime => localtime_r
97 20180826 1987 nsmd2 tcprecv debug done, nsmd_localtime_r, verbose log
98 20180826 1988 nsmd2 code cleanup and suppress log for release version
99 20180902 1989 c++example fix, simplest.cc is added
100 20180927 1990 nsmd2 another orphan node fix, b2lib fixes
101 20181009 1991 restoring 1970 and cope with 1978 gen/prio fix
102 20181029 1992 double free bug fix
103 20181029 1993 experimental: do not die in do_delclient bad ip
104 20190415 1994 add: NSMESHMNOSYS, NSMESHMACCMEM, nsmc->errn
105 20190524 1994 mod: NSMENODEST, shm handling, nodeproc, makefile
106 20190524 1995 add: nsmstat2, fix: nsmd2 ocnt/osiz/otim
107 20190529 1994 fix: nsmlib2.c null sysp handling
108 20190529 1995 merge: fix in 1994
109 20190530 1996 fix: nsmd2 int function must always return (for g++ 8.2.0 -O)
110 20190724 1997 mod: version definition, nsminfo2 format, log filename
111 20190903 1998 fix: nsmd2 momentary deputy, select timeout in tcprecv
112 20190913 1999 mod: b2nsm_logging and b2nsm_context return previous value
113 20191002 1999 mod: nsmsys2.h should not be needed by user
114 20191123 1999 fix: nsm2sh send_vset
115 20200121 1999 fix: call destroyconn upon new re-accept
116 20200122 1999 fix: reuse tm in reopenlog
117 20200122 1999 fix: bad tcphead
118 20200127 2000 dbg: nsmstat2 crash
119 20200314 2001 dbg: nsmstat2 crash (32-bit host), add: localhost support
120 20200416 2002 add: killnsm2, mod: nsmd2.cc code cleanup
121 20200520 2003 fix: bad tcphead by newclient, avoid already exist error
122 20200520 2004 fix: close fd 0,1,2 before running in background
123 20200522 2005 fix: allow udp socket == 0, eliminate log at startup with -b
124 20200603 2006 fix: corelib nnod fix
125 20210315 2007 fix: corelib nsmlib_parsefree fix for nsmlib_allocmem
126 20220425 2008 mod: nsmd2 ackdaemon format and handling, allocmem handling
127 */
128
129/* -- DATA TYPES ----------------------------------------------------- */
130#ifndef __nsm2_typedef_nonstdint__
131#define __nsm2_typedef_nonstdint__
132#include "stdint.h"
133typedef uint8_t byte8;
134typedef uint16_t uint16;
135typedef uint32_t uint32;
136typedef uint64_t uint64;
137typedef int16_t int16;
138typedef int32_t int32;
139typedef int64_t int64;
140#endif /* nsm2_typedef_nonstdint */
141
142#ifndef __nsm2_typedef_context__
143#define __nsm2_typedef_context__
144struct NSMcontext_struct;
145typedef struct NSMcontext_struct NSMcontext;
146#endif /* nsm2_typedef_context */
147
148/* request offset */
149#define NSMREQ_FIRST (0x1000)
150
151/* no error */
152#define NSMENOERR (0)
153
154/* unexpected system or internal errors */
155#define NSMEALLOC (-101)
156#define NSMESOCKET (-102)
157#define NSMESOCKDGRAM (-103)
158#define NSMEGIFCONF (-104)
159#define NSMEGIFFLAGS (-105)
160#define NSMESOCKREUSE (-106)
161#define NSMESOCKSNDBUF (-107)
162#define NSMESOCKRCVBUF (-108)
163#define NSMERDSELECT (-109)
164#define NSMERDUID (-110)
165#define NSMENOPIPE (-111)
166#define NSMESELECT (-112)
167#define NSMETIMEOUT (-113)
168#define NSMEWRITE (-114)
169#define NSMECLOSED (-115)
170#define NSMEPIPEREAD (-116)
171#define NSMEPIPEWRITE (-117)
172/* #define NSMEMAXRETRY (-118) */
173#define NSMEDATID (-118)
174#define NSMEUNEXPECTED (-119)
175
176/* possible errors by user parameters */
177#define NSMENOMASTER (-1) /* there is no master nsmd yet */
178#define NSMEINVNAME (-2) /* invalid name (length or character) */
179#define NSMEINVPAR (-3) /* invalid parameter(s) */
180#define NSMENODEEXIST (-4) /* node already exist */
181#define NSMEFULNODE (-5) /* no more NSM node */
182#define NSMENODEST (-6) /* destination node does not exist */
183#define NSMEINVFMT (-7) /* invalid data format */
184#define NSMEMEMEXIST (-8) /* data already exists */
185#define NSMENOMOREMEM (-9) /* no more data area */
186#define NSMEOPENED (-10) /* already opened */
187#define NSMENODENAME (-11)
188#define NSMENODELONG (-12)
189#define NSMEHOSTNAME (-13)
190#define NSMEALREADYP (-14)
191#define NSMEALREADYS (-15)
192#define NSMEALREADYH (-16)
193#define NSMENOIF (-17)
194#define NSMENONSMD (-18)
195#define NSMENOUID (-19)
196#define NSMERDCLOSE (-20)
197#define NSMEACCESS (-21)
198#define NSMESHMGETSYS (-22)
199#define NSMESHMATSYS (-23)
200#define NSMESHMGETMEM (-24)
201#define NSMESHMATMEM (-25)
202#define NSMENOINIT (-26)
203#define NSMEPERM (-27) /* anonymous node can't send */
204#define NSMEINVDATA (-28) /* len==0 xor data==0 */
205#define NSMEINVFUNC (-29)
206#define NSMEMAXFUNC (-30)
207#define NSMENOMEM (-31) /* data does not exist (openmem) */
208#define NSMEBADFMT (-32) /* data format is inconsistent (openmem) */
209#define NSMEBADREV (-33) /* data revision is inconsistent (openmem) */
210#define NSMEPARSE (-34) /* data format parse error (openmem) */
211#define NSMECONNECT (-35) /* connection error */
212#define NSMEINVPTR (-36) /* invalid data pointer */
213#define NSMESHMNOSYS (-37) /* ESHMGETSYS and ENOENT */
214#define NSMESHMACCES (-38) /* ESHMGETMEM and EACCES */
215#define NSMEEMPTYDEST (-39) /* empty string for destination node */
216#define NSMENGMASTER (-40) /* master nsmd2 temporarily unreachable */
217#define NSMETIMEOUTW (-41) /* timeout in sending to nsmd2 */
218#define NSMETIMEOUTR (-42) /* timeout in receiving from nsmd2 */
219#define NSMENOSUCHREQ (-43) /* no such registered request */
220#define NSMEBADHASH (-44) /* broken internal hash table */
221#define NSMENODEHERE (-45) /* node already exist on the same host */
222
223/* NSMmsg (in host byte order) */
224typedef struct {
225 uint16_t req;
226 uint16_t seq;
227 int16_t node; /* source/destination nodeid, or (-1) if not an NSM client */
228 uint8_t npar;
229 uint16_t len;
230 int32_t pars[256]; /* signed */
231 const char* datap;
232} NSMmsg;
233
234typedef void (*NSMcallback_t)(NSMmsg* msg, NSMcontext* nsmc);
235typedef void (*NSMfunc_t)(NSMmsg* msg, NSMcontext* nsmc);
236
237#if defined(__cplusplus)
238}
239#endif
240
241#endif /* __nsm2_h__ */
242
243/* -- (emacs outline mode setup) ------------------------------------- */
244/*
245// Local Variables: ***
246// mode:outline-minor ***
247// outline-regexp:"^/\\* --[+ ]" ***
248// End: ***
249*/
Definition: nsm2.h:224