Browse Source
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>ppa-0.6.1
Rusty Russell
7 years ago
committed by
Christian Decker
19 changed files with 147 additions and 111 deletions
@ -0,0 +1,33 @@ |
|||
#include <common/status_wire.h> |
|||
#include <wire/wire.h> |
|||
|
|||
enum status_failreason fromwire_status_failreason(const u8 **cursor, |
|||
size_t *max) |
|||
{ |
|||
u8 r = fromwire_u8(cursor, max); |
|||
if (r > STATUS_FAIL_MAX) { |
|||
fromwire_fail(cursor, max); |
|||
r = STATUS_FAIL_INTERNAL_ERROR; |
|||
} |
|||
return r; |
|||
} |
|||
|
|||
enum log_level fromwire_log_level(const u8 **cursor, size_t *max) |
|||
{ |
|||
u8 l = fromwire_u8(cursor, max); |
|||
if (l > LOG_LEVEL_MAX) { |
|||
fromwire_fail(cursor, max); |
|||
l = LOG_BROKEN; |
|||
} |
|||
return l; |
|||
} |
|||
|
|||
void towire_log_level(u8 **pptr, enum log_level level) |
|||
{ |
|||
towire_u8(pptr, level); |
|||
} |
|||
|
|||
void towire_status_failreason(u8 **pptr, enum status_failreason reason) |
|||
{ |
|||
towire_u8(pptr, reason); |
|||
} |
Can't render this file because it has a wrong number of fields in line 3.
|
@ -0,0 +1,14 @@ |
|||
#ifndef LIGHTNING_COMMON_STATUS_WIRE_H |
|||
#define LIGHTNING_COMMON_STATUS_WIRE_H |
|||
#include "config.h" |
|||
#include <ccan/short_types/short_types.h> |
|||
#include <common/status_levels.h> |
|||
#include <stddef.h> |
|||
|
|||
enum status_failreason fromwire_status_failreason(const u8 **cursor, |
|||
size_t *max); |
|||
enum log_level fromwire_log_level(const u8 **cursor, size_t *max); |
|||
|
|||
void towire_log_level(u8 **pptr, enum log_level level); |
|||
void towire_status_failreason(u8 **pptr, enum status_failreason reason); |
|||
#endif /* LIGHTNING_COMMON_STATUS_WIRE_H */ |
@ -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; |
|||
} |
|||
|
Loading…
Reference in new issue