peer: fail immediately if we detect double-connection.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-10-07 14:00:16 +10:30
parent 0f6c387899
commit fb99e0ccb0

View File

@ -2608,8 +2608,17 @@ static struct io_plan *crypto_on_out(struct io_conn *conn,
const struct pubkey *id,
struct json_connecting *connect)
{
struct peer *peer;
if (find_peer(dstate, id)) {
command_fail(connect->cmd, "Already connected to peer %s",
pubkey_to_hexstr(connect->cmd,
dstate->secpctx, id));
return io_close(conn);
}
/* Initiator currently funds channel */
struct peer *peer = new_peer(dstate, log, STATE_INIT, CMD_OPEN_WITH_ANCHOR);
peer = new_peer(dstate, log, STATE_INIT, CMD_OPEN_WITH_ANCHOR);
if (!peer_first_connected(peer, conn, SOCK_STREAM, IPPROTO_TCP,
iod, id, true)) {
command_fail(connect->cmd, "Failed to make peer for %s:%s",