Skip to content

Commit f15ff11

Browse files
committed
connected: tell lightningd if we didn't find an address we could even *try* to connect to.
This is important: if it's tor-only and we don't have a proxy, we will fail to connect, but it's no indication that the node is unreachable. Same with IPv6. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 46c33c4 commit f15ff11

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

connectd/connectd.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,12 @@ struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
789789
*/
790790
static void connect_failed(struct daemon *daemon,
791791
const struct node_id *id,
792+
bool connect_attempted,
792793
const char *connect_reason,
793794
struct timemono start,
794795
enum jsonrpc_errcode errcode,
795796
const char *errfmt, ...)
796-
PRINTF_FMT(6, 7);
797+
PRINTF_FMT(7, 8);
797798

798799
static void reconnect(struct important_id *imp)
799800
{
@@ -865,6 +866,7 @@ void release_one_waiting_connection(struct daemon *daemon, const char *why)
865866

866867
static void connect_failed(struct daemon *daemon,
867868
const struct node_id *id,
869+
bool connect_attempted,
868870
const char *connect_reason,
869871
struct timemono start,
870872
enum jsonrpc_errcode errcode,
@@ -885,7 +887,8 @@ static void connect_failed(struct daemon *daemon,
885887
msg = towire_connectd_connect_failed(NULL, id,
886888
connect_reason,
887889
time_to_nsec(timemono_since(start)),
888-
errcode, errmsg);
890+
errcode, errmsg,
891+
connect_attempted);
889892
daemon_conn_send(daemon->master, take(msg));
890893

891894
/* If we're supposed to schedule a reconnect, do so */
@@ -1037,7 +1040,7 @@ static void try_connect_one_addr(struct connecting *connect)
10371040
struct node_id id = connect->id;
10381041
const char *errors = tal_steal(tmpctx, connect->errors);
10391042

1040-
connect_failed(daemon, &id,
1043+
connect_failed(daemon, &id, connect->connect_attempted,
10411044
connect->reason, connect->start,
10421045
CONNECT_ALL_ADDRESSES_FAILED,
10431046
"All addresses failed: %s",
@@ -1166,6 +1169,8 @@ static void try_connect_one_addr(struct connecting *connect)
11661169
goto next;
11671170
}
11681171

1172+
connect->connect_attempted = true;
1173+
11691174
/* This creates the new connection using our fd, with the initialization
11701175
* function one of the above. */
11711176
if (use_proxy)
@@ -1872,7 +1877,7 @@ static void try_connect_peer(struct daemon *daemon,
18721877
/* Still no address? Fail immediately. Important ones get
18731878
* retried; an address may get gossiped. */
18741879
if (tal_count(addrs) == 0) {
1875-
connect_failed(daemon, id, reason, time_mono(),
1880+
connect_failed(daemon, id, false, reason, time_mono(),
18761881
CONNECT_NO_KNOWN_ADDRESS,
18771882
"Unable to connect, no address known for peer");
18781883
return;
@@ -1892,6 +1897,7 @@ static void try_connect_peer(struct daemon *daemon,
18921897
connect->connstate = "Connection establishment";
18931898
connect->errors = tal_strdup(connect, "");
18941899
connect->conn = NULL;
1900+
connect->connect_attempted = false;
18951901
connecting_htable_add(daemon->connecting, connect);
18961902
tal_add_destructor(connect, destroy_connecting);
18971903

connectd/connectd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ struct connecting {
214214
/* When did we start? */
215215
struct timemono start;
216216

217+
/* Did we find an address we could attempt to connect to? */
218+
bool connect_attempted;
219+
217220
/* Accumulated errors */
218221
char *errors;
219222
};

connectd/connectd_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ msgdata,connectd_connect_failed,connect_reason,wirestring,
7373
msgdata,connectd_connect_failed,connect_nsec,u64,
7474
msgdata,connectd_connect_failed,failcode,enum jsonrpc_errcode,
7575
msgdata,connectd_connect_failed,failreason,wirestring,
76+
msgdata,connectd_connect_failed,connect_attempted,bool,
7677

7778
# Connectd -> master: we got a peer.
7879
msgtype,connectd_peer_connected,2002

lightningd/connect_control.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ static void connect_failed(struct lightningd *ld,
257257
const char *connect_reason,
258258
u64 connect_nsec,
259259
enum jsonrpc_errcode errcode,
260-
const char *errmsg)
260+
const char *errmsg,
261+
bool connect_attempted)
261262
{
262263
struct connect *c;
263264

@@ -275,7 +276,8 @@ void connect_failed_disconnect(struct lightningd *ld,
275276
connect_failed(ld, id, addrhint,
276277
"", 0,
277278
CONNECT_DISCONNECTED_DURING,
278-
"disconnected during connection");
279+
"disconnected during connection",
280+
false);
279281
}
280282

281283
static void handle_connect_failed(struct lightningd *ld, const u8 *msg)
@@ -285,15 +287,18 @@ static void handle_connect_failed(struct lightningd *ld, const u8 *msg)
285287
char *errmsg;
286288
char *connect_reason;
287289
u64 nsec;
290+
bool connect_attempted;
288291

289292
if (!fromwire_connectd_connect_failed(tmpctx, msg, &id,
290293
&connect_reason,
291294
&nsec,
292-
&errcode, &errmsg))
295+
&errcode, &errmsg,
296+
&connect_attempted))
293297
fatal("Connect gave bad CONNECTD_CONNECT_FAILED message %s",
294298
tal_hex(msg, msg));
295299

296-
connect_failed(ld, &id, NULL, connect_reason, nsec, errcode, errmsg);
300+
connect_failed(ld, &id, NULL, connect_reason, nsec, errcode, errmsg,
301+
connect_attempted);
297302
}
298303

299304
const char *connect_any_cmd_id(const tal_t *ctx,

0 commit comments

Comments
 (0)