mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
Add --rgb and --alias options.
And derive random ones from nodeid if they don't choose. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ebdecebb1a
commit
b6a2b8c58b
7 changed files with 100 additions and 6 deletions
|
@ -78,7 +78,8 @@ static struct lightningd *new_lightningd(const tal_t *ctx,
|
|||
ld->dev_hsm_seed = NULL;
|
||||
ld->log_book = log_book;
|
||||
ld->log = new_log(log_book, log_book, "lightningd(%u):", (int)getpid());
|
||||
|
||||
ld->alias = NULL;
|
||||
ld->rgb = NULL;
|
||||
list_head_init(&ld->pay_commands);
|
||||
list_head_init(&ld->connects);
|
||||
ld->portnum = DEFAULT_PORT;
|
||||
|
@ -251,6 +252,9 @@ int main(int argc, char *argv[])
|
|||
/* Set up HSM. */
|
||||
hsm_init(ld, newdir);
|
||||
|
||||
/* Now we know our ID, we can set our color/alias if not already. */
|
||||
setup_color_and_alias(ld);
|
||||
|
||||
/* Initialize block topology. */
|
||||
setup_topology(ld->topology,
|
||||
&ld->timers,
|
||||
|
@ -288,7 +292,9 @@ int main(int argc, char *argv[])
|
|||
setup_jsonrpc(ld, ld->rpc_filename);
|
||||
|
||||
/* Mark ourselves live. */
|
||||
log_info(ld->log, "Hello world from %s!", version());
|
||||
log_info(ld->log, "Hello world from %s aka %s #%s (version %s)!",
|
||||
type_to_string(ltmp, struct pubkey, &ld->id),
|
||||
ld->alias, tal_hex(ltmp, ld->rgb), version());
|
||||
|
||||
#if 0
|
||||
/* Load peers from database. */
|
||||
|
|
|
@ -87,6 +87,10 @@ struct lightningd {
|
|||
/* This is us. */
|
||||
struct pubkey id;
|
||||
|
||||
/* My name is... my favorite color is... */
|
||||
char *alias; /* At least 32 bytes (zero-filled) */
|
||||
u8 *rgb; /* tal_len() == 3. */
|
||||
|
||||
/* Any pending timers. */
|
||||
struct timers timers;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <bitcoin/chainparams.h>
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/opt/opt.h>
|
||||
#include <ccan/read_write_all/read_write_all.h>
|
||||
|
@ -185,6 +186,36 @@ static void opt_show_network(char buf[OPT_SHOW_LEN],
|
|||
snprintf(buf, OPT_SHOW_LEN, "%s", get_chainparams(ld)->network_name);
|
||||
}
|
||||
|
||||
static char *opt_set_rgb(const char *arg, struct lightningd *ld)
|
||||
{
|
||||
ld->rgb = tal_free(ld->rgb);
|
||||
/* BOLT #7:
|
||||
*
|
||||
* the first byte of `rgb` is the red value, the second byte is the
|
||||
* green value and the last byte is the blue value */
|
||||
ld->rgb = tal_hexdata(ld, arg, strlen(arg));
|
||||
if (!ld->rgb || tal_len(ld->rgb) != 3)
|
||||
return tal_fmt(NULL, "rgb '%s' is not six hex digits", arg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *opt_set_alias(const char *arg, struct lightningd *ld)
|
||||
{
|
||||
ld->alias = tal_free(ld->alias);
|
||||
/* BOLT #7:
|
||||
*
|
||||
* * [`32`:`alias`]
|
||||
*...
|
||||
* It MUST set `alias` to a valid UTF-8 string, with any `alias` bytes
|
||||
* following equal to zero.
|
||||
*/
|
||||
if (strlen(arg) > 32)
|
||||
return tal_fmt(NULL, "Alias '%s' is over 32 characters", arg);
|
||||
ld->alias = tal_arrz(ld, char, 33);
|
||||
strncpy(ld->alias, arg, 32);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void config_register_opts(struct lightningd *ld)
|
||||
{
|
||||
opt_register_arg("--locktime-blocks", opt_set_u32, opt_show_u32,
|
||||
|
@ -520,6 +551,10 @@ void register_opts(struct lightningd *ld)
|
|||
opt_register_arg("--bitcoin-datadir", opt_set_charp, NULL,
|
||||
&ld->topology->bitcoind->datadir,
|
||||
"-datadir arg for bitcoin-cli");
|
||||
opt_register_arg("--rgb", opt_set_rgb, NULL, ld,
|
||||
"RRGGBB hex color for node");
|
||||
opt_register_arg("--alias", opt_set_alias, NULL, ld,
|
||||
"Up to 32-byte alias for node");
|
||||
opt_register_logging(ld->log);
|
||||
opt_register_version();
|
||||
|
||||
|
@ -528,6 +563,46 @@ void register_opts(struct lightningd *ld)
|
|||
dev_register_opts(ld);
|
||||
}
|
||||
|
||||
/* Names stolen from https://github.com/ternus/nsaproductgenerator/blob/master/nsa.js */
|
||||
static const char *codename_adjective[]
|
||||
= { "LOUD", "RED", "BLUE", "GREEN", "YELLOW", "IRATE", "ANGRY", "PEEVED",
|
||||
"HAPPY", "SLIMY", "SLEEPY", "JUNIOR", "SLICKER", "UNITED", "SOMBER",
|
||||
"BIZARRE", "ODD", "WEIRD", "WRONG", "LATENT", "CHILLY", "STRANGE", "LOUD",
|
||||
"SILENT", "HOPPING", "ORANGE", "VIOLET", "VIOLENT", "LIGHTNING" };
|
||||
|
||||
static const char *codename_noun[]
|
||||
= { "WHISPER", "FELONY", "MOON", "SUCKER", "PENGUIN", "WAFFLE", "MAESTRO",
|
||||
"NIGHT", "TRINITY", "DEITY", "MONKEY", "ARK", "SQUIRREL", "IRON", "BOUNCE",
|
||||
"FARM", "CHEF", "TROUGH", "NET", "TRAWL", "GLEE", "WATER", "SPORK", "PLOW",
|
||||
"FEED", "SOUFFLE", "ROUTE", "BAGEL", "MONTANA", "ANALYST", "AUTO", "WATCH",
|
||||
"PHOTO", "YARD", "SOURCE", "MONKEY", "SEAGULL", "TOLL", "SPAWN", "GOPHER",
|
||||
"CHIPMUNK", "SET", "CALENDAR", "ARTIST", "CHASER", "SCAN", "TOTE", "BEAM",
|
||||
"ENTOURAGE", "GENESIS", "WALK", "SPATULA", "RAGE", "FIRE", "MASTER" };
|
||||
|
||||
void setup_color_and_alias(struct lightningd *ld)
|
||||
{
|
||||
u8 der[PUBKEY_DER_LEN];
|
||||
pubkey_to_der(der, &ld->id);
|
||||
|
||||
if (!ld->rgb)
|
||||
/* You can't get much red by default */
|
||||
ld->rgb = tal_dup_arr(ld, u8, der, 3, 0);
|
||||
|
||||
if (!ld->alias) {
|
||||
u64 adjective, noun;
|
||||
|
||||
memcpy(&adjective, der+3, sizeof(adjective));
|
||||
memcpy(&noun, der+3+sizeof(adjective), sizeof(noun));
|
||||
noun %= ARRAY_SIZE(codename_noun);
|
||||
adjective %= ARRAY_SIZE(codename_adjective);
|
||||
ld->alias = tal_arrz(ld, char, 33);
|
||||
assert(strlen(codename_adjective[adjective])
|
||||
+ strlen(codename_noun[noun]) < 33);
|
||||
strcpy(ld->alias, codename_adjective[adjective]);
|
||||
strcat(ld->alias, codename_noun[noun]);
|
||||
}
|
||||
}
|
||||
|
||||
bool handle_opts(struct lightningd *ld, int argc, char *argv[])
|
||||
{
|
||||
bool newdir = false;
|
||||
|
|
|
@ -14,4 +14,7 @@ void register_opts(struct lightningd *ld);
|
|||
bool handle_opts(struct lightningd *ld, int argc, char *argv[]);
|
||||
|
||||
bool parse_ipaddr(const char *arg, struct ipaddr *addr);
|
||||
|
||||
/* Derive default color and alias from the pubkey. */
|
||||
void setup_color_and_alias(struct lightningd *ld);
|
||||
#endif /* LIGHTNING_LIGHTNINGD_OPTIONS_H */
|
||||
|
|
|
@ -1523,8 +1523,6 @@ static u8 *create_node_announcement(const tal_t *ctx, struct lightningd *ld,
|
|||
secp256k1_ecdsa_signature *sig,
|
||||
u32 timestamp)
|
||||
{
|
||||
u8 rgb[3] = {0x77, 0x88, 0x99};
|
||||
u8 alias[32];
|
||||
u8 *features = NULL;
|
||||
u8 *addresses = tal_arr(ctx, u8, 0);
|
||||
u8 *announcement;
|
||||
|
@ -1535,10 +1533,10 @@ static u8 *create_node_announcement(const tal_t *ctx, struct lightningd *ld,
|
|||
if (ld->config.ipaddr.type != ADDR_TYPE_PADDING) {
|
||||
towire_ipaddr(&addresses, &ld->config.ipaddr);
|
||||
}
|
||||
memset(alias, 0, sizeof(alias));
|
||||
announcement =
|
||||
towire_node_announcement(ctx, sig, features, timestamp,
|
||||
&ld->id, rgb, alias, addresses);
|
||||
&ld->id, ld->rgb, (u8 *)ld->alias,
|
||||
addresses);
|
||||
return announcement;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,9 @@ void populate_peer(struct lightningd *ld UNNEEDED, struct peer *peer UNNEEDED)
|
|||
/* Generated stub for register_opts */
|
||||
void register_opts(struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "register_opts called!\n"); abort(); }
|
||||
/* Generated stub for setup_color_and_alias */
|
||||
void setup_color_and_alias(struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "setup_color_and_alias called!\n"); abort(); }
|
||||
/* Generated stub for setup_jsonrpc */
|
||||
void setup_jsonrpc(struct lightningd *ld UNNEEDED, const char *rpc_filename UNNEEDED)
|
||||
{ fprintf(stderr, "setup_jsonrpc called!\n"); abort(); }
|
||||
|
|
|
@ -219,6 +219,11 @@ class BitcoinD(TailableProc):
|
|||
|
||||
logging.info("BitcoinD started")
|
||||
|
||||
# lightning-1 => 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518 aka JUNIORBEAM #0266e4
|
||||
# lightning-2 => 022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59 aka SILENTARTIST #022d22
|
||||
# lightning-3 => 035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d aka HOPPINGFIRE #035d2b
|
||||
# lightning-4 => 0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199 aka JUNIORFELONY #0382ce
|
||||
# lightning-5 => 032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e aka SOMBERFIRE #032cf1
|
||||
|
||||
class LightningD(TailableProc):
|
||||
def __init__(self, lightning_dir, bitcoin_dir, port=9735):
|
||||
|
|
Loading…
Add table
Reference in a new issue