mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ void connectd_activate(struct lightningd *ld);
|
||||
|
||||
void delay_then_reconnect(struct channel *channel, u32 seconds_delay,
|
||||
const struct wireaddr_internal *addrhint TAKES);
|
||||
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);
|
||||
void gossip_connect_result(struct lightningd *ld, const u8 *msg);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H */
|
||||
|
||||
@@ -1194,7 +1194,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
||||
peer_update_features(peer, their_features);
|
||||
|
||||
/* Complete any outstanding connect commands. */
|
||||
connect_succeeded(ld, peer);
|
||||
connect_succeeded(ld, peer, &hook_payload->addr);
|
||||
|
||||
/* Can't be opening, since we wouldn't have sent peer_disconnected. */
|
||||
assert(!peer->uncommitted_channel);
|
||||
|
||||
@@ -142,7 +142,8 @@ struct command_result *command_success(struct command *cmd UNNEEDED,
|
||||
|
||||
{ fprintf(stderr, "command_success called!\n"); abort(); }
|
||||
/* Generated stub for connect_succeeded */
|
||||
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct peer *peer UNNEEDED)
|
||||
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct peer *peer UNNEEDED,
|
||||
const struct wireaddr_internal *addr UNNEEDED)
|
||||
{ fprintf(stderr, "connect_succeeded called!\n"); abort(); }
|
||||
/* Generated stub for delay_then_reconnect */
|
||||
void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user