Skip to content

Commit 361639d

Browse files
committed
Remove OnionV2 parsing support
OnionV2s don't (really) work on Tor anymore anyway, and the field is set for removal in the BOLTs [1]. Sadly because of the way addresses are parsed we have to continue to understand that type 3 addresses are 12 bytes long. Thus, for simplicity we keep the `OnionV2` enum variant around and just make it an opaque 12 bytes, with the documentation updated to note the deprecation. [1] lightning/bolts#940
1 parent ea89286 commit 361639d

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

lightning/src/ln/msgs.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,10 @@ pub enum NetAddress {
394394
port: u16,
395395
},
396396
/// An old-style Tor onion address/port on which the peer is listening.
397-
OnionV2 {
398-
/// The bytes (usually encoded in base32 with ".onion" appended)
399-
addr: [u8; 10],
400-
/// The port on which the node is listening
401-
port: u16,
402-
},
397+
///
398+
/// This field is deprecated and the Tor network generally no longer supports V2 Onion
399+
/// addresses. Thus, the details are not parsed here.
400+
OnionV2([u8; 12]),
403401
/// A new-style Tor onion address/port on which the peer is listening.
404402
/// To create the human-readable "hostname", concatenate ed25519_pubkey, checksum, and version,
405403
/// wrap as base32 and append ".onion".
@@ -421,7 +419,7 @@ impl NetAddress {
421419
match self {
422420
&NetAddress::IPv4 {..} => { 1 },
423421
&NetAddress::IPv6 {..} => { 2 },
424-
&NetAddress::OnionV2 {..} => { 3 },
422+
&NetAddress::OnionV2(_) => { 3 },
425423
&NetAddress::OnionV3 {..} => { 4 },
426424
}
427425
}
@@ -431,7 +429,7 @@ impl NetAddress {
431429
match self {
432430
&NetAddress::IPv4 { .. } => { 6 },
433431
&NetAddress::IPv6 { .. } => { 18 },
434-
&NetAddress::OnionV2 { .. } => { 12 },
432+
&NetAddress::OnionV2(_) => { 12 },
435433
&NetAddress::OnionV3 { .. } => { 37 },
436434
}
437435
}
@@ -453,10 +451,9 @@ impl Writeable for NetAddress {
453451
addr.write(writer)?;
454452
port.write(writer)?;
455453
},
456-
&NetAddress::OnionV2 { ref addr, ref port } => {
454+
&NetAddress::OnionV2(bytes) => {
457455
3u8.write(writer)?;
458-
addr.write(writer)?;
459-
port.write(writer)?;
456+
bytes.write(writer)?;
460457
},
461458
&NetAddress::OnionV3 { ref ed25519_pubkey, ref checksum, ref version, ref port } => {
462459
4u8.write(writer)?;
@@ -486,12 +483,7 @@ impl Readable for Result<NetAddress, u8> {
486483
port: Readable::read(reader)?,
487484
}))
488485
},
489-
3 => {
490-
Ok(Ok(NetAddress::OnionV2 {
491-
addr: Readable::read(reader)?,
492-
port: Readable::read(reader)?,
493-
}))
494-
},
486+
3 => Ok(Ok(NetAddress::OnionV2(Readable::read(reader)?))),
495487
4 => {
496488
Ok(Ok(NetAddress::OnionV3 {
497489
ed25519_pubkey: Readable::read(reader)?,
@@ -1922,10 +1914,9 @@ mod tests {
19221914
});
19231915
}
19241916
if onionv2 {
1925-
addresses.push(msgs::NetAddress::OnionV2 {
1926-
addr: [255, 254, 253, 252, 251, 250, 249, 248, 247, 246],
1927-
port: 9735
1928-
});
1917+
addresses.push(msgs::NetAddress::OnionV2(
1918+
[255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]
1919+
));
19291920
}
19301921
if onionv3 {
19311922
addresses.push(msgs::NetAddress::OnionV3 {

lightning/src/util/ser.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,9 @@ macro_rules! impl_array {
475475
);
476476
}
477477

478-
//TODO: performance issue with [u8; size] with impl_array!()
479478
impl_array!(3); // for rgb
480479
impl_array!(4); // for IPv4
481-
impl_array!(10); // for OnionV2
480+
impl_array!(12); // for OnionV2
482481
impl_array!(16); // for IPv6
483482
impl_array!(32); // for channel id & hmac
484483
impl_array!(PUBLIC_KEY_SIZE); // for PublicKey

0 commit comments

Comments
 (0)