Skip to content

Commit

Permalink
Process incoming alternative addresses and store them to the CoreLN d…
Browse files Browse the repository at this point in the history
…atabase

Signed-off-by: Max Rantil <[email protected]>
  • Loading branch information
maxrantil committed Jun 18, 2024
1 parent 44315f2 commit b1b9a49
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 352 deletions.
65 changes: 19 additions & 46 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct peer {
bool channel_ready[NUM_SIDES];
u64 next_index[NUM_SIDES];

/* ID of peer */
struct node_id id;

/* --developer? */
bool developer;

Expand Down Expand Up @@ -191,10 +194,13 @@ struct peer {

/* --experimental-upgrade-protocol */
bool experimental_upgrade;

/* Alt address for peer connections not publicly announced */
u8 *alt_addr;
};

static void start_commit_timer(struct peer *peer);
// void send_peer_alt_address(struct peer *peer, const struct pubkey *node_id, const u8 *alt_address);
static void send_peer_alt_address(struct peer *peer);

static void billboard_update(const struct peer *peer)
{
Expand Down Expand Up @@ -536,46 +542,13 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
check_mutual_splice_locked(peer);
}

// void send_peer_alt_address(struct peer *peer, const struct pubkey *node_id, const u8 *alt_address)
// {
// u8 *msg = towire_peer_alt_address(peer, node_id, alt_address);

// peer_write(peer->pps, take(msg));
// fprintf(stderr, "Sent alternative address message to peer");
// }
static void send_peer_alt_address(struct peer *peer) {
struct pubkey node_id;

static void handle_peer_alt_addr(struct peer *peer, const u8 *msg)
{
struct pubkey peer_id;
u8 *alt_addr;
// u32 *timestamp = NULL;
// fprintf(stderr, "Entering handle_peer_alt_eight with msg %s\n", msg);
fprintf(stderr, "1 THIS IS A TEST\n");
status_info("2 THIS IS A TEST");
if (!fromwire_peer_alt_address(tmpctx, msg, &peer_id, &alt_addr/* , timestamp */)) {
master_badmsg(WIRE_PEER_ALT_ADDRESS, msg);
if (pubkey_from_node_id(&node_id, &peer->id)) {
u8 *msg = towire_peer_alt_address(peer, &node_id, peer->alt_addr);
peer_write(peer->pps, take(msg));
}
fprintf(stderr, "3 THIS IS A TEST\n");
status_info("3.5 THIS IS A TEST");
// peer = peer_htable_get(daemon->peers, &id);
// if (!peer)
// return;

// Store the alternative address in the peer structure
// peer->alt_address = alt_addr; // Assuming you have such a field in the struct
// log_info(peer->log, "Received alt address: %s", alt_addr);

// struct peer *peer = peer_htable_get(daemon->peers, &peer_id);
// if (!peer)
// return; // Peer not found

// updating peer information in a database:
// update_peer_address(peer, &alt_addr);

// Optionally, trigger actions that use the new address immediately,
// such as attempting a new connection:
// try_connect_to_peer(peer, &alt_addr);

}

static void handle_peer_channel_ready(struct peer *peer, const u8 *msg)
Expand Down Expand Up @@ -4201,14 +4174,14 @@ static void peer_in(struct peer *peer, const u8 *msg)
{
enum peer_wire type = fromwire_peektype(msg);

// fprintf(stderr, "4 THIS IS A TEST\n");
// status_info("5 THIS IS A TEST %s", msg);

if (handle_peer_error_or_warning(peer->pps, msg))
return;

check_tx_abort(peer, msg);

if (peer->alt_addr)
send_peer_alt_address(peer);

/* If we're in STFU mode and aren't waiting for a STFU mode
* specific message, the only valid message was tx_abort */
if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) {
Expand Down Expand Up @@ -4300,9 +4273,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
case WIRE_SPLICE_LOCKED:
handle_peer_splice_locked(peer, msg);
return;
case WIRE_PEER_ALT_ADDRESS:
handle_peer_alt_addr(peer, msg);
return;
case WIRE_INIT:
case WIRE_OPEN_CHANNEL:
case WIRE_ACCEPT_CHANNEL:
Expand Down Expand Up @@ -4344,6 +4314,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
case WIRE_ONION_MESSAGE:
case WIRE_PEER_STORAGE:
case WIRE_YOUR_PEER_STORAGE:
case WIRE_PEER_ALT_ADDRESS:
abort();
}

Expand Down Expand Up @@ -5918,7 +5889,9 @@ static void init_channel(struct peer *peer)
&reestablish_only,
&peer->experimental_upgrade,
&peer->splice_state->inflights,
&peer->local_alias)) {
&peer->local_alias,
&peer->alt_addr,
&peer->id)) {
master_badmsg(WIRE_CHANNELD_INIT, msg);
}

Expand Down
1 change: 0 additions & 1 deletion channeld/channeld.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
#include <ccan/tal/tal.h>

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

#endif /* LIGHTNING_CHANNELD_CHANNELD_H */
3 changes: 3 additions & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ msgdata,channeld_init,experimental_upgrade,bool,
msgdata,channeld_init,num_inflights,u16,
msgdata,channeld_init,inflights,inflight,num_inflights
msgdata,channeld_init,scid_alias,short_channel_id,
msgdata,channeld_init,alt_addr_len,u16,
msgdata,channeld_init,alt_addr,u8,alt_addr_len,
msgdata,channeld_init,id,node_id,

# channeld->lightningd: successfully negotated reestablishment.
msgtype,channeld_reestablished,1101
Expand Down
1 change: 0 additions & 1 deletion common/wireaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ bool wireaddr_eq_without_port(const struct wireaddr *a, const struct wireaddr *b
* announce */
enum addr_listen_announce {
ADDR_LISTEN = (1 << 0),
ALT_ADDR_LISTEN = (2 << 0),
ADDR_ANNOUNCE = (1 << 1),
ADDR_LISTEN_AND_ANNOUNCE = ADDR_LISTEN|ADDR_ANNOUNCE
};
Expand Down
Loading

0 comments on commit b1b9a49

Please sign in to comment.