From acc6afc8de590f645a4f699c363591a162eb62a0 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sat, 27 Jan 2018 17:18:45 +0100 Subject: [PATCH] gossip: Directly return an error if we don't know a node's address Signed-off-by: Christian Decker --- gossipd/gossip.c | 13 ++++++++++--- gossipd/gossip_wire.csv | 1 + lightningd/peer_control.c | 28 ++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index c72142e0d..119f471ca 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1573,9 +1573,10 @@ static void connect_failed(struct io_conn *conn, struct reaching *reach) status_trace("Failed to connect after %d attempts, giving up " "after %d seconds", reach->attempts, diff); - daemon_conn_send(&reach->daemon->master, - take(towire_gossip_peer_connection_failed( - conn, &reach->id, diff, reach->attempts))); + daemon_conn_send( + &reach->daemon->master, + take(towire_gossip_peer_connection_failed( + conn, &reach->id, diff, reach->attempts, false))); tal_free(reach); } else { status_trace("Failed connected out for %s, will try again", @@ -1645,6 +1646,12 @@ static void try_connect(struct reaching *reach) /* FIXME: add reach_failed message */ status_trace("No address known for %s, giving up", type_to_string(trc, struct pubkey, &reach->id)); + daemon_conn_send( + &reach->daemon->master, + take(towire_gossip_peer_connection_failed( + reach, &reach->id, + time_now().ts.tv_sec - reach->first_attempt, + reach->attempts, true))); tal_free(reach); return; } diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 0ebeb0493..41e183c91 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -48,6 +48,7 @@ gossip_peer_connection_failed,3020 gossip_peer_connection_failed,,id,struct pubkey gossip_peer_connection_failed,,timeout,u32 gossip_peer_connection_failed,,attempts,u32 +gossip_peer_connection_failed,,addr_unknown,bool # Gossipd -> master: peer sent non-gossip packet. Two fds: peer and gossip gossip_peer_nongossip,3003 diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index defe14718..909af6838 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -610,20 +610,32 @@ 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)); + struct connect *i, *next; + bool addr_unknown; + char *error; + + if (!fromwire_gossip_peer_connection_failed(msg, NULL, &id, &attempts, + &timediff, &addr_unknown)) + fatal( + "Gossip gave bad GOSSIP_PEER_CONNECTION_FAILED message %s", + tal_hex(msg, msg)); + + if (addr_unknown) { + error = tal_fmt( + msg, "No address known for node %s, please provide one", + type_to_string(msg, struct pubkey, &id)); + } else { + error = tal_fmt(msg, "Could not connect to %s after %d seconds and %d attempts", + type_to_string(msg, struct pubkey, &id), timediff, + attempts); + } /* 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); + command_fail(i->cmd, "%s", error); } }