Skip to content

Commit

Permalink
channeld: introduce support for alternative addresses for peer connec…
Browse files Browse the repository at this point in the history
…tions

- Enhanced peer connection handling to use alternative addresses for selective private communications.
- Updated channeld, connectd, gossipd, and other components to support and process alternative addresses.
- Added database fields to store alternative addresses for peers.
- Implemented new RPC commands for managing alternative addresses.
- Added tests to verify the behavior of alternative address handling in different scenarios.

Changelog-Added: Added new configuration parameters alt-addr, alt-bind-addr, and alt-announce-addr for managing alternative addresses for peer connections.

Signed-off-by: Max Rantil <[email protected]>
  • Loading branch information
maxrantil committed Jul 22, 2024
1 parent 89ede8a commit e7f303f
Show file tree
Hide file tree
Showing 36 changed files with 1,942 additions and 948 deletions.
56 changes: 56 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,9 @@
"ListConfigs.configs.addr": 47,
"ListConfigs.configs.alias": 30,
"ListConfigs.configs.allow-deprecated-apis": 14,
"ListConfigs.configs.alt-addr": 71,
"ListConfigs.configs.alt-announce-addr": 73,
"ListConfigs.configs.alt-bind-addr": 72,
"ListConfigs.configs.always-use-proxy": 17,
"ListConfigs.configs.announce-addr": 48,
"ListConfigs.configs.announce-addr-discovered": 54,
Expand Down Expand Up @@ -1672,6 +1675,18 @@
"ListConfigs.configs.allow-deprecated-apis.source": 2,
"ListConfigs.configs.allow-deprecated-apis.value_bool": 1
},
"ListconfigsConfigsAlt-addr": {
"ListConfigs.configs.alt-addr.sources[]": 2,
"ListConfigs.configs.alt-addr.values_str[]": 1
},
"ListconfigsConfigsAlt-announce-addr": {
"ListConfigs.configs.alt-addr.sources[]": 2,
"ListConfigs.configs.alt-addr.values_str[]": 1
},
"ListconfigsConfigsAlt-bind-addr": {
"ListConfigs.configs.alt-addr.sources[]": 2,
"ListConfigs.configs.alt-addr.values_str[]": 1
},
"ListconfigsConfigsAlways-use-proxy": {
"ListConfigs.configs.always-use-proxy.source": 2,
"ListConfigs.configs.always-use-proxy.value_bool": 1
Expand Down Expand Up @@ -2362,6 +2377,7 @@
"ListPeerChannels.channels[]": 1
},
"ListpeersPeers": {
"ListPeers.peers[].alt_addrs[]": 9,
"ListPeers.peers[].channels[]": 4,
"ListPeers.peers[].connected": 2,
"ListPeers.peers[].features": 6,
Expand Down Expand Up @@ -6681,6 +6697,42 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"ListConfigs.configs.alt-addr": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-addr.sources[]": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-addr.values_str[]": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-announce-addr": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-announce-addr.sources[]": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-announce-addr.values_str[]": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-bind-addr": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-bind-addr.sources[]": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.alt-bind-addr.values_str[]": {
"added": "v24.08",
"deprecated": false
},
"ListConfigs.configs.always-use-proxy": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down Expand Up @@ -8753,6 +8805,10 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"ListPeers.peers[].alt_addrs[]": {
"added": "v24.08",
"deprecated": false
},
"ListPeers.peers[].channels[]": {
"added": "pre-v0.10.1",
"deprecated": "v23.02"
Expand Down
41 changes: 40 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 @@ -189,6 +192,9 @@ struct peer {

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

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

static void start_commit_timer(struct peer *peer);
Expand Down Expand Up @@ -533,6 +539,17 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
check_mutual_splice_locked(peer);
}

static void send_peer_our_alt_addr(struct peer *peer)
{
/* Send our alt addr to peer db */
u8 *peer_msg = towire_peer_alt_addr(peer, peer->our_alt_addr);
peer_write(peer->pps, take(peer_msg));

/* We need the addrs in our own db too for later whitelist confirmation */
u8 *msg = towire_channeld_our_alt_addr(tmpctx, peer->our_alt_addr);
wire_sync_write(MASTER_FD, take(msg));
}

static void handle_peer_channel_ready(struct peer *peer, const u8 *msg)
{
struct channel_id chanid;
Expand Down Expand Up @@ -4158,6 +4175,9 @@ static void peer_in(struct peer *peer, const u8 *msg)

check_tx_abort(peer, msg);

if (peer->our_alt_addr)
send_peer_our_alt_addr(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 @@ -4290,6 +4310,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_ADDR:
abort();
}

Expand Down Expand Up @@ -5660,6 +5681,18 @@ static void handle_dev_quiesce(struct peer *peer, const u8 *msg)
maybe_send_stfu(peer);
}

static void handle_channeld_peer_alt_addr(struct peer *peer, const u8 *msg)
{
u8 *our_alt_addr;

if (!fromwire_channeld_peer_alt_addr(peer, msg, &our_alt_addr))
master_badmsg(WIRE_CHANNELD_PEER_ALT_ADDR, msg);

u8 *peer_msg = towire_peer_alt_addr(peer, our_alt_addr);
peer_write(peer->pps, take(peer_msg));
tal_free(our_alt_addr);
}

static void req_in(struct peer *peer, const u8 *msg)
{
enum channeld_wire t = fromwire_peektype(msg);
Expand Down Expand Up @@ -5699,6 +5732,9 @@ static void req_in(struct peer *peer, const u8 *msg)
case WIRE_CHANNELD_SEND_ERROR:
handle_send_error(peer, msg);
return;
case WIRE_CHANNELD_PEER_ALT_ADDR:
handle_channeld_peer_alt_addr(peer, msg);
return;
case WIRE_CHANNELD_SPLICE_INIT:
handle_splice_init(peer, msg);
return;
Expand Down Expand Up @@ -5762,6 +5798,7 @@ static void req_in(struct peer *peer, const u8 *msg)
case WIRE_CHANNELD_SPLICE_STATE_ERROR:
case WIRE_CHANNELD_LOCAL_ANCHOR_INFO:
case WIRE_CHANNELD_REESTABLISHED:
case WIRE_CHANNELD_OUR_ALT_ADDR:
break;
}
master_badmsg(-1, msg);
Expand Down Expand Up @@ -5847,7 +5884,9 @@ static void init_channel(struct peer *peer)
&reestablish_only,
&peer->experimental_upgrade,
&peer->splice_state->inflights,
&peer->local_alias)) {
&peer->local_alias,
&peer->our_alt_addr,
&peer->id)) {
master_badmsg(WIRE_CHANNELD_INIT, msg);
}

Expand Down
13 changes: 13 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 Expand Up @@ -347,3 +350,13 @@ msgdata,channeld_upgraded,new_type,channel_type,
# Tell peer about our latest and greatest blockheight.
msgtype,channeld_blockheight,1012
msgdata,channeld_blockheight,blockheight,u32,

# master -> channeld: send peer our alternative addresses
msgtype,channeld_peer_alt_addr,1035
msgdata,channeld_peer_alt_addr,alt_addr_len,u16,
msgdata,channeld_peer_alt_addr,alt_addr,u8,alt_addr_len,

# channeld -> master: send our alternative addresses to our db
msgtype,channeld_our_alt_addr,1037
msgdata,channeld_our_alt_addr,alt_addr_len,u16,
msgdata,channeld_our_alt_addr,alt_addr,u8,alt_addr_len,
7 changes: 7 additions & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,7 @@ const void *gossmap_stream_next(const tal_t *ctx,
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
case WIRE_ONION_MESSAGE:
case WIRE_PEER_ALT_ADDR:
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions common/interactivetx.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ static u8 *read_next_msg(const tal_t *ctx,
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
*error = tal_fmt(ctx,
"Received invalid message from peer: %d", t);
return NULL;
Expand Down Expand Up @@ -736,6 +737,7 @@ char *process_interactivetx_updates(const tal_t *ctx,
case WIRE_SPLICE_ACK:
case WIRE_STFU:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
return tal_fmt(ctx, "Unexpected wire message %s",
tal_hex(ctx, msg));
}
Expand Down
Loading

0 comments on commit e7f303f

Please sign in to comment.