mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 15:44:21 +01:00
status: generate messages rather than marshal/unmarshal manually.
Now we have wirestring, this is much more natural. And with the 24M length limit, we needn't be so concerned about dumping 64k peer messages in hex. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
c7b693d7ce
commit
fd498be7ca
@@ -1,26 +1,22 @@
|
||||
#include <common/gen_status_wire.h>
|
||||
#include <lightningd/log_status.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
bool log_status_msg(struct log *log, const u8 *msg)
|
||||
{
|
||||
size_t max = tal_len(msg);
|
||||
int type = fromwire_u16(&msg, &max);
|
||||
enum log_level level;
|
||||
char *entry;
|
||||
u8 *data;
|
||||
enum log_level level;
|
||||
|
||||
if (type < STATUS_LOG_MIN || type > STATUS_LOG_MAX)
|
||||
return false;
|
||||
|
||||
level = type - STATUS_LOG_MIN;
|
||||
if (level == LOG_IO_IN || level == LOG_IO_OUT) {
|
||||
log_io(log, level, "", msg, max);
|
||||
} else {
|
||||
int i;
|
||||
/* Truncate if unprintable */
|
||||
for (i = 0; i < max; i++) {
|
||||
if (!cisprint((char)msg[i]))
|
||||
break;
|
||||
if (fromwire_status_log(msg, msg, NULL, &level, &entry)) {
|
||||
if (level != LOG_IO_IN && level != LOG_IO_OUT) {
|
||||
log_(log, level, "%s", entry);
|
||||
return true;
|
||||
}
|
||||
} else if (fromwire_status_io(msg, msg, NULL, &level, &data)) {
|
||||
if (level == LOG_IO_IN || level == LOG_IO_OUT) {
|
||||
log_io(log, level, "", data, tal_len(data));
|
||||
return true;
|
||||
}
|
||||
log_(log, level, "%.*s%s", i, msg, i == max ? "" : "...");
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user