1 #ifndef LIGHTNING_COMMON_STATUS_H
2 #define LIGHTNING_COMMON_STATUS_H
3 #include "config.h"
4 #include <ccan/short_types/short_types.h>
5 #include <common/status_levels.h>
6 
7 struct channel_id;
8 struct daemon_conn;
9 struct node_id;
10 struct per_peer_state;
11 
12 /* Simple status reporting API. */
13 void status_setup_sync(int fd);
14 void status_setup_async(struct daemon_conn *master);
15 
16 /* Send a printf-style debugging trace. */
17 void status_fmt(enum log_level level,
18 		const struct node_id *peer,
19 		const char *fmt, ...)
20 	PRINTF_FMT(3,4);
21 
22 /* vprintf-style */
23 void status_vfmt(enum log_level level,
24 		 const struct node_id *peer,
25 		 const char *fmt, va_list ap);
26 
27 /* Usually we only log the packet names, not contents. */
28 extern volatile bool logging_io;
29 
30 /* This logs a debug summary if IO logging not enabled. */
31 void status_peer_io(enum log_level iodir,
32 		    const struct node_id *peer,
33 		    const u8 *p);
34 void status_io(enum log_level iodir,
35 	       const struct node_id *peer,
36 	       const char *who,
37 	       const void *data, size_t len);
38 
39 /* Helpers */
40 #define status_debug(...)			\
41 	status_fmt(LOG_DBG, NULL, __VA_ARGS__)
42 #define status_info(...)			\
43 	status_fmt(LOG_INFORM, NULL, __VA_ARGS__)
44 #define status_unusual(...)			\
45 	status_fmt(LOG_UNUSUAL, NULL, __VA_ARGS__)
46 #define status_broken( ...)			\
47 	status_fmt(LOG_BROKEN, NULL, __VA_ARGS__)
48 
49 /* For daemons which handle multiple peers */
50 #define status_peer_debug(peer, ...)			\
51 	status_fmt(LOG_DBG, (peer), __VA_ARGS__)
52 #define status_peer_info(peer, ...)			\
53 	status_fmt(LOG_INFORM, (peer), __VA_ARGS__)
54 #define status_peer_unusual(peer, ...)			\
55 	status_fmt(LOG_UNUSUAL, (peer), __VA_ARGS__)
56 #define status_peer_broken(peer, ...)			\
57 	status_fmt(LOG_BROKEN, (peer), __VA_ARGS__)
58 
59 /* Send a failure status code with printf-style msg, and exit. */
60 void status_failed(enum status_failreason code,
61 		   const char *fmt, ...) PRINTF_FMT(2,3) NORETURN;
62 
63 /* Helper for master failures: sends STATUS_FATAL_MASTER_IO.
64  * msg NULL == read failure. */
65 void master_badmsg(u32 type_expected, const u8 *msg) NORETURN;
66 
67 void status_send(const u8 *msg TAKES);
68 void status_send_fatal(const u8 *msg TAKES) NORETURN;
69 
70 /* Only for sync status! */
71 void status_send_fd(int fd);
72 
73 #if DEVELOPER
74 /* Print BROKEN status: callback for dump_memleak. */
75 void memleak_status_broken(const char *fmt, ...);
76 #endif
77 
78 #endif /* LIGHTNING_COMMON_STATUS_H */
79