Browse Source

devtools/decodemsg: decode node_announcement.addresses

$ ./devtools/decodemsg 01014bfa4585cb36194ce7c308e8d3d9032ff4e42ed4764a4c6d0a9a58da0a4e57e97fbd463577a5fd14347c60cc7bef2b40bd644337153564320b310b4d155cab1300005b3315de0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c035180266e4e3838ae383b3e382bbe383b3e382b92031e69daf000000000000000000000000004d010102030404d202000000000000000000000000000000002607039216a8b803f3acd758aa260704e00533f3e8f2aedaa8969b3d0fa03a96e857bbb28064dca5e147e934244b9ba50230032607

Before:
    WIRE_NODE_ANNOUNCEMENT:
    signature=304402204bfa4585cb36194ce7c308e8d3d9032ff4e42ed4764a4c6d0a9a58da0a4e57e902207fbd463577a5fd14347c60cc7bef2b40bd644337153564320b310b4d155cab13
    features=[]
    timestamp=1530074590
    node_id=0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518
    rgb_color=[0266e4]
    alias=[ナンセンス 1杯 e3838ae383b3e382bbe383b3e382b92031e69daf000000000000000000000000 ]
    addresses=[010102030404d202000000000000000000000000000000002607039216a8b803f3acd758aa260704e00533f3e8f2aedaa8969b3d0fa03a96e857bbb28064dca5e147e934244b9ba50230032607]

After:
    WIRE_NODE_ANNOUNCEMENT:
    signature=304402204bfa4585cb36194ce7c308e8d3d9032ff4e42ed4764a4c6d0a9a58da0a4e57e902207fbd463577a5fd14347c60cc7bef2b40bd644337153564320b310b4d155cab13
    features=[]
    timestamp=1530074590
    node_id=0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518
    rgb_color=[0266e4]
    alias=[ナンセンス 1杯 e3838ae383b3e382bbe383b3e382b92031e69daf000000000000000000000000 ]
    addresses=[ 1.2.3.4:1234 [::]:9735 silkroad6ownowfk.onion:9735 4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion:9735 ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
0bd82a8138
  1. 4
      devtools/Makefile
  2. 20
      devtools/decodemsg.c
  3. 22
      devtools/print_wire.c
  4. 1
      devtools/print_wire.h

4
devtools/Makefile

@ -4,13 +4,15 @@ DEVTOOLS_TOOL_SRC := devtools/bolt11-cli.c devtools/decodemsg.c devtools/onion.c
DEVTOOLS_TOOL_OBJS := $(DEVTOOLS_TOOL_SRC:.c=.o)
DEVTOOLS_COMMON_OBJS := \
common/base32.o \
common/bech32.o \
common/bech32_util.o \
common/bolt11.o \
common/hash_u5.o \
common/type_to_string.o \
common/utils.o \
common/version.o
common/version.o \
common/wireaddr.o
devtools-all: devtools/bolt11-cli devtools/decodemsg devtools/onion

20
devtools/decodemsg.c

@ -1,11 +1,27 @@
#include <ccan/err/err.h>
#include <common/utils.h>
#include <devtools/gen_print_wire.h>
#include <stdio.h>
int main(int argc UNUSED, char *argv[])
static void usage(void)
{
fprintf(stderr, "Usage: decodemsg <msg-in-hex>\n");
exit(1);
}
int main(int argc, char *argv[])
{
const u8 *m;
setup_locale();
u8 *m = tal_hexdata(NULL, argv[1], strlen(argv[1]));
if (argc != 2)
usage();
/* Last arg is hex string */
m = tal_hexdata(NULL, argv[1], strlen(argv[1]));
if (!m)
errx(1, "'%s' is not valid hex", argv[1]);
print_message(m);
return 0;
}

22
devtools/print_wire.c

@ -82,12 +82,34 @@ hexdump:
return;
}
static void printwire_addresses(const u8 **cursor, size_t *plen, size_t len)
{
struct wireaddr addr;
printf("[");
while (*plen && fromwire_wireaddr(cursor, plen, &addr))
printf(" %s", fmt_wireaddr(NULL, &addr));
if (!*cursor)
return;
if (*plen != 0) {
printf(" UNKNOWN:");
if (!print_hexstring(cursor, plen, len))
return;
}
printf(" ]\n");
}
void printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len)
{
if (streq(fieldname, "node_announcement.alias")) {
printwire_alias(cursor, plen, len);
return;
}
if (streq(fieldname, "node_announcement.addresses")) {
printwire_addresses(cursor, plen, len);
return;
}
printf("[");
if (!print_hexstring(cursor, plen, len))

1
devtools/print_wire.h

@ -2,6 +2,7 @@
#define LIGHTNING_DEVTOOLS_PRINT_WIRE_H
#include <bitcoin/preimage.h>
#include <bitcoin/tx.h>
#include <common/wireaddr.h>
#include <wire/gen_peer_wire.h>
void printwire_u8(const char *fieldname, const u8 *v);

Loading…
Cancel
Save