Skip to content
31 changes: 31 additions & 0 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,17 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
check_mutual_splice_locked(peer);
}

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

/* We need the addrs in my own db too for later whitelist confirmation */
u8 *msg = towire_channeld_my_alt_addr(tmpctx, peer->my_alt_addr);
wire_sync_write(MASTER_FD, take(msg));
}
Comment on lines +548 to +551
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very weird thing for channeld to do. It's more gossipy than channel-related. These days, this kind of thing is handled by connectd.


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

check_tx_abort(peer, msg);

if (peer->my_alt_addr)
send_peer_my_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 @@ -4296,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 @@ -5666,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 *my_alt_addr;

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

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

static void req_in(struct peer *peer, const u8 *msg)
{
enum channeld_wire t = fromwire_peektype(msg);
Expand Down Expand Up @@ -5705,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 @@ -5768,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_MY_ALT_ADDR:
break;
}
master_badmsg(-1, msg);
Expand Down
10 changes: 10 additions & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -350,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_my_alt_addr,1037
msgdata,channeld_my_alt_addr,alt_addr_len,u16,
msgdata,channeld_my_alt_addr,alt_addr,u8,alt_addr_len,
1 change: 1 addition & 0 deletions common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,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
14 changes: 14 additions & 0 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <wire/peer_wiregen.h>
#include <wire/wire_io.h>
#include <wire/wire_sync.h>

Expand Down Expand Up @@ -518,6 +519,18 @@ static struct io_plan *connection_in(struct io_conn *conn,
return conn_in(conn, &conn_in_arg);
}

void handle_peer_alt_addr_in(struct peer *peer, const u8 *msg)
{
u8 *p_alt_addr;

if (!fromwire_peer_alt_addr(peer, msg, &p_alt_addr))
master_badmsg(WIRE_PEER_ALT_ADDR, msg);

u8 *fwd_msg = towire_connectd_peer_alt_addr(tmpctx, &peer->id, p_alt_addr);
daemon_conn_send(peer->daemon->master, take(fwd_msg));
tal_free(p_alt_addr);
}

/*~ <hello>I speak web socket</hello>.
*
* Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */
Expand Down Expand Up @@ -2249,6 +2262,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_CONNECTD_PEER_DISCONNECT_DONE:
case WIRE_CONNECTD_START_SHUTDOWN_REPLY:
case WIRE_CONNECTD_INJECT_ONIONMSG_REPLY:
case WIRE_CONNECTD_PEER_ALT_ADDR:
break;
}

Expand Down
3 changes: 3 additions & 0 deletions connectd/connectd.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ void update_recent_timestamp(struct daemon *daemon, struct gossmap *gossmap);
/* add erros to error list */
void add_errors_to_error_list(struct connecting *connect, const char *error);

/* Handles alternative address message from peer. */
void handle_peer_alt_addr_in(struct peer *peer, const u8 *msg);

/* Called by peer_exchange_initmsg if successful. */
struct io_plan *peer_connected(struct io_conn *conn,
struct daemon *daemon,
Expand Down
6 changes: 6 additions & 0 deletions connectd/connectd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,9 @@ msgtype,connectd_dev_exhaust_fds,2036
# master -> connect: set artificial maximum reply_channel_range size.
msgtype,connectd_dev_set_max_scids_encode_size,2035
msgdata,connectd_dev_set_max_scids_encode_size,max,u32,

# connectd -> master: incoming alternative connection address from peer
msgtype,connectd_peer_alt_addr,2037
msgdata,connectd_peer_alt_addr,id,node_id,
msgdata,connectd_peer_alt_addr,addr_len,u8,
msgdata,connectd_peer_alt_addr,addr,byte,addr_len,
1 change: 1 addition & 0 deletions connectd/gossip_rcvd_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static bool is_msg_gossip_broadcast(const u8 *cursor)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
break;
}
return false;
Expand Down
1 change: 1 addition & 0 deletions connectd/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static bool public_msg_type(enum peer_wire type)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
return false;
case WIRE_CHANNEL_ANNOUNCEMENT:
case WIRE_NODE_ANNOUNCEMENT:
Expand Down
4 changes: 4 additions & 0 deletions connectd/multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ static bool is_urgent(enum peer_wire type)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
return false;

/* These are time-sensitive, and so send without delay. */
Expand Down Expand Up @@ -754,6 +755,9 @@ static bool handle_message_locally(struct peer *peer, const u8 *msg)
} else if (type == WIRE_QUERY_SHORT_CHANNEL_IDS) {
handle_query_short_channel_ids(peer, msg);
return true;
} else if (type == WIRE_PEER_ALT_ADDR) {
handle_peer_alt_addr_in(peer, msg);
return true;
} else if (handle_custommsg(peer->daemon, peer, msg)) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ static void handle_recv_gossip(struct daemon *daemon, const u8 *outermsg)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
break;
}

Expand Down
19 changes: 19 additions & 0 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,21 @@ static void handle_local_anchors(struct channel *channel, const u8 *msg)
}
}

static void handle_channeld_my_alt_addr(struct lightningd *ld, struct channel *channel,
const u8 *msg)
{
u8 *my_alt_addr;

if (!fromwire_channeld_my_alt_addr(tmpctx, msg, &my_alt_addr)) {
channel_internal_error(channel,
"bad channeld_my_alt_addr %s",
tal_hex(channel, msg));
return;
}

tal_free(my_alt_addr);
}

static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
{
enum channeld_wire t = fromwire_peektype(msg);
Expand Down Expand Up @@ -1500,6 +1515,9 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
case WIRE_CHANNELD_UPGRADED:
handle_channel_upgrade(sd->channel, msg);
break;
case WIRE_CHANNELD_MY_ALT_ADDR:
handle_channeld_my_alt_addr(sd->ld, sd->channel, msg);
break;
/* And we never get these from channeld. */
case WIRE_CHANNELD_INIT:
case WIRE_CHANNELD_FUNDING_DEPTH:
Expand All @@ -1516,6 +1534,7 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
case WIRE_CHANNELD_DEV_MEMLEAK:
case WIRE_CHANNELD_DEV_QUIESCE:
case WIRE_CHANNELD_GOT_INFLIGHT:
case WIRE_CHANNELD_PEER_ALT_ADDR:
/* Replies go to requests. */
case WIRE_CHANNELD_OFFER_HTLC_REPLY:
case WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY:
Expand Down
18 changes: 18 additions & 0 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,21 @@ static void handle_custommsg_in(struct lightningd *ld, const u8 *msg)
plugin_hook_call_custommsg(ld, NULL, p);
}

static void handle_peer_alt_addr(struct lightningd *ld, const u8 *msg)
{
struct node_id p_id;
u8 *p_alt_addr;

if (!fromwire_connectd_peer_alt_addr(tmpctx, msg, &p_id, &p_alt_addr)) {
log_broken(ld->log,
"handle_alt_addr_in: Malformed alt_addr message: %s",
tal_hex(tmpctx, msg));
return;
}

tal_free(p_alt_addr);
}

static void connectd_start_shutdown_reply(struct subd *connectd,
const u8 *reply,
const int *fds UNUSED,
Expand Down Expand Up @@ -646,6 +661,9 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
case WIRE_CONNECTD_CUSTOMMSG_IN:
handle_custommsg_in(connectd->ld, msg);
break;
case WIRE_CONNECTD_PEER_ALT_ADDR:
handle_peer_alt_addr(connectd->ld, msg);
break;
}
return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions openingd/dualopend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
break;
}

Expand Down Expand Up @@ -2079,6 +2080,7 @@ static bool run_tx_interactive(struct state *state,
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
open_abort(state, "Unexpected wire message %s",
tal_hex(tmpctx, msg));
return false;
Expand Down Expand Up @@ -4262,6 +4264,7 @@ static u8 *handle_peer_in(struct state *state)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
break;
}

Expand Down
3 changes: 3 additions & 0 deletions wire/peer_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static bool unknown_type(enum peer_wire t)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
return false;
}
return true;
Expand Down Expand Up @@ -110,6 +111,7 @@ bool is_msg_for_gossipd(const u8 *cursor)
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
case WIRE_PEER_ALT_ADDR:
break;
}
return false;
Expand Down Expand Up @@ -162,6 +164,7 @@ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
case WIRE_ONION_MESSAGE:
case WIRE_PEER_STORAGE:
case WIRE_YOUR_PEER_STORAGE:
case WIRE_PEER_ALT_ADDR:
return false;

/* Special cases: */
Expand Down
5 changes: 4 additions & 1 deletion wire/peer_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,7 @@ msgdata,gossip_timestamp_filter,timestamp_range,u32,
msgtype,onion_message,513,option_onion_messages
msgdata,onion_message,blinding,point,
msgdata,onion_message,len,u16,
msgdata,onion_message,onionmsg,byte,len
msgdata,onion_message,onionmsg,byte,len,
msgtype,peer_alt_addr,209
msgdata,peer_alt_addr,addr_len,u8,
msgdata,peer_alt_addr,addr,byte,addr_len,
Comment on lines +394 to +396
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a spec change! This means:

  1. It needs an associated assignment for a BOLT PR.
  2. Meanwhile it should use 32768+ as that's the experimental range.
  3. We should probably mark it experimental in the mean time.

Also, this file is generated from the spec, rather than hand-edited.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding the BOLT PR, after discussions with other devs here we came to the conclusion for a blip-0043 instead of a BOLT.