@@ -68,6 +68,9 @@ struct peer {
68
68
bool channel_ready [NUM_SIDES ];
69
69
u64 next_index [NUM_SIDES ];
70
70
71
+ /* ID of peer */
72
+ struct node_id id ;
73
+
71
74
/* --developer? */
72
75
bool developer ;
73
76
@@ -191,10 +194,13 @@ struct peer {
191
194
192
195
/* --experimental-upgrade-protocol */
193
196
bool experimental_upgrade ;
197
+
198
+ /* Alt address for peer connections not publicly announced */
199
+ u8 * alt_addr ;
194
200
};
195
201
196
202
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 );
198
204
199
205
static void billboard_update (const struct peer * peer )
200
206
{
@@ -536,46 +542,13 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
536
542
check_mutual_splice_locked (peer );
537
543
}
538
544
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 ;
546
547
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 ));
557
551
}
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
-
579
552
}
580
553
581
554
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)
4201
4174
{
4202
4175
enum peer_wire type = fromwire_peektype (msg );
4203
4176
4204
- // fprintf(stderr, "4 THIS IS A TEST\n");
4205
- // status_info("5 THIS IS A TEST %s", msg);
4206
-
4207
4177
if (handle_peer_error_or_warning (peer -> pps , msg ))
4208
4178
return ;
4209
4179
4210
4180
check_tx_abort (peer , msg );
4211
4181
4182
+ if (peer -> alt_addr )
4183
+ send_peer_alt_address (peer );
4184
+
4212
4185
/* If we're in STFU mode and aren't waiting for a STFU mode
4213
4186
* specific message, the only valid message was tx_abort */
4214
4187
if (is_stfu_active (peer ) && !peer -> stfu_wait_single_msg ) {
@@ -4300,9 +4273,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
4300
4273
case WIRE_SPLICE_LOCKED :
4301
4274
handle_peer_splice_locked (peer , msg );
4302
4275
return ;
4303
- case WIRE_PEER_ALT_ADDRESS :
4304
- handle_peer_alt_addr (peer , msg );
4305
- return ;
4306
4276
case WIRE_INIT :
4307
4277
case WIRE_OPEN_CHANNEL :
4308
4278
case WIRE_ACCEPT_CHANNEL :
@@ -4344,6 +4314,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
4344
4314
case WIRE_ONION_MESSAGE :
4345
4315
case WIRE_PEER_STORAGE :
4346
4316
case WIRE_YOUR_PEER_STORAGE :
4317
+ case WIRE_PEER_ALT_ADDRESS :
4347
4318
abort ();
4348
4319
}
4349
4320
@@ -5918,7 +5889,9 @@ static void init_channel(struct peer *peer)
5918
5889
& reestablish_only ,
5919
5890
& peer -> experimental_upgrade ,
5920
5891
& peer -> splice_state -> inflights ,
5921
- & peer -> local_alias )) {
5892
+ & peer -> local_alias ,
5893
+ & peer -> alt_addr ,
5894
+ & peer -> id )) {
5922
5895
master_badmsg (WIRE_CHANNELD_INIT , msg );
5923
5896
}
5924
5897
0 commit comments