daemon: --add-route option.

This allows hardcoded routes in the config file, which is required until
we get route advertisements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-08-18 14:25:14 +09:30
parent 319c2ec5fc
commit 830a65de46
4 changed files with 51 additions and 7 deletions

View File

@ -141,6 +141,10 @@ static void config_register_opts(struct lightningd_state *dstate)
opt_register_arg("--fee-per-satoshi", opt_set_s32, opt_show_s32,
&dstate->config.fee_per_satoshi,
"Microsatoshi fee for every satoshi in HTLC");
opt_register_arg("--add-route", opt_add_route, NULL,
dstate,
"Add route of form srcid/dstid/base/var/delay/minblocks"
"(base in millisatoshi, var in millionths of satoshi per satoshi)");
}
static void dev_register_opts(struct lightningd_state *dstate)

View File

@ -303,6 +303,48 @@ struct peer *find_route(struct lightningd_state *dstate,
return first;
}
static bool get_slash_u32(const char **arg, u32 *v)
{
size_t len;
char *endp;
if (**arg != '/')
return false;
(*arg)++;
len = strcspn(*arg, "/");
*v = strtoul(*arg, &endp, 10);
(*arg) += len;
return (endp == *arg);
}
/* srcid/dstid/base/var/delay/minblocks */
char *opt_add_route(const char *arg, struct lightningd_state *dstate)
{
size_t len;
struct pubkey src, dst;
u32 base, var, delay, minblocks;
len = strcspn(arg, "/");
if (!pubkey_from_hexstr(dstate->secpctx, arg, len, &src))
return "Bad src pubkey";
arg += len + 1;
len = strcspn(arg, "/");
if (!pubkey_from_hexstr(dstate->secpctx, arg, len, &dst))
return "Bad dst pubkey";
arg += len;
if (!get_slash_u32(&arg, &base)
|| !get_slash_u32(&arg, &var)
|| !get_slash_u32(&arg, &delay)
|| !get_slash_u32(&arg, &minblocks))
return "Bad base/var/delay/minblocks";
if (*arg)
return "Data after minblocks";
add_connection(dstate, &src, &dst, base, var, delay, minblocks);
return NULL;
}
static void json_add_route(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{

View File

@ -58,4 +58,6 @@ struct peer *find_route(struct lightningd_state *dstate,
struct node_map *empty_node_map(struct lightningd_state *dstate);
char *opt_add_route(const char *arg, struct lightningd_state *dstate);
#endif /* LIGHTNING_DAEMON_ROUTING_H */

View File

@ -140,11 +140,6 @@ lcli1()
echo "dev-restart failed!">&2
exit 1
fi
# It will have forgotten any added routes.
if [ -n "$ADDROUTE" ]; then
echo $LCLI1 $ADDROUTE >&2
$LCLI1 $ADDROUTE >&2
fi
# These are safe to resubmit, will simply fail.
if [ "$1" = "fulfillhtlc" -o "$1" = "failhtlc" ]; then
if [ -z "$VERBOSE" ]; then
@ -938,8 +933,9 @@ if [ ! -n "$MANUALCOMMIT" ]; then
HTLC_AMOUNT=100000000
# Tell node 1 about the 2->3 route.
ADDROUTE="add-route $ID2 $ID3 546000 10 36 36"
lcli1 $ADDROUTE
lcli1 add-route $ID2 $ID3 546000 10 36 36
# Add to config in case we are restaring.
echo "add-route=$ID2/$ID3/546000/10/36/36" >> $DIR1/config
RHASH5=`lcli3 accept-payment $HTLC_AMOUNT | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
# Try wrong hash.