Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket not experimental, don't advertize, fix address parsing #6173

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"ipv6": 2,
"local socket": 0,
"torv2": 3,
"torv3": 4
"torv3": 4,
"websocket": 5
},
"GetrouteRouteStyle": {
"tlv": 0
Expand Down
3 changes: 1 addition & 2 deletions cln-grpc/proto/node.proto

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

21 changes: 9 additions & 12 deletions cln-rpc/src/model.rs

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

66 changes: 47 additions & 19 deletions common/json_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,38 +493,54 @@ void json_add_short_channel_id(struct json_stream *response,
short_channel_id_outnum(scid));
}

void json_add_address(struct json_stream *response, const char *fieldname,
const struct wireaddr *addr)
static void json_add_address_fields(struct json_stream *response,
const struct wireaddr *addr,
const char *typefield)
{
json_object_start(response, fieldname);
if (addr->type == ADDR_TYPE_IPV4) {
switch (addr->type) {
case ADDR_TYPE_IPV4: {
char addrstr[INET_ADDRSTRLEN];
inet_ntop(AF_INET, addr->addr, addrstr, INET_ADDRSTRLEN);
json_add_string(response, "type", "ipv4");
json_add_string(response, typefield, "ipv4");
json_add_string(response, "address", addrstr);
json_add_num(response, "port", addr->port);
} else if (addr->type == ADDR_TYPE_IPV6) {
return;
}
case ADDR_TYPE_IPV6: {
char addrstr[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, addr->addr, addrstr, INET6_ADDRSTRLEN);
json_add_string(response, "type", "ipv6");
json_add_string(response, typefield, "ipv6");
json_add_string(response, "address", addrstr);
json_add_num(response, "port", addr->port);
} else if (addr->type == ADDR_TYPE_TOR_V2_REMOVED) {
json_add_string(response, "type", "torv2");
return;
}
case ADDR_TYPE_TOR_V2_REMOVED: {
json_add_string(response, typefield, "torv2");
json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr));
json_add_num(response, "port", addr->port);
} else if (addr->type == ADDR_TYPE_TOR_V3) {
json_add_string(response, "type", "torv3");
return;
}
case ADDR_TYPE_TOR_V3: {
json_add_string(response, typefield, "torv3");
json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr));
json_add_num(response, "port", addr->port);
} else if (addr->type == ADDR_TYPE_DNS) {
json_add_string(response, "type", "dns");
return;
}
case ADDR_TYPE_DNS: {
json_add_string(response, typefield, "dns");
json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr));
json_add_num(response, "port", addr->port);
} else if (addr->type == ADDR_TYPE_WEBSOCKET) {
json_add_string(response, "type", "websocket");
json_add_num(response, "port", addr->port);
return;
}
}
abort();
}

void json_add_address(struct json_stream *response, const char *fieldname,
const struct wireaddr *addr)
{
json_object_start(response, fieldname);
json_add_address_fields(response, addr, "type");
json_object_end(response);
}

Expand All @@ -541,8 +557,13 @@ void json_add_address_internal(struct json_stream *response,
return;
case ADDR_INTERNAL_ALLPROTO:
json_object_start(response, fieldname);
json_add_string(response, "type", "any protocol");
json_add_num(response, "port", addr->u.port);
if (addr->u.allproto.is_websocket) {
json_add_string(response, "type", "websocket");
json_add_string(response, "subtype", "any protocol");
} else {
json_add_string(response, "type", "any protocol");
}
json_add_num(response, "port", addr->u.allproto.port);
json_object_end(response);
return;
case ADDR_INTERNAL_AUTOTOR:
Expand All @@ -565,7 +586,14 @@ void json_add_address_internal(struct json_stream *response,
json_object_end(response);
return;
case ADDR_INTERNAL_WIREADDR:
json_add_address(response, fieldname, &addr->u.wireaddr);
json_object_start(response, fieldname);
if (addr->u.wireaddr.is_websocket) {
json_add_string(response, "type", "websocket");
json_add_address_fields(response, &addr->u.wireaddr.wireaddr, "subtype");
} else {
json_add_address_fields(response, &addr->u.wireaddr.wireaddr, "type");
}
json_object_end(response);
return;
}
abort();
Expand Down
4 changes: 3 additions & 1 deletion common/scb_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ subtype,scb_chan
subtypedata,scb_chan,id,u64,
subtypedata,scb_chan,cid,channel_id,
subtypedata,scb_chan,node_id,node_id,
subtypedata,scb_chan,addr,wireaddr_internal,
subtypedata,scb_chan,unused,u8,
subtypedata,scb_chan,addr,wireaddr,
subtypedata,scb_chan,funding,bitcoin_outpoint,
subtypedata,scb_chan,funding_sats,amount_sat,
subtypedata,scb_chan,type,channel_type,

msgtype,static_chan_backup,6135,
msgdata,static_chan_backup,version,u64,
msgdata,static_chan_backup,timestamp,u32,
Expand Down
19 changes: 9 additions & 10 deletions common/test/run-ip_port_parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,37 +196,36 @@ int main(int argc, char *argv[])
assert(!separate_address_and_port(tmpctx, "[::1]:http", &ip, &port));

// localhost hostnames for backward compat
assert(parse_wireaddr("localhost", &addr, 200, false, NULL));
assert(parse_wireaddr(tmpctx, "localhost", 200, false, &addr) == NULL);
assert(addr.port == 200);

// string should win the port battle
assert(parse_wireaddr("[::1]:9735", &addr, 500, false, NULL));
assert(parse_wireaddr(tmpctx, "[::1]:9735", 500, false, &addr) == NULL);
assert(addr.port == 9735);
ip = fmt_wireaddr(tmpctx, &addr);
assert(streq(ip, "[::1]:9735"));

// should use argument if we have no port in string
assert(parse_wireaddr("2001:db8:85a3::8a2e:370:7334", &addr, 9777, false, NULL));
assert(parse_wireaddr(tmpctx, "2001:db8:85a3::8a2e:370:7334", 9777, false, &addr) == NULL);
assert(addr.port == 9777);

ip = fmt_wireaddr(tmpctx, &addr);
assert(streq(ip, "[2001:db8:85a3::8a2e:370:7334]:9777"));

assert(parse_wireaddr("[::ffff:127.0.0.1]:49150", &addr, 1, false, NULL));
assert(parse_wireaddr(tmpctx, "[::ffff:127.0.0.1]:49150", 1, false, &addr) == NULL);
assert(addr.port == 49150);

assert(parse_wireaddr("4ruvswpqec5i2gogopxl4vm5bruzknbvbylov2awbo4rxiq4cimdldad.onion:49150", &addr, 1, false, NULL));
assert(parse_wireaddr(tmpctx, "4ruvswpqec5i2gogopxl4vm5bruzknbvbylov2awbo4rxiq4cimdldad.onion:49150", 1, false, &addr) == NULL);
assert(addr.port == 49150);

assert(parse_wireaddr("4ruvswpqec5i2gogopxl4vm5bruzknbvbylov2awbo4rxiq4cimdldad.onion", &addr, 1, false, NULL));
assert(parse_wireaddr(tmpctx, "4ruvswpqec5i2gogopxl4vm5bruzknbvbylov2awbo4rxiq4cimdldad.onion", 1, false, &addr) == NULL);
assert(addr.port == 1);

/* We don't accept torv2 any more */
assert(!parse_wireaddr("odpzvneidqdf5hdq.onion:49150", &addr, 1, false, NULL));
assert(!parse_wireaddr("odpzvneidqdf5hdq.onion", &addr, 1, false, NULL));
assert(parse_wireaddr(tmpctx, "odpzvneidqdf5hdq.onion:49150", 1, false, &addr) != NULL);
assert(parse_wireaddr(tmpctx, "odpzvneidqdf5hdq.onion", 1, false, &addr) != NULL);

assert(!parse_wireaddr_internal("odpzvneidqdf5hdq.onion", &addr_int, 1,
false, false, false, NULL));
assert(parse_wireaddr_internal(tmpctx, "odpzvneidqdf5hdq.onion", 1, false, &addr_int) != NULL);

assert(wireaddr_from_hostname(tmpctx, "odpzvneidqdf5hdq.onion", 1, NULL, NULL, NULL) == NULL);
assert(wireaddr_from_hostname(tmpctx, "aaa.onion", 1, NULL, NULL, NULL) == NULL);
Expand Down
Loading