Belle II Software  release-08-01-10
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 #ifndef __nsm2_h__
9 #define __nsm2_h__
10 
11 #if defined(__cplusplus)
12 extern "C" {
13 #endif
14 #if defined(__dummy_close_bracket_to_cheat_emacs_auto_indent)
15 }
16 #endif
17 
18 /* -- version info */
19 
20 #define NSM_REQUIRED_VERSION 1999 /* required version */
21 #define NSM_LIBRARY_VERSION 2003 /* library version */
22 #define NSM_PACKAGE_VERSION 2006 /* package version */
23 
24 /*
25  20120723 1900 file created
26  20121115 1903 queue based message sending starts working
27  20121117 1904 queue based touchsys working for newclient
28  20121218 1905 fix delclient
29  (next is to implement hash)
30  20130116 1906 hash implemented
31  20130117 1907 hash fix1 (***hash not in network-byte order yet)
32  20130117 1908 hash fix (***hash in network-byte order)
33  20130219 1909 first version with usrcpymem (still many bugs)
34  20130303 1910 alpha version release candidate
35  20131218 1914 merged with Konno veresion
36  20131219 1915 uid/gid for MEM shm
37  20131222 1916 printlog infinite loop fix
38  20131229 1917 no change in nsmd2, update in nsminfo2 and b2lib
39  20131230 1918 libs: strerror fix, initnet fix, stdint fix, bridge fix
40  20140104 1919 b2libs: b2nsm_ok text, nsmd2: disid fix
41  20140105 1920 nsminfo2 from nsmd2
42  20140106 1921 destroyconn fix, etc
43  20140107 1922 fixing the case when both master/deputy are killed
44  20140107 1923 fixing priority passing
45  20140114 1924 rewrite of nsmd_do_newmaster
46  20140117 1924 nsmd2 check error before going background, many crucial bug
47  fixes on nsmd master/deputy switching, color nsminfo2
48  20140124 1925 anonymous node
49  20140304 1926 new parser, 20 byte smaller chunk size for IP header
50  20140305 1927 freeq fix for sending a long packet
51  20140305 1928 fix to 1927, DoS vulnerability test, still far from OK
52  20140306 1929 no fprintf for DoS vulnerability trial tests, in vain
53  20140306 1930 restore logfp and cleanup (but still write instead of fwrite)
54  20140516 1931 corelib: ip address from shm if not specified
55  20140614 1932 corelib: sprintf ip address if host is missing
56  20140614 1933 corelib: use nodhash for nsmlib_nodeid
57  20140902 1934 static bsizbuf pollution fix, broken tcprecv debug
58  20140902 1935 memset fix
59  20140903 1936 debug message fix
60  20140903 1937 nsmparse fix (see nsmparse.c)
61  20140917 1938 newclient error return fix / shm cleanup fix
62  20140917 1939 skip revision check by -1
63  20140921 1940 bytes in nsmparse_t, flushmem, less DBG in nsmd2
64  20140922 1941 nsmget is added
65  20140922 1942 nodtim fix
66  20150520 1943 destroyconn fix [for anonymous and for sys.ready]
67  20150521 1944 new protocol version, master reconnect fix
68  20150808 1945 updates for PNNL summer school tutorial
69  20160420 1946 suppress debug output of nsmd2 and b2lib
70  20170613 1947 nsmd2 update for USRCPYMEM protection
71  20180326 1959 based on 1947, just change the handling of -o option
72  20180327 1960 delconn/touchsys fix, better log, nsminfo2 hostname
73  20180328 1961 limit syscpymem.pos in uint16 range
74  20180329 1962 nsmlib.h fix for nsmlib_parsefile type
75  20180404 1963 nsminfo2 no hostname resolving by default
76  20180412 1964 one more nsminfo2 update on hostname cache
77  20180417 1965 suppress "bad" in usrcpymem if not ready
78  20180423 1966 destroyconn when write error at tcpwriteq
79  20180430 1967 src/dest at command and lastmsg at delconn for debug
80  20180502 1968 fix nsmd_dbg of 1967 printing all DBG messages
81  20180504 1969 b2nsm_nodename restored from 1957
82  20180515 1970 int16_t fix for owner in usrcpymem
83  20180519 1971 tcprecv static buffer shift upon delcon
84  20180521 1972 further debug of 1971
85  20180523 1973 nsminfo2 usage print
86  20180709 1974 nsmlib memory leak fix, etc, nsmd2 is rolled back to 1970
87  20180711 1975 nsmlib update again
88  20180801 1976 nsmd2 for better shm handling, b2nsm_term (experimental)
89  20180802 1977 example update, shmget fix, pipe close, USRCPYMEM delay
90  20180811 1978 fix prio, ready, forward, etc for master switch
91  20180815 1979 nsmd2 fix conid on master, nsminfo2 -X fix
92  20180815 1980 nsmd2 partial fix of node already exists
93  20180815 1981 nsmd2 hopefully final fix of node already exists
94  20180820 1982 nsmd2 kill HUP when connection is closed
95  20180820 1983 nsmd2 tcprecv local conid shift upon delcon, c++example added
96  20180822 1984 nsmd2 quick patch to avoid kill 0 HUP
97  20180823 1985 nsmd2 debug for tcprecv assert
98  20180824 1986 nsmd2 tcprecv debug continue, localtime => localtime_r
99  20180826 1987 nsmd2 tcprecv debug done, nsmd_localtime_r, verbose log
100  20180826 1988 nsmd2 code cleanup and suppress log for release version
101  20180902 1989 c++example fix, simplest.cc is added
102  20180927 1990 nsmd2 another orphan node fix, b2lib fixes
103  20181009 1991 restoring 1970 and cope with 1978 gen/prio fix
104  20181029 1992 double free bug fix
105  20181029 1993 experimental: do not die in do_delclient bad ip
106  20190415 1994 add: NSMESHMNOSYS, NSMESHMACCMEM, nsmc->errn
107  20190524 1994 mod: NSMENODEST, shm handling, nodeproc, makefile
108  20190524 1995 add: nsmstat2, fix: nsmd2 ocnt/osiz/otim
109  20190529 1994 fix: nsmlib2.c null sysp handling
110  20190529 1995 merge: fix in 1994
111  20190530 1996 fix: nsmd2 int function must always return (for g++ 8.2.0 -O)
112  20190724 1997 mod: version definition, nsminfo2 format, log filename
113  20190903 1998 fix: nsmd2 momentary deputy, select timeout in tcprecv
114  20190913 1999 mod: b2nsm_logging and b2nsm_context return previous value
115  20191002 1999 mod: nsmsys2.h should not be needed by user
116  20191123 1999 fix: nsm2sh send_vset
117  20200121 1999 fix: call destroyconn upon new re-accept
118  20200122 1999 fix: reuse tm in reopenlog
119  20200122 1999 fix: bad tcphead
120  20200127 2000 dbg: nsmstat2 crash
121  20200314 2001 dbg: nsmstat2 crash (32-bit host), add: localhost support
122  20200416 2002 add: killnsm2, mod: nsmd2.cc code cleanup
123  20200520 2003 fix: bad tcphead by newclient, avoid already exist error
124  20200520 2004 fix: close fd 0,1,2 before running in background
125  20200522 2005 fix: allow udp socket == 0, eliminate log at startup with -b
126  20200603 2006 fix: corelib nnod fix
127  */
128 
129 /* -- DATA TYPES ----------------------------------------------------- */
130 #ifndef __nsm2_typedef_nonstdint__
131 #define __nsm2_typedef_nonstdint__
132 #include "stdint.h"
133 typedef uint8_t byte8;
134 typedef uint16_t uint16;
135 typedef uint32_t uint32;
136 typedef uint64_t uint64;
137 typedef int16_t int16;
138 typedef int32_t int32;
139 typedef int64_t int64;
140 #endif /* nsm2_typedef_nonstdint */
141 
142 #ifndef __nsm2_typedef_context__
143 #define __nsm2_typedef_context__
144 struct NSMcontext_struct;
145 typedef 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) */
224 typedef 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 
234 typedef void (*NSMcallback_t)(NSMmsg* msg, NSMcontext* nsmc);
235 typedef void (*NSMfunc_t)(NSMmsg* msg, NSMcontext* nsmc);
236 
237 #if defined(__dummy_open_bracket_to_cheat_emacs_auto_indent)
238 __dummy_open_bracket_to_cheat_emacs_auto_indent {
239 #endif
240 #if defined(__cplusplus)
241 }
242 #endif
243 
244 #endif /* __nsm2_h__ */
245 
246 /* -- (emacs outline mode setup) ------------------------------------- */
247 /*
248 // Local Variables: ***
249 // mode:outline-minor ***
250 // outline-regexp:"^/\\* --[+ ]" ***
251 // End: ***
252 */
Definition: nsm2.h:224