@@ -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
196202static 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
199205static 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
581554static 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
0 commit comments