@@ -318,24 +318,25 @@ static struct io_plan *handshake_in_success(struct io_conn *conn,
318318 node_id_from_pubkey (& id , id_key );
319319 status_peer_debug (& id , "Connect IN" );
320320
321- /* FIXME(maxrantil): loop all alt_bind_addr after making it an array (code down-under)*/
322- /* bool is_whitelisted = false;
323-
321+ /* Confirm that peer connects to the alt-bind-addr you sent */
324322 if (daemon -> alt_bind_addr ) {
325- for (size_t i = 0; i < tal_count(daemon->alt_bind_addr); i++) {
326- if (strcmp(incoming_addr, (char *)daemon->alt_bind_addr[i]) == 0) {
327- is_whitelisted = true;
323+ char * incoming_addr = fmt_wireaddr_internal (tmpctx , addr );
324+ fprintf (stderr , "--> incoming connection addr: '%s'\n" , incoming_addr );
325+
326+ char * bind_addrs = tal_strdup (NULL , (char * )daemon -> alt_bind_addr );
327+ char * token = strtok (bind_addrs , "," );
328+
329+ while (token != NULL ) {
330+ fprintf (stderr , "--> comparing '%s' with token '%s'\n" , incoming_addr , token );
331+ if (strcmp (incoming_addr , token ) == 0 ) {
332+ fprintf (stderr , "--> INSIDE\n" );
333+ towire_connectd_alt_addr_whitelist (tmpctx , id_key , (u8 * )incoming_addr );
328334 break ;
329335 }
336+ token = strtok (NULL , "," );
330337 }
331- } */
332-
333- char * incoming_addr = fmt_wireaddr_internal (tmpctx , addr );
334-
335- /* Confirm that peer connects to the alt-bind-addr you sent */
336- if (daemon -> alt_bind_addr )
337- if (strcmp (incoming_addr , (char * )daemon -> alt_bind_addr ) == 0 )
338- towire_connectd_alt_addr_whitelist (tmpctx , id_key , (u8 * )incoming_addr );
338+ tal_free (bind_addrs );
339+ }
339340
340341 return peer_exchange_initmsg (conn , daemon , daemon -> our_features ,
341342 cs , & id , addr , timeout , is_websocket , true);
@@ -655,6 +656,9 @@ static struct io_plan *handshake_out_success(struct io_conn *conn,
655656 node_id_from_pubkey (& id , key );
656657 connect -> connstate = "Exchanging init messages" ;
657658 status_peer_debug (& id , "Connect OUT" );
659+
660+ fprintf (stderr , "<-- outgoing connection addr: '%s'\n" , fmt_wireaddr_internal (tmpctx , addr ));
661+
658662 return peer_exchange_initmsg (conn , connect -> daemon ,
659663 connect -> daemon -> our_features ,
660664 cs , & id , addr , timeout , is_websocket , false);
@@ -1719,6 +1723,7 @@ static void try_connect_peer(struct daemon *daemon,
17191723 const struct node_id * id ,
17201724 struct wireaddr * gossip_addrs ,
17211725 struct wireaddr_internal * addrhint STEALS ,
1726+ struct wireaddr_internal * peer_alt_addrs STEALS ,
17221727 bool dns_fallback ,
17231728 bool transient )
17241729{
@@ -1746,6 +1751,13 @@ static void try_connect_peer(struct daemon *daemon,
17461751 tal_arr_expand (& connect -> addrs , * addrhint );
17471752 }
17481753
1754+ /* Update addrs with peer_alt_addrs if provided */
1755+ if (peer_alt_addrs ) {
1756+ for (size_t i = 0 ; i < tal_count (peer_alt_addrs ); i ++ ) {
1757+ tal_arr_expand (& connect -> addrs , peer_alt_addrs [i ]);
1758+ }
1759+ }
1760+
17491761 return ;
17501762 }
17511763
@@ -1764,6 +1776,22 @@ static void try_connect_peer(struct daemon *daemon,
17641776 && !addrhint -> u .wireaddr .is_websocket
17651777 ? & addrhint -> u .wireaddr .wireaddr : NULL );
17661778
1779+ /*
1780+ * FIXME(maxrantil): Question for Alex:
1781+ * Expanding the addrs array with peer_alt_addrs here (after addrhint) only allows
1782+ * using alt_addrs from node2 to node1 when connecting, but not from node1 to node2.
1783+ * If you start a regtest environment with (start_ln, fund_node, and then repeatedly
1784+ * stop_ln and start_ln), you will see that it only works about 50% of the time.
1785+ * This is because every second time or so, the nodes alternate as sender and receiver.
1786+ * If we move the for loop 10 lines up, before the addrhint if statement,
1787+ * the alt_addrs will be utilized by both nodes when initializing a connection.
1788+ * What are your thoughts on this?
1789+ */
1790+
1791+ /* Add all peer_alt_addrs next so they're tried after addrhint by connectd */
1792+ for (size_t i = 0 ; i < tal_count (peer_alt_addrs ); i ++ )
1793+ tal_arr_expand (& addrs , peer_alt_addrs [i ]);
1794+
17671795 if (tal_count (addrs ) == 0 ) {
17681796 /* Don't resolve via DNS seed if we're supposed to use proxy. */
17691797 if (use_proxy ) {
@@ -1820,16 +1848,17 @@ static void connect_to_peer(struct daemon *daemon, const u8 *msg)
18201848 struct node_id id ;
18211849 struct wireaddr_internal * addrhint ;
18221850 struct wireaddr * addrs ;
1851+ struct wireaddr_internal * peer_alt_addrs ;
18231852 bool dns_fallback ;
18241853 bool transient ;
18251854
18261855 if (!fromwire_connectd_connect_to_peer (tmpctx , msg ,
1827- & id , & addrs , & addrhint ,
1856+ & id , & addrs , & addrhint , & peer_alt_addrs ,
18281857 & dns_fallback ,
18291858 & transient ))
18301859 master_badmsg (WIRE_CONNECTD_CONNECT_TO_PEER , msg );
18311860
1832- try_connect_peer (daemon , & id , addrs , addrhint , dns_fallback , transient );
1861+ try_connect_peer (daemon , & id , addrs , addrhint , peer_alt_addrs , dns_fallback , transient );
18331862}
18341863
18351864/* lightningd tells us a peer should be disconnected. */
@@ -2098,13 +2127,16 @@ static void dev_exhaust_fds(struct daemon *daemon, const u8 *msg)
20982127 daemon -> dev_exhausted_fds = true;
20992128}
21002129
2130+ #include <stdio.h>
21012131static void handle_alt_addr_whitelist_reply (struct daemon * daemon , const u8 * msg )
21022132{
21032133 struct pubkey p_pk ;
21042134 struct peer * peer ;
21052135 u8 * incoming_addr ;
21062136 bool is_whitelisted ;
21072137
2138+ fprintf (stderr , "INSIDE WHITELIST\n" );
2139+
21082140 if (!fromwire_connectd_alt_addr_whitelist_reply (tmpctx ,
21092141 msg , & p_pk , & incoming_addr , & is_whitelisted )) {
21102142 master_badmsg (WIRE_CONNECTD_ALT_ADDR_WHITELIST_REPLY , msg );
@@ -2220,10 +2252,8 @@ static struct io_plan *recv_req(struct io_conn *conn,
22202252 goto out ;
22212253 }
22222254 case WIRE_CONNECTD_ALT_ADDR_WHITELIST_REPLY :
2223- if (daemon -> developer ) {
2224- handle_alt_addr_whitelist_reply (daemon , msg );
2225- goto out ;
2226- }
2255+ handle_alt_addr_whitelist_reply (daemon , msg );
2256+ goto out ;
22272257 /* Fall thru */
22282258 /* We send these, we don't receive them */
22292259 case WIRE_CONNECTD_INIT_REPLY :
0 commit comments