From 74df755a297115651ecd98dadd78df6801e1a21e Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 15 Mar 2017 10:43:03 +0100 Subject: [PATCH] gossip: Added nested message types for getnodes query Added a struct that represents a single entry in a `getnodes` reply, so that we can append one after the other and parse them again on the other side. --- lightningd/Makefile | 1 + lightningd/gossip_msg.c | 27 +++++++++++++++++++++++++++ lightningd/gossip_msg.h | 15 +++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lightningd/gossip_msg.c create mode 100644 lightningd/gossip_msg.h diff --git a/lightningd/Makefile b/lightningd/Makefile index b5cbe6fde..79748dc9b 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -45,6 +45,7 @@ LIGHTNINGD_LIB_SRC := \ lightningd/debug.c \ lightningd/derive_basepoints.c \ lightningd/funding_tx.c \ + lightningd/gossip_msg.c \ lightningd/htlc_tx.c \ lightningd/key_derive.c \ lightningd/msg_queue.c \ diff --git a/lightningd/gossip_msg.c b/lightningd/gossip_msg.c new file mode 100644 index 000000000..4d3698851 --- /dev/null +++ b/lightningd/gossip_msg.c @@ -0,0 +1,27 @@ +#include +#include + +void fromwire_gossip_getnodes_entry(const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry) +{ + u8 hostnamelen; + fromwire_pubkey(pptr, max, &entry->nodeid); + hostnamelen = fromwire_u8(pptr, max); + entry->hostname = tal_arr(entry, char, hostnamelen); + fromwire_u8_array(pptr, max, (u8*)entry->hostname, hostnamelen); + entry->port = fromwire_u16(pptr, max); +} +void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry *entry) +{ + u8 hostnamelen; + towire_pubkey(pptr, &entry->nodeid); + if (entry->hostname) { + hostnamelen = strlen(entry->hostname); + towire_u8(pptr, hostnamelen); + towire_u8_array(pptr, (u8*)entry->hostname, hostnamelen); + }else { + /* If we don't have a hostname just write an empty string */ + hostnamelen = 0; + towire_u8(pptr, hostnamelen); + } + towire_u16(pptr, entry->port); +} diff --git a/lightningd/gossip_msg.h b/lightningd/gossip_msg.h new file mode 100644 index 000000000..3a543f297 --- /dev/null +++ b/lightningd/gossip_msg.h @@ -0,0 +1,15 @@ +#ifndef LIGHTNING_LIGHTNINGD_GOSSIP_MSG_H +#define LIGHTNING_LIGHTNINGD_GOSSIP_MSG_H +#include "config.h" +#include + +struct gossip_getnodes_entry { + struct pubkey nodeid; + char *hostname; + u16 port; +}; + +void fromwire_gossip_getnodes_entry(const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry); +void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry *entry); + +#endif /* LIGHTNING_LIGHTGNINGD_GOSSIP_MSG_H */