gossip: Directly return an error if we don't know a node's address

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-01-27 17:18:45 +01:00 committed by Rusty Russell
parent 61e982c6b7
commit acc6afc8de
3 changed files with 31 additions and 11 deletions

View File

@ -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 " status_trace("Failed to connect after %d attempts, giving up "
"after %d seconds", "after %d seconds",
reach->attempts, diff); reach->attempts, diff);
daemon_conn_send(&reach->daemon->master, daemon_conn_send(
take(towire_gossip_peer_connection_failed( &reach->daemon->master,
conn, &reach->id, diff, reach->attempts))); take(towire_gossip_peer_connection_failed(
conn, &reach->id, diff, reach->attempts, false)));
tal_free(reach); tal_free(reach);
} else { } else {
status_trace("Failed connected out for %s, will try again", 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 */ /* FIXME: add reach_failed message */
status_trace("No address known for %s, giving up", status_trace("No address known for %s, giving up",
type_to_string(trc, struct pubkey, &reach->id)); 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); tal_free(reach);
return; return;
} }

View File

@ -48,6 +48,7 @@ gossip_peer_connection_failed,3020
gossip_peer_connection_failed,,id,struct pubkey gossip_peer_connection_failed,,id,struct pubkey
gossip_peer_connection_failed,,timeout,u32 gossip_peer_connection_failed,,timeout,u32
gossip_peer_connection_failed,,attempts,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 # Gossipd -> master: peer sent non-gossip packet. Two fds: peer and gossip
gossip_peer_nongossip,3003 gossip_peer_nongossip,3003

1 #include <common/cryptomsg.h>
48 gossip_peer_nongossip,,addr,struct wireaddr gossip_peer_nongossip,,id,struct pubkey
49 gossip_peer_nongossip,,crypto_state,struct crypto_state gossip_peer_nongossip,,addr,struct wireaddr
50 gossip_peer_nongossip,,gossip_index,u64 gossip_peer_nongossip,,crypto_state,struct crypto_state
51 gossip_peer_nongossip,,gossip_index,u64
52 gossip_peer_nongossip,,gflen,u16
53 gossip_peer_nongossip,,gfeatures,gflen*u8
54 gossip_peer_nongossip,,lflen,u16

View File

@ -610,20 +610,32 @@ void peer_connection_failed(struct lightningd *ld, const u8 *msg)
{ {
struct pubkey id; struct pubkey id;
u32 attempts, timediff; u32 attempts, timediff;
struct connect *i, *next; struct connect *i, *next;
if (!fromwire_gossip_peer_connection_failed(msg, NULL, &id, &attempts, &timediff)) bool addr_unknown;
fatal("Gossip gave bad GOSSIP_PEER_CONNECTION_FAILED message %s", tal_hex(msg, msg)); 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. */ /* Careful! Completing command frees connect. */
list_for_each_safe(&ld->connects, i, next, list) { list_for_each_safe(&ld->connects, i, next, list) {
if (!pubkey_eq(&i->id, &id)) if (!pubkey_eq(&i->id, &id))
continue; continue;
command_fail( command_fail(i->cmd, "%s", error);
i->cmd,
"Could not connect to %s after %d seconds and %d attempts",
type_to_string(msg, struct pubkey, &id), timediff,
attempts);
} }
} }