Skip to content

Commit 3851ac6

Browse files
committed
lightningd: Update 'listpeers' command to print alt-addrs for a peer
1 parent 70e03ac commit 3851ac6

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

contrib/msggen/msggen/schema.json

+22
Original file line numberDiff line numberDiff line change
@@ -4080,6 +4080,9 @@
40804080
"netaddr": [
40814081
"127.0.0.1:40119"
40824082
],
4083+
"alt_addrs": [
4084+
"127.0.0.1:34321"
4085+
],
40834086
"features": "08a0000a8a5961",
40844087
"log": [
40854088
{
@@ -21424,6 +21427,19 @@
2142421427
]
2142521428
}
2142621429
},
21430+
"alt_addrs": {
21431+
"type": "array",
21432+
"description": [
21433+
"An array containing zero or more alternative addresses for the peer."
21434+
],
21435+
"items": {
21436+
"type": "string",
21437+
"description": [
21438+
"Address, e.g. 1.2.3.4:1234."
21439+
]
21440+
},
21441+
"added": "v24.08"
21442+
},
2142721443
"remote_addr": {
2142821444
"type": "string",
2142921445
"description": [
@@ -21480,6 +21496,9 @@
2148021496
"netaddr": [
2148121497
"127.0.0.1:44619"
2148221498
],
21499+
"alt_addrs": [
21500+
"127.0.0.1:34321"
21501+
],
2148321502
"features": "08a0000a0a69a2"
2148421503
}
2148521504
]
@@ -21500,6 +21519,9 @@
2150021519
"netaddr": [
2150121520
"127.0.0.1:48862"
2150221521
],
21522+
"alt_addrs": [
21523+
"127.0.0.1:34321"
21524+
],
2150321525
"features": "08a0000a0a69a2"
2150421526
}
2150521527
]

doc/schemas/lightning-commando.json

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
"netaddr": [
148148
"127.0.0.1:40119"
149149
],
150+
"alt_addrs": [
151+
"127.0.0.1:34321"
152+
],
150153
"features": "08a0000a8a5961",
151154
"log": [
152155
{

doc/schemas/lightning-listpeers.json

+19
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@
282282
]
283283
}
284284
},
285+
"alt_addrs": {
286+
"type": "array",
287+
"description": [
288+
"An array containing zero or more alternative addresses for the peer."
289+
],
290+
"items": {
291+
"type": "string",
292+
"description": [
293+
"Address, e.g. 1.2.3.4:1234."
294+
]
295+
},
296+
"added": "v24.08"
297+
},
285298
"remote_addr": {
286299
"type": "string",
287300
"description": [
@@ -338,6 +351,9 @@
338351
"netaddr": [
339352
"127.0.0.1:44619"
340353
],
354+
"alt_addrs": [
355+
"127.0.0.1:34321"
356+
],
341357
"features": "08a0000a0a69a2"
342358
}
343359
]
@@ -358,6 +374,9 @@
358374
"netaddr": [
359375
"127.0.0.1:48862"
360376
],
377+
"alt_addrs": [
378+
"127.0.0.1:34321"
379+
],
361380
"features": "08a0000a0a69a2"
362381
}
363382
]

lightningd/peer_control.c

+10
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,7 @@ static void json_add_peer(struct lightningd *ld,
22362236
const enum log_level *ll)
22372237
{
22382238
struct channel *channel;
2239+
struct wireaddr_internal *peer_alt_addr;
22392240
u32 num_channels;
22402241

22412242
json_object_start(response, NULL);
@@ -2258,6 +2259,15 @@ static void json_add_peer(struct lightningd *ld,
22582259
fmt_wireaddr(response, p->remote_addr));
22592260
}
22602261

2262+
peer_alt_addr = wallet_get_alt_addr(ld->wallet, &p->id, false);
2263+
if (peer_alt_addr) {
2264+
json_array_start(response, "alt_addrs");
2265+
for (size_t i = 0; i < tal_count(peer_alt_addr); i++)
2266+
json_add_string(response, NULL,
2267+
fmt_wireaddr_internal(tmpctx, &peer_alt_addr[i]));
2268+
json_array_end(response);
2269+
}
2270+
22612271
/* Note: If !PEER_CONNECTED, peer may use different features on reconnect */
22622272
json_add_hex_talarr(response, "features", p->their_features);
22632273

tests/test_plugin.py

+7
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,13 @@ def test_sql(node_factory, bitcoind):
37073707
'type': 'string'},
37083708
{'name': 'features',
37093709
'type': 'hex'}]},
3710+
'peers_alt_addrs': {
3711+
'columns': [{'name': 'peer_id',
3712+
'type': 'pubkey'},
3713+
{'name': 'alt_addr',
3714+
'type': 'string'},
3715+
{'name': 'port',
3716+
'type': 'u16'}]},
37103717
'peers_netaddr': {
37113718
'columns': [{'name': 'row',
37123719
'type': 'u64'},

0 commit comments

Comments
 (0)