Skip to content

Commit b1b9a49

Browse files
committed
Process incoming alternative addresses and store them to the CoreLN database
Signed-off-by: Max Rantil <[email protected]>
1 parent 44315f2 commit b1b9a49

19 files changed

+88
-352
lines changed

channeld/channeld.c

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ struct peer {
6868
bool channel_ready[NUM_SIDES];
6969
u64 next_index[NUM_SIDES];
7070

71+
/* ID of peer */
72+
struct node_id id;
73+
7174
/* --developer? */
7275
bool developer;
7376

@@ -191,10 +194,13 @@ struct peer {
191194

192195
/* --experimental-upgrade-protocol */
193196
bool experimental_upgrade;
197+
198+
/* Alt address for peer connections not publicly announced */
199+
u8 *alt_addr;
194200
};
195201

196202
static void start_commit_timer(struct peer *peer);
197-
// void send_peer_alt_address(struct peer *peer, const struct pubkey *node_id, const u8 *alt_address);
203+
static void send_peer_alt_address(struct peer *peer);
198204

199205
static void billboard_update(const struct peer *peer)
200206
{
@@ -536,46 +542,13 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
536542
check_mutual_splice_locked(peer);
537543
}
538544

539-
// void send_peer_alt_address(struct peer *peer, const struct pubkey *node_id, const u8 *alt_address)
540-
// {
541-
// u8 *msg = towire_peer_alt_address(peer, node_id, alt_address);
542-
543-
// peer_write(peer->pps, take(msg));
544-
// fprintf(stderr, "Sent alternative address message to peer");
545-
// }
545+
static void send_peer_alt_address(struct peer *peer) {
546+
struct pubkey node_id;
546547

547-
static void handle_peer_alt_addr(struct peer *peer, const u8 *msg)
548-
{
549-
struct pubkey peer_id;
550-
u8 *alt_addr;
551-
// u32 *timestamp = NULL;
552-
// fprintf(stderr, "Entering handle_peer_alt_eight with msg %s\n", msg);
553-
fprintf(stderr, "1 THIS IS A TEST\n");
554-
status_info("2 THIS IS A TEST");
555-
if (!fromwire_peer_alt_address(tmpctx, msg, &peer_id, &alt_addr/* , timestamp */)) {
556-
master_badmsg(WIRE_PEER_ALT_ADDRESS, msg);
548+
if (pubkey_from_node_id(&node_id, &peer->id)) {
549+
u8 *msg = towire_peer_alt_address(peer, &node_id, peer->alt_addr);
550+
peer_write(peer->pps, take(msg));
557551
}
558-
fprintf(stderr, "3 THIS IS A TEST\n");
559-
status_info("3.5 THIS IS A TEST");
560-
// peer = peer_htable_get(daemon->peers, &id);
561-
// if (!peer)
562-
// return;
563-
564-
// Store the alternative address in the peer structure
565-
// peer->alt_address = alt_addr; // Assuming you have such a field in the struct
566-
// log_info(peer->log, "Received alt address: %s", alt_addr);
567-
568-
// struct peer *peer = peer_htable_get(daemon->peers, &peer_id);
569-
// if (!peer)
570-
// return; // Peer not found
571-
572-
// updating peer information in a database:
573-
// update_peer_address(peer, &alt_addr);
574-
575-
// Optionally, trigger actions that use the new address immediately,
576-
// such as attempting a new connection:
577-
// try_connect_to_peer(peer, &alt_addr);
578-
579552
}
580553

581554
static void handle_peer_channel_ready(struct peer *peer, const u8 *msg)
@@ -4201,14 +4174,14 @@ static void peer_in(struct peer *peer, const u8 *msg)
42014174
{
42024175
enum peer_wire type = fromwire_peektype(msg);
42034176

4204-
// fprintf(stderr, "4 THIS IS A TEST\n");
4205-
// status_info("5 THIS IS A TEST %s", msg);
4206-
42074177
if (handle_peer_error_or_warning(peer->pps, msg))
42084178
return;
42094179

42104180
check_tx_abort(peer, msg);
42114181

4182+
if (peer->alt_addr)
4183+
send_peer_alt_address(peer);
4184+
42124185
/* If we're in STFU mode and aren't waiting for a STFU mode
42134186
* specific message, the only valid message was tx_abort */
42144187
if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) {
@@ -4300,9 +4273,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
43004273
case WIRE_SPLICE_LOCKED:
43014274
handle_peer_splice_locked(peer, msg);
43024275
return;
4303-
case WIRE_PEER_ALT_ADDRESS:
4304-
handle_peer_alt_addr(peer, msg);
4305-
return;
43064276
case WIRE_INIT:
43074277
case WIRE_OPEN_CHANNEL:
43084278
case WIRE_ACCEPT_CHANNEL:
@@ -4344,6 +4314,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
43444314
case WIRE_ONION_MESSAGE:
43454315
case WIRE_PEER_STORAGE:
43464316
case WIRE_YOUR_PEER_STORAGE:
4317+
case WIRE_PEER_ALT_ADDRESS:
43474318
abort();
43484319
}
43494320

@@ -5918,7 +5889,9 @@ static void init_channel(struct peer *peer)
59185889
&reestablish_only,
59195890
&peer->experimental_upgrade,
59205891
&peer->splice_state->inflights,
5921-
&peer->local_alias)) {
5892+
&peer->local_alias,
5893+
&peer->alt_addr,
5894+
&peer->id)) {
59225895
master_badmsg(WIRE_CHANNELD_INIT, msg);
59235896
}
59245897

channeld/channeld.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
#include <ccan/tal/tal.h>
77

88
const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES);
9-
// void send_peer_alt_address(struct peer *peer, const struct pubkey *node_id, const u8 *alt_address);
109

1110
#endif /* LIGHTNING_CHANNELD_CHANNELD_H */

channeld/channeld_wire.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ msgdata,channeld_init,experimental_upgrade,bool,
7777
msgdata,channeld_init,num_inflights,u16,
7878
msgdata,channeld_init,inflights,inflight,num_inflights
7979
msgdata,channeld_init,scid_alias,short_channel_id,
80+
msgdata,channeld_init,alt_addr_len,u16,
81+
msgdata,channeld_init,alt_addr,u8,alt_addr_len,
82+
msgdata,channeld_init,id,node_id,
8083

8184
# channeld->lightningd: successfully negotated reestablishment.
8285
msgtype,channeld_reestablished,1101

common/wireaddr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ bool wireaddr_eq_without_port(const struct wireaddr *a, const struct wireaddr *b
5656
* announce */
5757
enum addr_listen_announce {
5858
ADDR_LISTEN = (1 << 0),
59-
ALT_ADDR_LISTEN = (2 << 0),
6059
ADDR_ANNOUNCE = (1 << 1),
6160
ADDR_LISTEN_AND_ANNOUNCE = ADDR_LISTEN|ADDR_ANNOUNCE
6261
};

0 commit comments

Comments
 (0)