mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
JSONRPC listnodes: return timestamp, alias and color.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1101,7 +1101,15 @@ static void append_node(struct gossip_getnodes_entry **nodes,
|
||||
size_t num_nodes = tal_count(*nodes);
|
||||
tal_resize(nodes, num_nodes + 1);
|
||||
(*nodes)[num_nodes].nodeid = n->id;
|
||||
(*nodes)[num_nodes].last_timestamp = n->last_timestamp;
|
||||
if (n->last_timestamp < 0) {
|
||||
(*nodes)[num_nodes].addresses = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
(*nodes)[num_nodes].addresses = n->addresses;
|
||||
(*nodes)[num_nodes].alias = n->alias;
|
||||
memcpy((*nodes)[num_nodes].color, n->rgb_color, 3);
|
||||
}
|
||||
|
||||
static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "lightningd.h"
|
||||
#include "peer_control.h"
|
||||
#include "subd.h"
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/fdpass/fdpass.h>
|
||||
#include <ccan/take/take.h>
|
||||
@@ -199,6 +200,17 @@ static void 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 (nodes[i].last_timestamp < 0) {
|
||||
json_object_end(response);
|
||||
continue;
|
||||
}
|
||||
json_add_string(response, "alias",
|
||||
tal_strndup(response, (char *)nodes[i].alias,
|
||||
tal_len(nodes[i].alias)));
|
||||
json_add_hex(response, "color",
|
||||
nodes[i].color, ARRAY_SIZE(nodes[i].color));
|
||||
json_add_u64(response, "last_timestamp",
|
||||
nodes[i].last_timestamp);
|
||||
json_array_start(response, "addresses");
|
||||
for (j=0; j<tal_count(nodes[i].addresses); j++) {
|
||||
json_add_address(response, NULL, &nodes[i].addresses[j]);
|
||||
|
||||
@@ -6,6 +6,13 @@ void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *m
|
||||
{
|
||||
u8 numaddresses, i;
|
||||
fromwire_pubkey(pptr, max, &entry->nodeid);
|
||||
entry->last_timestamp = fromwire_u64(pptr, max);
|
||||
|
||||
if (entry->last_timestamp < 0) {
|
||||
entry->addresses = NULL;
|
||||
entry->alias = NULL;
|
||||
return;
|
||||
}
|
||||
numaddresses = fromwire_u8(pptr, max);
|
||||
|
||||
entry->addresses = tal_arr(ctx, struct wireaddr, numaddresses);
|
||||
@@ -16,16 +23,26 @@ void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *m
|
||||
return;
|
||||
}
|
||||
}
|
||||
entry->alias = tal_arr(ctx, u8, fromwire_u8(pptr, max));
|
||||
fromwire(pptr, max, entry->alias, tal_len(entry->alias));
|
||||
fromwire(pptr, max, entry->color, sizeof(entry->color));
|
||||
}
|
||||
void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry *entry)
|
||||
{
|
||||
u8 i, numaddresses = tal_count(entry->addresses);
|
||||
towire_pubkey(pptr, &entry->nodeid);
|
||||
towire_u8(pptr, numaddresses);
|
||||
towire_u64(pptr, entry->last_timestamp);
|
||||
|
||||
if (entry->last_timestamp < 0)
|
||||
return;
|
||||
|
||||
towire_u8(pptr, numaddresses);
|
||||
for (i=0; i<numaddresses; i++) {
|
||||
towire_wireaddr(pptr, &entry->addresses[i]);
|
||||
}
|
||||
towire_u8(pptr, tal_len(entry->alias));
|
||||
towire(pptr, entry->alias, tal_len(entry->alias));
|
||||
towire(pptr, entry->color, sizeof(entry->color));
|
||||
}
|
||||
|
||||
void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
|
||||
struct gossip_getnodes_entry {
|
||||
struct pubkey nodeid;
|
||||
s64 last_timestamp; /* -1 means never: following fields ignored */
|
||||
struct wireaddr *addresses;
|
||||
u8 *alias;
|
||||
u8 color[3];
|
||||
};
|
||||
|
||||
struct gossip_getchannels_entry {
|
||||
|
||||
@@ -1421,6 +1421,16 @@ class LightningDTests(BaseLightningDTests):
|
||||
assert n1['nodeid'] == l1.info['id']
|
||||
assert n2['nodeid'] == l2.info['id']
|
||||
|
||||
# Might not have seen other node-announce yet.
|
||||
assert n1['alias'] == 'JUNIORBEAM'
|
||||
assert n1['color'] == '0266e4'
|
||||
if not 'alias' in n2:
|
||||
assert not 'color' in n2
|
||||
assert not 'addresses' in n2
|
||||
else:
|
||||
assert n2['alias'] == 'SILENTARTIST'
|
||||
assert n2['color'] == '022d22'
|
||||
|
||||
assert [c['active'] for c in l1.rpc.getchannels()['channels']] == [True, True]
|
||||
assert [c['public'] for c in l1.rpc.getchannels()['channels']] == [True, True]
|
||||
assert [c['active'] for c in l2.rpc.getchannels()['channels']] == [True, True]
|
||||
|
||||
Reference in New Issue
Block a user