Skip to content

Commit

Permalink
devtools/gossipwith: add a "network" option
Browse files Browse the repository at this point in the history
If specified, this will add the corresponding chain_hash to the init message.
  • Loading branch information
darosior committed Nov 28, 2019
1 parent 4861e2c commit ebbcb0e
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion devtools/gossipwith.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* Simple tool to route gossip from a peer. */
#include <bitcoin/block.h>
#include <bitcoin/chainparams.h>
#include <ccan/array_size/array_size.h>
#include <ccan/err/err.h>
#include <ccan/io/io.h>
Expand All @@ -24,6 +26,7 @@ static bool no_init = false;
static bool hex = false;
static int timeout_after = -1;
static u8 *features;
static const struct chainparams *blockchainparams = NULL;

static struct io_plan *simple_write(struct io_conn *conn,
const void *data, size_t len,
Expand Down Expand Up @@ -81,6 +84,22 @@ enum dev_disconnect dev_disconnect(int pkt_type)
}
#endif

static char *opt_set_network(const char *arg, void *unused)
{
assert(arg != NULL);

/* Set the global chainparams instance */
blockchainparams = chainparams_for_network(arg);
if (!blockchainparams)
return tal_fmt(NULL, "Unknown network name '%s'", arg);
return NULL;
}

static void opt_show_network(char buf[OPT_SHOW_LEN], const void *unused)
{
snprintf(buf, OPT_SHOW_LEN, "%s", blockchainparams->network_name);
}

void peer_failed_connection_lost(void)
{
exit(0);
Expand Down Expand Up @@ -137,11 +156,21 @@ static struct io_plan *handshake_success(struct io_conn *conn,
OPTIONAL_FEATURE(OPT_INITIAL_ROUTING_SYNC));

if (!no_init) {
msg = towire_init(NULL, NULL, features, NULL);
struct tlv_init_tlvs *tlvs = NULL;
if (blockchainparams) {
tlvs = tlv_init_tlvs_new(NULL);
tlvs->networks = tal(tlvs, struct tlv_init_tlvs_networks);
tlvs->networks->chains = tal_arr(tlvs->networks, struct bitcoin_blkid, 1);
tlvs->networks->chains[0] = blockchainparams->genesis_blockhash;
msg = towire_init(NULL, NULL, features, tlvs);
} else
msg = towire_init(NULL, NULL, features, NULL);

sync_crypto_write(pps, take(msg));
/* Ignore their init message. */
tal_free(sync_crypto_read(NULL, pps));
if (tlvs)
tal_free(tlvs);
}

if (stream_stdin)
Expand Down Expand Up @@ -254,6 +283,10 @@ int main(int argc, char *argv[])
"Print out messages in hex");
opt_register_arg("--features=<hex>", opt_set_features, NULL,
&features, "Send these features in init");
opt_register_arg("--network", opt_set_network, opt_show_network,
NULL,
"Select the network parameters (bitcoin, testnet,"
" regtest, litecoin or litecoin-testnet)");
opt_register_noarg("--help|-h", opt_usage_and_exit,
"id@addr[:port] [hex-msg-tosend...]\n"
"Connect to a lightning peer and relay gossip messages from it",
Expand Down

0 comments on commit ebbcb0e

Please sign in to comment.