mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
routing: Passing back all addresses on getnodes
This commit is contained in:
parent
26892e79bb
commit
e972b208c7
6 changed files with 46 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
/* JSON core and helpers */
|
||||
#include "json.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
|
@ -453,6 +454,25 @@ void json_add_short_channel_id(struct json_result *response,
|
|||
json_add_string(response, fieldname, str);
|
||||
}
|
||||
|
||||
void json_add_address(struct json_result *response, const char *fieldname,
|
||||
const struct ipaddr *addr)
|
||||
{
|
||||
json_object_start(response, fieldname);
|
||||
char *addrstr = tal_arr(response, char, INET6_ADDRSTRLEN);
|
||||
if (addr->type == ADDR_TYPE_IPV4) {
|
||||
inet_ntop(AF_INET, addr->addr, addrstr, INET_ADDRSTRLEN);
|
||||
json_add_string(response, "type", "ipv4");
|
||||
json_add_string(response, "address", addrstr);
|
||||
json_add_num(response, "port", addr->port);
|
||||
} else if (addr->type == ADDR_TYPE_IPV6) {
|
||||
inet_ntop(AF_INET6, addr->addr, addrstr, INET6_ADDRSTRLEN);
|
||||
json_add_string(response, "type", "ipv6");
|
||||
json_add_string(response, "address", addrstr);
|
||||
json_add_num(response, "port", addr->port);
|
||||
}
|
||||
json_object_end(response);
|
||||
}
|
||||
|
||||
void json_add_object(struct json_result *result, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
|
@ -112,6 +112,10 @@ void json_add_short_channel_id(struct json_result *response,
|
|||
const char *fieldname,
|
||||
const struct short_channel_id *id);
|
||||
|
||||
/* JSON serialize a network address for a node */
|
||||
void json_add_address(struct json_result *response, const char *fieldname,
|
||||
const struct ipaddr *addr);
|
||||
|
||||
void json_add_object(struct json_result *result, ...);
|
||||
|
||||
const char *json_result_string(const struct json_result *result);
|
||||
|
|
|
@ -572,6 +572,7 @@ static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon)
|
|||
nodes[node_count].nodeid = n->id;
|
||||
nodes[node_count].hostname = n->hostname;
|
||||
nodes[node_count].port = n->port;
|
||||
nodes[node_count].addresses = n->addresses;
|
||||
node_count++;
|
||||
n = node_map_next(daemon->rstate->nodes, &i);
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ static bool json_getnodes_reply(struct subd *gossip, const u8 *reply,
|
|||
{
|
||||
struct gossip_getnodes_entry *nodes;
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
size_t i;
|
||||
size_t i, j;
|
||||
|
||||
if (!fromwire_gossip_getnodes_reply(reply, reply, NULL, &nodes)) {
|
||||
command_fail(cmd, "Malformed gossip_getnodes response");
|
||||
|
@ -211,12 +211,11 @@ static bool json_getnodes_reply(struct subd *gossip, const u8 *reply,
|
|||
for (i = 0; i < tal_count(nodes); i++) {
|
||||
json_object_start(response, NULL);
|
||||
json_add_pubkey(response, "nodeid", &nodes[i].nodeid);
|
||||
if (tal_len(nodes[i].hostname) > 0) {
|
||||
json_add_string(response, "hostname", nodes[i].hostname);
|
||||
} else {
|
||||
json_add_null(response, "hostname");
|
||||
json_array_start(response, "addresses");
|
||||
for (j=0; j<tal_count(nodes[i].addresses); j++) {
|
||||
json_add_address(response, NULL, &nodes[i].addresses[j]);
|
||||
}
|
||||
json_add_num(response, "port", nodes[i].port);
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
}
|
||||
json_array_end(response);
|
||||
|
|
|
@ -4,7 +4,15 @@
|
|||
void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry)
|
||||
{
|
||||
u8 hostnamelen;
|
||||
u8 numaddresses, i;
|
||||
fromwire_pubkey(pptr, max, &entry->nodeid);
|
||||
numaddresses = fromwire_u8(pptr, max);
|
||||
|
||||
entry->addresses = tal_arr(ctx, struct ipaddr, numaddresses);
|
||||
for (i=0; i<numaddresses; i++) {
|
||||
fromwire_ipaddr(pptr, max, entry->addresses);
|
||||
}
|
||||
|
||||
hostnamelen = fromwire_u8(pptr, max);
|
||||
entry->hostname = tal_arr(ctx, char, hostnamelen);
|
||||
fromwire_u8_array(pptr, max, (u8*)entry->hostname, hostnamelen);
|
||||
|
@ -13,7 +21,14 @@ void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *m
|
|||
void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry *entry)
|
||||
{
|
||||
u8 hostnamelen;
|
||||
u8 i, numaddresses = tal_count(entry->addresses);
|
||||
towire_pubkey(pptr, &entry->nodeid);
|
||||
towire_u8(pptr, numaddresses);
|
||||
|
||||
for (i=0; i<numaddresses; i++) {
|
||||
towire_ipaddr(pptr, &entry->addresses[i]);
|
||||
}
|
||||
|
||||
if (entry->hostname) {
|
||||
hostnamelen = strlen(entry->hostname);
|
||||
towire_u8(pptr, hostnamelen);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
struct gossip_getnodes_entry {
|
||||
struct pubkey nodeid;
|
||||
struct ipaddr *addresses;
|
||||
char *hostname;
|
||||
u16 port;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue