mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-05 07:14:36 +01:00
lightningd/lightningd: finish connect command once gossip started.
This is after the INIT message is received, so we know there are no incompatible features. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "subdaemon.h"
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/take/take.h>
|
||||
#include <daemon/jsonrpc.h>
|
||||
#include <daemon/log.h>
|
||||
#include <inttypes.h>
|
||||
#include <lightningd/gossip/gen_gossip_control_wire.h>
|
||||
@@ -76,7 +77,16 @@ static void peer_ready(struct subdaemon *gossip, const u8 *msg)
|
||||
log_info_struct(gossip->log, "Peer %s ready for channel open",
|
||||
struct pubkey, peer->id);
|
||||
|
||||
/* FIXME: finish json connect cmd if any. */
|
||||
if (peer->connect_cmd) {
|
||||
struct json_result *response;
|
||||
response = new_json_result(peer->connect_cmd);
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_pubkey(response, "id", peer->id);
|
||||
json_object_end(response);
|
||||
command_success(peer->connect_cmd, response);
|
||||
peer->connect_cmd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static enum subdaemon_status gossip_status(struct subdaemon *gossip,
|
||||
|
||||
@@ -23,9 +23,13 @@ static void destroy_peer(struct peer *peer)
|
||||
list_del_from(&peer->ld->peers, &peer->list);
|
||||
if (peer->fd >= 0)
|
||||
close(peer->fd);
|
||||
if (peer->connect_cmd)
|
||||
/* FIXME: Better diagnostics */
|
||||
command_fail(peer->connect_cmd, "Connect failed");
|
||||
}
|
||||
|
||||
static struct peer *new_peer(const tal_t *ctx, struct lightningd *ld, int fd)
|
||||
static struct peer *new_peer(const tal_t *ctx, struct lightningd *ld, int fd,
|
||||
struct command *cmd)
|
||||
{
|
||||
static u64 id_counter;
|
||||
struct peer *peer = tal(ctx, struct peer);
|
||||
@@ -34,6 +38,7 @@ static struct peer *new_peer(const tal_t *ctx, struct lightningd *ld, int fd)
|
||||
peer->owner = NULL;
|
||||
peer->id = NULL;
|
||||
peer->fd = fd;
|
||||
peer->connect_cmd = cmd;
|
||||
list_add_tail(&ld->peers, &peer->list);
|
||||
tal_add_destructor(peer, destroy_peer);
|
||||
return peer;
|
||||
@@ -143,7 +148,7 @@ error:
|
||||
/* FIXME: timeout handshake if taking too long? */
|
||||
static struct io_plan *peer_in(struct io_conn *conn, struct lightningd *ld)
|
||||
{
|
||||
struct peer *peer = new_peer(ld, ld, io_conn_fd(conn));
|
||||
struct peer *peer = new_peer(ld, ld, io_conn_fd(conn), NULL);
|
||||
|
||||
/* Get HSM fd for this peer. */
|
||||
subdaemon_req(ld->hsm,
|
||||
@@ -268,7 +273,7 @@ static struct io_plan *peer_out(struct io_conn *conn,
|
||||
struct json_connecting *jc)
|
||||
{
|
||||
struct lightningd *ld = ld_from_dstate(jc->cmd->dstate);
|
||||
struct peer *peer = new_peer(ld, ld, io_conn_fd(conn));
|
||||
struct peer *peer = new_peer(ld, ld, io_conn_fd(conn), jc->cmd);
|
||||
|
||||
/* We already know ID we're trying to reach. */
|
||||
peer->id = tal_dup(peer, struct pubkey, &jc->id);
|
||||
|
||||
@@ -23,6 +23,9 @@ struct peer {
|
||||
|
||||
/* HSM connection for this peer. */
|
||||
int hsmfd;
|
||||
|
||||
/* Json command which made us connect (if any) */
|
||||
struct command *connect_cmd;
|
||||
};
|
||||
|
||||
struct peer *peer_by_unique_id(struct lightningd *ld, u64 unique_id);
|
||||
|
||||
@@ -11,8 +11,12 @@ setup_lightning 2
|
||||
|
||||
start_lightningd 2 lightningd/lightningd
|
||||
|
||||
# FIXME: Try to connect.
|
||||
# lcli1 connect localhost $PORT2 $ID2
|
||||
if lcli1 connect localhost $PORT2 $ID1; then
|
||||
echo Connected OK with wrong ID? >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
lcli1 connect localhost $PORT2 $ID2
|
||||
|
||||
# FIXME: Check status.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user