Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/topology: remove topology functionality from gossipd. #4585

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
370aee0
ccan: update to get RETURNS_NONNULL macro.
rustyrussell Jun 14, 2021
ab61067
common: note that command_fail doesn't return NULL.
rustyrussell Jun 14, 2021
ee94799
topology: plugin to implement getroute command.
rustyrussell Jun 14, 2021
d1f0c6b
pyln-client: hack in test that getroute returns the same old/new.
rustyrussell Jun 14, 2021
e1ba3e7
plugins/topology: listchannels command.
rustyrussell Jun 14, 2021
2063c91
plugins/topology: make listchannels mark disconnected local channels …
rustyrussell Jun 14, 2021
83cef65
pyln-client: hack in test that listchannels returns the same old/new.
rustyrussell Jun 14, 2021
56014eb
common/wireaddr: fromwire_wireaddr_array helper.
rustyrussell Jun 14, 2021
781d811
plugins/topology: add listnodes command.
rustyrussell Jun 14, 2021
63b7e09
pyln-client: hack in test that listnodes returns the same old/new.
rustyrussell Jun 14, 2021
8da24b8
plugins/topology: listincoming function to help invoices.
rustyrussell Jun 14, 2021
f62b90f
invoice: overhaul routehints to use topology.listincoming, cleanup.
rustyrussell Jun 14, 2021
a7fd016
signmessage: use listnodes instead of gossipd_getnodes_request.
rustyrussell Jun 14, 2021
4b8fbf2
pyln-client: revert old/new comparisons for getroute, listchannels, l…
rustyrussell Jun 14, 2021
ec86963
gossipd/test: remove routing tests.
rustyrussell Jun 14, 2021
9a7d49d
gossipd: remove routing, listchannels and listnodes infrastructure.
rustyrussell Jun 14, 2021
a0e1020
lightningd: wait for gossipd to finish initalizing before starting pl…
rustyrussell Jun 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
plugins/topology: add listnodes command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 14, 2021
commit 781d811c0ecf802112e1c942ddd37f569ef1ad22
2 changes: 1 addition & 1 deletion lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static struct command_result *json_listnodes(struct command *cmd,
}

static const struct json_command listnodes_command = {
"listnodes",
"listnodesold",
"network",
json_listnodes,
"Show node {id} (or all, if no {id}), in our local network view"
Expand Down
4 changes: 3 additions & 1 deletion plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ $(PLUGIN_PAY_OBJS): $(PLUGIN_PAY_LIB_HEADER)

plugins/autoclean: bitcoin/chainparams.o $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

plugins/topology: common/route.o common/dijkstra.o common/gossmap.o common/fp16.o bitcoin/chainparams.o $(PLUGIN_TOPOLOGY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
# Topology wants to decode node_announcement, and peer_wiregen which
# pulls in some of bitcoin/.
plugins/topology: common/route.o common/dijkstra.o common/gossmap.o common/fp16.o bitcoin/chainparams.o wire/peer$(EXP)_wiregen.o bitcoin/block.o bitcoin/preimage.o $(PLUGIN_TOPOLOGY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

plugins/txprepare: bitcoin/chainparams.o $(PLUGIN_TXPREPARE_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

Expand Down
100 changes: 100 additions & 0 deletions plugins/topology.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <ccan/array_size/array_size.h>
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/htable/htable_type.h>
#include <ccan/json_escape/json_escape.h>
#include <ccan/json_out/json_out.h>
#include <ccan/tal/str/str.h>
#include <ccan/time/time.h>
Expand All @@ -12,9 +13,11 @@
#include <common/route.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <common/wireaddr.h>
#include <errno.h>
#include <inttypes.h>
#include <plugins/libplugin.h>
#include <wire/peer_wire.h>

/* Access via get_gossmap() */
static struct node_id local_id;
Expand Down Expand Up @@ -497,6 +500,96 @@ static struct command_result *json_listchannels(struct command *cmd,
return send_outreq(cmd->plugin, req);
}

static void json_add_node(struct json_stream *js,
const struct gossmap *gossmap,
const struct gossmap_node *n)
{
struct node_id node_id;
u8 *nannounce;

json_object_start(js, NULL);
gossmap_node_get_id(gossmap, n, &node_id);
json_add_node_id(js, "nodeid", &node_id);
nannounce = gossmap_node_get_announce(tmpctx, gossmap, n);
if (nannounce) {
secp256k1_ecdsa_signature signature;
u8 *features;
u32 timestamp;
u8 rgb_color[3], alias[32];
u8 *addresses;
struct node_id nid;
struct wireaddr *addrs;
struct json_escape *esc;

if (!fromwire_node_announcement(nannounce, nannounce,
&signature,
&features,
&timestamp,
&nid,
rgb_color,
alias,
&addresses)) {
plugin_log(plugin, LOG_BROKEN,
"Cannot parse stored node_announcement"
" for %s at %u: %s",
type_to_string(tmpctx, struct node_id,
&node_id),
n->nann_off,
tal_hex(tmpctx, nannounce));
goto out;
}

esc = json_escape(NULL,
take(tal_strndup(NULL,
(const char *)alias,
ARRAY_SIZE(alias))));
json_add_escaped_string(js, "alias", take(esc));
json_add_hex(js, "color", rgb_color, ARRAY_SIZE(rgb_color));
json_add_u64(js, "last_timestamp", timestamp);
json_add_hex_talarr(js, "features", features);

json_array_start(js, "addresses");
addrs = fromwire_wireaddr_array(nannounce, addresses);
for (size_t i = 0; i < tal_count(addrs); i++)
json_add_address(js, NULL, &addrs[i]);
json_array_end(js);
}
out:
json_object_end(js);
}

static struct command_result *json_listnodes(struct command *cmd,
const char *buffer,
const jsmntok_t *params)
{
struct node_id *id;
struct json_stream *js;
struct gossmap *gossmap;

if (!param(cmd, buffer, params,
p_opt("id", param_node_id, &id),
NULL))
return command_param_failed();

gossmap = get_gossmap();
js = jsonrpc_stream_success(cmd);
json_array_start(js, "nodes");
if (id) {
struct gossmap_node *n = gossmap_find_node(gossmap, id);
if (n)
json_add_node(js, gossmap, n);
} else {
for (struct gossmap_node *n = gossmap_first_node(gossmap);
n;
n = gossmap_next_node(gossmap, n)) {
json_add_node(js, gossmap, n);
}
}
json_array_end(js);

return command_finished(cmd, js);
}

static const char *init(struct plugin *p,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
Expand Down Expand Up @@ -528,6 +621,13 @@ static const struct plugin_command commands[] = {
"Show channel {short_channel_id} or {source} (or all known channels, if not specified)",
json_listchannels,
},
{
"listnodes",
"network",
"List all known nodes in the network",
"Show node {id} (or all known nods, if not specified)",
json_listnodes,
},
};

int main(int argc, char *argv[])
Expand Down