Skip to content

Commit b013b3a

Browse files
rustyrussellcdecker
authored andcommitted
patch websocket-address-support.patch
1 parent 81b2092 commit b013b3a

File tree

10 files changed

+139
-35
lines changed

10 files changed

+139
-35
lines changed

common/json_helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ void json_add_address(struct json_stream *response, const char *fieldname,
281281
json_add_string(response, "type", "torv3");
282282
json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr));
283283
json_add_num(response, "port", addr->port);
284+
} else if (addr->type == ADDR_TYPE_WEBSOCKET) {
285+
json_add_string(response, "type", "websocket");
286+
json_add_num(response, "port", addr->port);
284287
}
285288
json_object_end(response);
286289
}

common/wireaddr.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr)
3737
case ADDR_TYPE_TOR_V3:
3838
addr->addrlen = TOR_V3_ADDRLEN;
3939
break;
40+
case ADDR_TYPE_WEBSOCKET:
41+
addr->addrlen = 0;
42+
break;
4043
default:
4144
return false;
4245
}
@@ -160,6 +163,14 @@ void wireaddr_from_ipv6(struct wireaddr *addr,
160163
memcpy(&addr->addr, ip6, addr->addrlen);
161164
}
162165

166+
void wireaddr_from_websocket(struct wireaddr *addr, const u16 port)
167+
{
168+
addr->type = ADDR_TYPE_WEBSOCKET;
169+
addr->addrlen = 0;
170+
addr->port = port;
171+
memset(addr->addr, 0, sizeof(addr->addr));
172+
}
173+
163174
bool wireaddr_to_ipv4(const struct wireaddr *addr, struct sockaddr_in *s4)
164175
{
165176
if (addr->type != ADDR_TYPE_IPV4)
@@ -184,6 +195,14 @@ bool wireaddr_to_ipv6(const struct wireaddr *addr, struct sockaddr_in6 *s6)
184195
return true;
185196
}
186197

198+
bool wireaddr_to_websocket(const struct wireaddr *addr, u16 *port)
199+
{
200+
if (addr->type != ADDR_TYPE_WEBSOCKET)
201+
return false;
202+
*port = addr->port;
203+
return true;
204+
}
205+
187206
bool wireaddr_is_wildcard(const struct wireaddr *addr)
188207
{
189208
switch (addr->type) {
@@ -192,6 +211,7 @@ bool wireaddr_is_wildcard(const struct wireaddr *addr)
192211
return memeqzero(addr->addr, addr->addrlen);
193212
case ADDR_TYPE_TOR_V2:
194213
case ADDR_TYPE_TOR_V3:
214+
case ADDR_TYPE_WEBSOCKET:
195215
return false;
196216
}
197217
abort();
@@ -239,6 +259,8 @@ char *fmt_wireaddr_without_port(const tal_t * ctx, const struct wireaddr *a)
239259
case ADDR_TYPE_TOR_V3:
240260
return tal_fmt(ctx, "%s.onion",
241261
b32_encode(tmpctx, a->addr, a->addrlen));
262+
case ADDR_TYPE_WEBSOCKET:
263+
return tal_strdup(ctx, "websocket");
242264
}
243265

244266
hex = tal_hexstr(ctx, a->addr, a->addrlen);
@@ -675,6 +697,7 @@ struct addrinfo *wireaddr_to_addrinfo(const tal_t *ctx,
675697
return ai;
676698
case ADDR_TYPE_TOR_V2:
677699
case ADDR_TYPE_TOR_V3:
700+
case ADDR_TYPE_WEBSOCKET:
678701
break;
679702
}
680703
abort();
@@ -729,6 +752,7 @@ bool all_tor_addresses(const struct wireaddr_internal *wireaddr)
729752
return false;
730753
case ADDR_TYPE_TOR_V2:
731754
case ADDR_TYPE_TOR_V3:
755+
case ADDR_TYPE_WEBSOCKET:
732756
continue;
733757
}
734758
}

common/wireaddr.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct sockaddr_un;
3737
* where `checksum = sha3(".onion checksum" | pubkey || version)[:2]`
3838
*/
3939

40+
/* BOLT-websockets #7:
41+
* * `5`: WebSocket port; data = `[2:port]` (length 2)
42+
*/
43+
4044
#define TOR_V2_ADDRLEN 10
4145
#define TOR_V3_ADDRLEN 35
4246
#define LARGEST_ADDRLEN TOR_V3_ADDRLEN
@@ -47,7 +51,8 @@ enum wire_addr_type {
4751
ADDR_TYPE_IPV4 = 1,
4852
ADDR_TYPE_IPV6 = 2,
4953
ADDR_TYPE_TOR_V2 = 3,
50-
ADDR_TYPE_TOR_V3 = 4
54+
ADDR_TYPE_TOR_V3 = 4,
55+
ADDR_TYPE_WEBSOCKET = 5,
5156
};
5257

5358
/* Structure now fit for tor support */
@@ -98,8 +103,10 @@ void wireaddr_from_ipv4(struct wireaddr *addr,
98103
void wireaddr_from_ipv6(struct wireaddr *addr,
99104
const struct in6_addr *ip6,
100105
const u16 port);
106+
void wireaddr_from_websocket(struct wireaddr *addr, const u16 port);
101107
bool wireaddr_to_ipv4(const struct wireaddr *addr, struct sockaddr_in *s4);
102108
bool wireaddr_to_ipv6(const struct wireaddr *addr, struct sockaddr_in6 *s6);
109+
bool wireaddr_to_websocket(const struct wireaddr *addr, u16 *port);
103110

104111
bool wireaddr_is_wildcard(const struct wireaddr *addr);
105112

connectd/connectd.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -835,36 +835,41 @@ static void try_connect_one_addr(struct connecting *connect)
835835
case ADDR_TYPE_IPV6:
836836
af = AF_INET6;
837837
break;
838+
case ADDR_TYPE_WEBSOCKET:
839+
af = -1;
840+
break;
838841
}
839842
}
840843

841844
/* If we have to use proxy but we don't have one, we fail. */
842845
if (use_proxy) {
843846
if (!connect->daemon->proxyaddr) {
844-
status_debug("Need proxy");
845-
af = -1;
846-
} else
847-
af = connect->daemon->proxyaddr->ai_family;
847+
tal_append_fmt(&connect->errors,
848+
"%s: need a proxy. ",
849+
type_to_string(tmpctx,
850+
struct wireaddr_internal,
851+
addr));
852+
goto next;
853+
}
854+
af = connect->daemon->proxyaddr->ai_family;
848855
}
849856

850857
if (af == -1) {
851-
fd = -1;
852-
errno = EPROTONOSUPPORT;
853-
} else
854-
fd = socket(af, SOCK_STREAM, 0);
858+
tal_append_fmt(&connect->errors,
859+
"%s: not supported. ",
860+
type_to_string(tmpctx, struct wireaddr_internal,
861+
addr));
862+
goto next;
863+
}
855864

856-
/* We might not have eg. IPv6 support, or it might be an onion addr
857-
* and we have no proxy. */
865+
fd = socket(af, SOCK_STREAM, 0);
858866
if (fd < 0) {
859867
tal_append_fmt(&connect->errors,
860868
"%s: opening %i socket gave %s. ",
861869
type_to_string(tmpctx, struct wireaddr_internal,
862870
addr),
863871
af, strerror(errno));
864-
/* This causes very limited recursion. */
865-
connect->addrnum++;
866-
try_connect_one_addr(connect);
867-
return;
872+
goto next;
868873
}
869874

870875
/* This creates the new connection using our fd, with the initialization
@@ -878,6 +883,13 @@ static void try_connect_one_addr(struct connecting *connect)
878883
* that frees connect. */
879884
if (conn)
880885
connect->conn = conn;
886+
887+
return;
888+
889+
next:
890+
/* This causes very limited recursion. */
891+
connect->addrnum++;
892+
try_connect_one_addr(connect);
881893
}
882894

883895
/*~ connectd is responsible for incoming connections, but it's the process of
@@ -988,6 +1000,8 @@ static bool handle_wireaddr_listen(struct daemon *daemon,
9881000
return true;
9891001
}
9901002
return false;
1003+
/* Handle specially by callers. */
1004+
case ADDR_TYPE_WEBSOCKET:
9911005
case ADDR_TYPE_TOR_V2:
9921006
case ADDR_TYPE_TOR_V3:
9931007
break;

connectd/netaddress.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ bool guess_address(struct wireaddr *addr)
258258
}
259259
case ADDR_TYPE_TOR_V2:
260260
case ADDR_TYPE_TOR_V3:
261+
case ADDR_TYPE_WEBSOCKET:
261262
status_broken("Cannot guess address type %u", addr->type);
262263
break;
263264
}

devtools/gossipwith.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ int main(int argc, char *argv[])
321321
case ADDR_TYPE_TOR_V3:
322322
opt_usage_exit_fail("Don't support proxy use");
323323
break;
324+
case ADDR_TYPE_WEBSOCKET:
325+
opt_usage_exit_fail("Don't support websockets");
326+
break;
324327
case ADDR_TYPE_IPV4:
325328
af = AF_INET;
326329
break;

doc/lightning-getinfo.7.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ On success, an object is returned, containing:
4040
- **network** (string): represents the type of network on the node are working (e.g: `bitcoin`, `testnet`, or `regtest`)
4141
- **fees_collected_msat** (msat): Total routing fees collected by this node
4242
- **address** (array of objects, optional): The addresses we announce to the world:
43-
- **type** (string): Type of connection (one of "ipv4", "ipv6", "torv2", "torv3")
44-
- **address** (string): address in expected format for **type**
43+
- **type** (string): Type of connection (one of "ipv4", "ipv6", "torv2", "torv3", "websocket")
4544
- **port** (u16): port number
45+
46+
If **type** is "ipv4", "ipv6", "torv2" or "torv3":
47+
- **address** (string): address in expected format for **type**
4648
- **binding** (array of objects, optional): The addresses we are listening on:
4749
- **type** (string): Type of connection (one of "local socket", "ipv4", "ipv6", "torv2", "torv3")
4850
- **address** (string, optional): address in expected format for **type**
@@ -115,4 +117,4 @@ RESOURCES
115117
---------
116118

117119
Main web site: <https://github.com/ElementsProject/lightning>
118-
[comment]: # ( SHA256STAMP:a41fb9bb8e6e61bec105ff250584ae019dda93d4f97bfff53bc86d57ab6e8607)
120+
[comment]: # ( SHA256STAMP:50c41a77a5f440cc22e5df9e3748e4280cd4508469887382690c580f10bc5af4)

doc/lightning-listnodes.7.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ If **last_timestamp** is present:
3636
- **color** (hex): The favorite RGB color this node advertized (always 6 characters)
3737
- **features** (hex): BOLT #9 features bitmap this node advertized
3838
- **addresses** (array of objects): The addresses this node advertized:
39-
- **type** (string): Type of connection (one of "ipv4", "ipv6", "torv2", "torv3")
40-
- **address** (string): address in expected format for *type*
39+
- **type** (string): Type of connection (one of "ipv4", "ipv6", "torv2", "torv3", "websocket")
4140
- **port** (u16): port number
4241

42+
If **type** is "ipv4", "ipv6", "torv2" or "torv3":
43+
- **address** (string): address in expected format for **type**
44+
4345
If **option_will_fund** is present:
4446
- **option_will_fund** (object):
4547
- **lease_fee_base_msat** (msat): the fixed fee for a lease (whole number of satoshis)
@@ -93,4 +95,4 @@ RESOURCES
9395
---------
9496

9597
Main web site: <https://github.com/ElementsProject/lightning>
96-
[comment]: # ( SHA256STAMP:158477348efb51a8cf71a595b3d76dde545ab6824958c8a32d4b3dbbbe2c8121)
98+
[comment]: # ( SHA256STAMP:f9e1f4655b416c5e60279cf11a832bc4c652f503e48095dc3cf39deee5f0c769)

doc/schemas/getinfo.schema.json

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,46 @@
6464
"description": "The addresses we announce to the world",
6565
"items": {
6666
"type": "object",
67-
"required": [ "type", "address", "port" ],
68-
"additionalProperties": false,
67+
"required": [ "type", "port" ],
68+
"additionalProperties": true,
6969
"properties": {
7070
"type": {
7171
"type": "string",
72-
"enum": [ "ipv4", "ipv6", "torv2", "torv3" ],
72+
"enum": [ "ipv4", "ipv6", "torv2", "torv3", "websocket" ],
7373
"description": "Type of connection"
7474
},
75-
"address": {
76-
"type": "string",
77-
"description": "address in expected format for **type**"
78-
},
7975
"port": {
8076
"type": "u16",
8177
"description": "port number"
8278
}
79+
},
80+
"if": {
81+
"properties": {
82+
"type": {
83+
"type": "string",
84+
"enum": [ "ipv4", "ipv6", "torv2", "torv3" ]
85+
}
86+
}
87+
},
88+
"then": {
89+
"required": [ "type", "address", "port" ],
90+
"additionalProperties": false,
91+
"properties": {
92+
"type": { },
93+
"port": { },
94+
"address": {
95+
"type": "string",
96+
"description": "address in expected format for **type**"
97+
}
98+
}
99+
},
100+
"else": {
101+
"required": [ "type", "port" ],
102+
"additionalProperties": false,
103+
"properties": {
104+
"type": { },
105+
"port": { }
106+
}
83107
}
84108
}
85109
},

doc/schemas/listnodes.schema.json

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,46 @@
5252
"description": "The addresses this node advertized",
5353
"items": {
5454
"type": "object",
55-
"required": [ "type", "address", "port" ],
56-
"additionalProperties": false,
55+
"required": [ "type", "port" ],
56+
"additionalProperties": true,
5757
"properties": {
5858
"type": {
5959
"type": "string",
60-
"enum": [ "ipv4", "ipv6", "torv2", "torv3" ],
60+
"enum": [ "ipv4", "ipv6", "torv2", "torv3", "websocket" ],
6161
"description": "Type of connection"
6262
},
63-
"address": {
64-
"type": "string",
65-
"description": "address in expected format for *type*"
66-
},
6763
"port": {
6864
"type": "u16",
6965
"description": "port number"
7066
}
67+
},
68+
"if": {
69+
"properties": {
70+
"type": {
71+
"type": "string",
72+
"enum": [ "ipv4", "ipv6", "torv2", "torv3" ]
73+
}
74+
}
75+
},
76+
"then": {
77+
"required": [ "type", "address", "port" ],
78+
"additionalProperties": false,
79+
"properties": {
80+
"type": { },
81+
"port": { },
82+
"address": {
83+
"type": "string",
84+
"description": "address in expected format for **type**"
85+
}
86+
}
87+
},
88+
"else": {
89+
"required": [ "type", "port" ],
90+
"additionalProperties": false,
91+
"properties": {
92+
"type": { },
93+
"port": { }
94+
}
7195
}
7296
}
7397
}

0 commit comments

Comments
 (0)