diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 450f55770..992bc9f7c 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -134,7 +134,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) peer_already_connected(gossip->ld, msg); break; case WIRE_GOSSIP_PEER_CONNECTION_FAILED: - /* TODO(cdecker) Implement handler */ + peer_connection_failed(gossip->ld, msg); break; case WIRE_GOSSIP_PEER_NONGOSSIP: if (tal_count(fds) != 2) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 984d7c877..defe14718 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -606,6 +606,29 @@ void peer_already_connected(struct lightningd *ld, const u8 *msg) connect_succeeded(ld, &id); } +void peer_connection_failed(struct lightningd *ld, const u8 *msg) +{ + struct pubkey id; + u32 attempts, timediff; + struct connect *i, *next; + if (!fromwire_gossip_peer_connection_failed(msg, NULL, &id, &attempts, &timediff)) + fatal("Gossip gave bad GOSSIP_PEER_CONNECTION_FAILED message %s", tal_hex(msg, msg)); + + /* Careful! Completing command frees connect. */ + list_for_each_safe(&ld->connects, i, next, list) { + if (!pubkey_eq(&i->id, &id)) + continue; + + command_fail( + i->cmd, + "Could not connect to %s after %d seconds and %d attempts", + type_to_string(msg, struct pubkey, &id), timediff, + attempts); + } +} + + + void peer_sent_nongossip(struct lightningd *ld, const struct pubkey *id, const struct wireaddr *addr, diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 51f5003ed..117588bd9 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -179,6 +179,9 @@ void peer_connected(struct lightningd *ld, const u8 *msg, /* This simply means we asked to reach a peer, but we already have it */ void peer_already_connected(struct lightningd *ld, const u8 *msg); +/* We were unable to connect to the peer */ +void peer_connection_failed(struct lightningd *ld, const u8 *msg); + void peer_sent_nongossip(struct lightningd *ld, const struct pubkey *id, const struct wireaddr *addr,