mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 00:24:19 +01:00
connect: return address we actually connected to.
Otherwise, we might find an address other than the one given and the user might think that address worked. Fixes: #4185 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSON-RPC: `connect` returns `address` it actually connected to
This commit is contained in:
@@ -68,11 +68,13 @@ static struct connect *find_connect(struct lightningd *ld,
|
||||
}
|
||||
|
||||
static struct command_result *connect_cmd_succeed(struct command *cmd,
|
||||
const struct peer *peer)
|
||||
const struct peer *peer,
|
||||
const struct wireaddr_internal *addr)
|
||||
{
|
||||
struct json_stream *response = json_stream_success(cmd);
|
||||
json_add_node_id(response, "id", &peer->id);
|
||||
json_add_hex_talarr(response, "features", peer->their_features);
|
||||
json_add_address_internal(response, "address", addr);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
@@ -143,7 +145,9 @@ static struct command_result *json_connect(struct command *cmd,
|
||||
|
||||
if (peer->uncommitted_channel
|
||||
|| (channel && channel->connected)) {
|
||||
return connect_cmd_succeed(cmd, peer);
|
||||
log_debug(cmd->ld->log, "Already connected via %s",
|
||||
type_to_string(tmpctx, struct wireaddr_internal, &peer->addr));
|
||||
return connect_cmd_succeed(cmd, peer, &peer->addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,14 +264,15 @@ static void connect_failed(struct lightningd *ld, const u8 *msg)
|
||||
delay_then_reconnect(channel, seconds_to_delay, addrhint);
|
||||
}
|
||||
|
||||
void connect_succeeded(struct lightningd *ld, const struct peer *peer)
|
||||
void connect_succeeded(struct lightningd *ld, const struct peer *peer,
|
||||
const struct wireaddr_internal *addr)
|
||||
{
|
||||
struct connect *c;
|
||||
|
||||
/* We can have multiple connect commands: fail them all */
|
||||
while ((c = find_connect(ld, &peer->id)) != NULL) {
|
||||
/* They delete themselves from list */
|
||||
connect_cmd_succeed(c->cmd, peer);
|
||||
connect_cmd_succeed(c->cmd, peer, addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user