Skip to content

Commit b001741

Browse files
committed
Connect to peers alt addr (if provided) when reconnecting. If both nodes
provide alt addrsses only the connection_out will utilize the alt addr. Signed-off-by: Max Rantil <[email protected]>
1 parent b1b9a49 commit b001741

File tree

18 files changed

+147
-65
lines changed

18 files changed

+147
-65
lines changed

channeld/channeld.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ struct peer {
196196
bool experimental_upgrade;
197197

198198
/* Alt address for peer connections not publicly announced */
199-
u8 *alt_addr;
199+
u8 *our_alt_addr;
200200
};
201201

202202
static void start_commit_timer(struct peer *peer);
203-
static void send_peer_alt_address(struct peer *peer);
203+
static void send_peer_our_alt_address(struct peer *peer);
204204

205205
static void billboard_update(const struct peer *peer)
206206
{
@@ -542,11 +542,11 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
542542
check_mutual_splice_locked(peer);
543543
}
544544

545-
static void send_peer_alt_address(struct peer *peer) {
545+
static void send_peer_our_alt_address(struct peer *peer) {
546546
struct pubkey node_id;
547547

548548
if (pubkey_from_node_id(&node_id, &peer->id)) {
549-
u8 *msg = towire_peer_alt_address(peer, &node_id, peer->alt_addr);
549+
u8 *msg = towire_peer_alt_address(peer, &node_id, peer->our_alt_addr);
550550
peer_write(peer->pps, take(msg));
551551
}
552552
}
@@ -4179,8 +4179,8 @@ static void peer_in(struct peer *peer, const u8 *msg)
41794179

41804180
check_tx_abort(peer, msg);
41814181

4182-
if (peer->alt_addr)
4183-
send_peer_alt_address(peer);
4182+
if (peer->our_alt_addr)
4183+
send_peer_our_alt_address(peer);
41844184

41854185
/* If we're in STFU mode and aren't waiting for a STFU mode
41864186
* specific message, the only valid message was tx_abort */
@@ -5890,7 +5890,7 @@ static void init_channel(struct peer *peer)
58905890
&peer->experimental_upgrade,
58915891
&peer->splice_state->inflights,
58925892
&peer->local_alias,
5893-
&peer->alt_addr,
5893+
&peer->our_alt_addr,
58945894
&peer->id)) {
58955895
master_badmsg(WIRE_CHANNELD_INIT, msg);
58965896
}

connectd/connectd.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,26 @@ static struct io_plan *connection_in(struct io_conn *conn,
506506

507507
conn_in_arg.daemon = daemon;
508508
conn_in_arg.is_websocket = false;
509+
509510
return conn_in(conn, &conn_in_arg);
510511
}
511512

513+
void handle_peer_alt_address(struct peer *peer, const u8 *msg)
514+
{
515+
u8 *peer_alt_addr;
516+
struct pubkey peer_id;
517+
/* u32 *timestamp = NULL; */ /* TODO */
518+
519+
if (!fromwire_peer_alt_address(peer, msg, &peer_id, &peer_alt_addr/* , timestamp */)) {
520+
master_badmsg(WIRE_PEER_ALT_ADDRESS, msg);
521+
}
522+
523+
msg = towire_connectd_alt_address(NULL, &peer_id, peer_alt_addr);
524+
daemon_conn_send(peer->daemon->master, take(msg));
525+
526+
tal_free(peer_alt_addr);
527+
}
528+
512529
/*~ <hello>I speak web socket</hello>.
513530
*
514531
* Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */
@@ -1776,22 +1793,6 @@ static void try_connect_peer(struct daemon *daemon,
17761793
try_connect_one_addr(connect);
17771794
}
17781795

1779-
void handle_peer_alt_addr(struct peer *peer, const u8 *msg)
1780-
{
1781-
u8 *alt_addr;
1782-
struct pubkey peer_id;
1783-
1784-
// u32 *timestamp = NULL;
1785-
if (!fromwire_peer_alt_address(peer, msg, &peer_id, &alt_addr/* , timestamp */)) {
1786-
master_badmsg(WIRE_PEER_ALT_ADDRESS, msg);
1787-
}
1788-
1789-
msg = towire_connectd_alt_address(NULL, &peer_id, alt_addr);
1790-
daemon_conn_send(peer->daemon->master, take(msg));
1791-
1792-
tal_free(alt_addr);
1793-
}
1794-
17951796
/* lightningd tells us to connect to a peer by id, with optional addr hint. */
17961797
static void connect_to_peer(struct daemon *daemon, const u8 *msg)
17971798
{

connectd/connectd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct peer {
6161

6262
/* The pubkey of the node */
6363
struct node_id id;
64+
6465
/* Counters and keys for symmetric crypto */
6566
struct crypto_state cs;
6667

@@ -294,6 +295,6 @@ void destroy_peer(struct peer *peer);
294295
void close_random_connection(struct daemon *daemon);
295296

296297
/* Handles alternative address message from peer. */
297-
void handle_peer_alt_addr(struct peer *peer, const u8 *msg);
298+
void handle_peer_alt_address(struct peer *peer, const u8 *msg);
298299

299300
#endif /* LIGHTNING_CONNECTD_CONNECTD_H */

connectd/multiplex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,8 @@ static bool handle_message_locally(struct peer *peer, const u8 *msg)
772772
} else if (type == WIRE_ONION_MESSAGE) {
773773
handle_onion_message(peer->daemon, peer, msg);
774774
return true;
775-
} else if (type == WIRE_PEER_ALT_ADDRESS) { // IS THIS THE RIGHT PLACE ?? IT WORKS BUT...
776-
handle_peer_alt_addr(peer, msg);
775+
} else if (type == WIRE_PEER_ALT_ADDRESS) {
776+
handle_peer_alt_address(peer, msg);
777777
return true;
778778
} else if (handle_custommsg(peer->daemon, peer, msg)) {
779779
return true;

contrib/msggen/msggen/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,6 +4146,7 @@
41464146
"netaddr": [
41474147
"127.0.0.1:40119"
41484148
],
4149+
"alt_addr": "127.0.0.21:7171",
41494150
"features": "08a0000a8a5961",
41504151
"log": [
41514152
{
@@ -21203,6 +21204,7 @@
2120321204
]
2120421205
}
2120521206
},
21207+
"alt_addr": {},
2120621208
"remote_addr": {
2120721209
"type": "string",
2120821210
"description": [
@@ -21247,6 +21249,7 @@
2124721249
"netaddr": [
2124821250
"127.0.0.1:44619"
2124921251
],
21252+
"alt_addr": "127.0.0.21:7171",
2125021253
"features": "08a0000a0a69a2"
2125121254
}
2125221255
]
@@ -21270,6 +21273,7 @@
2127021273
"netaddr": [
2127121274
"127.0.0.1:48862"
2127221275
],
21276+
"alt_addr": "127.0.0.21:7171",
2127321277
"features": "08a0000a0a69a2"
2127421278
}
2127521279
]

doc/schemas/lightning-commando.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"netaddr": [
137137
"127.0.0.1:40119"
138138
],
139+
"alt_addr": "127.0.0.21:7171",
139140
"features": "08a0000a8a5961",
140141
"log": [
141142
{

doc/schemas/lightning-listconfigs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@
11851185
],
11861186
"properties": {
11871187
"values_str": {
1188-
"added": "v24.05",
1188+
"added": "v24.05",
11891189
"type": "array",
11901190
"items": {
11911191
"type": "string",

doc/schemas/lightning-listpeers.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
]
280280
}
281281
},
282+
"alt_addr": {},
282283
"remote_addr": {
283284
"type": "string",
284285
"description": [
@@ -323,6 +324,7 @@
323324
"netaddr": [
324325
"127.0.0.1:44619"
325326
],
327+
"alt_addr": "127.0.0.21:7171",
326328
"features": "08a0000a0a69a2"
327329
}
328330
]
@@ -346,6 +348,7 @@
346348
"netaddr": [
347349
"127.0.0.1:48862"
348350
],
351+
"alt_addr": "127.0.0.21:7171",
349352
"features": "08a0000a0a69a2"
350353
}
351354
]

lightningd/channel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,5 @@ const u8 *channel_update_for_error(const tal_t *ctx,
798798

799799
struct amount_msat htlc_max_possible_send(const struct channel *channel);
800800

801+
801802
#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_H */

lightningd/channel_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ bool peer_start_channeld(struct channel *channel,
17261726
cast_const2(const struct inflight **,
17271727
inflights),
17281728
*channel->alias[LOCAL],
1729-
ld->alt_addr,
1729+
ld->our_alt_addr,
17301730
&ld->id);
17311731

17321732
/* We don't expect a response: we are triggered by funding_depth_cb. */

0 commit comments

Comments
 (0)