From e4a7d51537509dab765976f8642f9e15b84408bb Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 26 May 2015 08:59:13 +0200 Subject: [PATCH 1/3] Simplify code for CSubnet Simplify the code by using CAddress.ip directly, instead of the reversed GetByte() semantics. Rebased-From: 19e8d7be42039724b4893515ec6457d0187024a9 Github-Pull: #6186 --- src/netbase.cpp | 14 ++++++-------- src/netbase.h | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index 053c645a1..fe6e79efc 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -1214,12 +1214,12 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup) std::string strNetmask = strSubnet.substr(slash + 1); int32_t n; // IPv4 addresses start at offset 12, and first 12 bytes must match, so just offset n - int noffset = network.IsIPv4() ? (12 * 8) : 0; + const int astartofs = network.IsIPv4() ? 12 : 0; if (ParseInt32(strNetmask, &n)) // If valid number, assume /24 symtex { - if(n >= 0 && n <= (128 - noffset)) // Only valid if in range of bits of address + if(n >= 0 && n <= (128 - astartofs*8)) // Only valid if in range of bits of address { - n += noffset; + n += astartofs*8; // Clear bits [n..127] for (; n < 128; ++n) netmask[n>>3] &= ~(1<<(n&7)); @@ -1233,12 +1233,10 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup) { if (LookupHost(strNetmask.c_str(), vIP, 1, false)) // Never allow lookup for netmask { - // Remember: GetByte returns bytes in reversed order // Copy only the *last* four bytes in case of IPv4, the rest of the mask should stay 1's as // we don't want pchIPv4 to be part of the mask. - int asize = network.IsIPv4() ? 4 : 16; - for(int x=0; x Date: Tue, 26 May 2015 08:59:20 +0200 Subject: [PATCH 2/3] Fix two problems in CSubNet parsing Fix two CSubNet constructor problems: - The use of `/x` where 8 does not divide x was broken, due to a bit-order issue - The use of e.g. `1.2.3.4/24` where the netmasked bits in the network are not 0 was broken. Fix this by explicitly normalizing the netwok according to the bitmask. Also add tests for these cases. Fixes #6179. Thanks to @jonasschnelli for reporting and initial fix. Rebased-From: b45c50ce511dbf541ea086ae40a3ad16ff06de0c Github-Pull: #6186 --- src/netbase.cpp | 6 +++++- src/test/netbase_tests.cpp | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index fe6e79efc..d7c263f34 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -1222,7 +1222,7 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup) n += astartofs*8; // Clear bits [n..127] for (; n < 128; ++n) - netmask[n>>3] &= ~(1<<(n&7)); + netmask[n>>3] &= ~(1<<(7-(n&7))); } else { @@ -1249,6 +1249,10 @@ CSubNet::CSubNet(const std::string &strSubnet, bool fAllowLookup) { valid = false; } + + // Normalize network according to netmask + for(int x=0; x<16; ++x) + network.ip[x] &= netmask[x]; } bool CSubNet::Match(const CNetAddr &addr) const diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp index c26e73838..d5188c3ac 100644 --- a/src/test/netbase_tests.cpp +++ b/src/test/netbase_tests.cpp @@ -116,6 +116,11 @@ BOOST_AUTO_TEST_CASE(subnet_test) BOOST_CHECK(CSubNet("1:2:3:4:5:6:7:8").Match(CNetAddr("1:2:3:4:5:6:7:8"))); BOOST_CHECK(!CSubNet("1:2:3:4:5:6:7:8").Match(CNetAddr("1:2:3:4:5:6:7:9"))); BOOST_CHECK(CSubNet("1:2:3:4:5:6:7:0/112").Match(CNetAddr("1:2:3:4:5:6:7:1234"))); + BOOST_CHECK(CSubNet("192.168.0.1/24").Match(CNetAddr("192.168.0.2"))); + BOOST_CHECK(CSubNet("192.168.0.20/29").Match(CNetAddr("192.168.0.18"))); + BOOST_CHECK(CSubNet("1.2.2.1/24").Match(CNetAddr("1.2.2.4"))); + BOOST_CHECK(CSubNet("1.2.2.110/31").Match(CNetAddr("1.2.2.111"))); + BOOST_CHECK(CSubNet("1.2.2.20/26").Match(CNetAddr("1.2.2.63"))); // All-Matching IPv6 Matches arbitrary IPv4 and IPv6 BOOST_CHECK(CSubNet("::/0").Match(CNetAddr("1:2:3:4:5:6:7:1234"))); BOOST_CHECK(CSubNet("::/0").Match(CNetAddr("1.2.3.4"))); From e2714d2082fbcefc7ed2f9085192942a2a5478a0 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Wed, 27 May 2015 15:08:46 -0700 Subject: [PATCH 3/3] Litecoin: v0.10.2.1 release notes --- doc/release-notes-litecoin.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/release-notes-litecoin.md b/doc/release-notes-litecoin.md index 83cb7adea..fa2260a53 100644 --- a/doc/release-notes-litecoin.md +++ b/doc/release-notes-litecoin.md @@ -1,6 +1,6 @@ -Litecoin Core version 0.10.1.3 is now available from: +Litecoin Core version 0.10.2.1 is now available from: - + This is a new major version release, bringing bug fixes and translation updates. It is recommended to upgrade to this version. @@ -23,9 +23,9 @@ litecoind/litecoin-qt (on Linux). Downgrade warning ------------------ -Because release 0.10.0 and later makes use of headers-first synchronization and +Because release 0.10+ and later makes use of headers-first synchronization and parallel block download (see further), the block files and databases are not -backwards-compatible with pre-0.10 versions of Bitcoin Core or other software: +backwards-compatible with pre-0.10 versions of Litecoin Core or other software: * Blocks will be stored on disk out of order (in the order they are received, really), which makes it incompatible with some tools or @@ -44,9 +44,9 @@ supported and may break as soon as the older version attempts to reindex. This does not affect wallet forward or backward compatibility. -Litecoin 0.10.1.3 Change log +Litecoin 0.10.2.1 Change log ============================ -This release is based upon Bitcoin Core v0.10.1. Their upstream changelog applies to us and +This release is based upon Bitcoin Core v0.10.2. Their upstream changelog applies to us and is included in as separate release-notes. This section describes the Litecoin-specific differences. Protocol: @@ -62,13 +62,13 @@ Protocol: - bnProofOfWorkLimit = >> 20 (instead of >> 32) - See 9a980612005adffdeb2a17ca7a09fe126dd45e0e for Genesis Parameters - zeitgeist2 protection: b1b31d15cc720a1c186431b21ecc9d1a9062bcb6 Slightly different way to calculate difficulty changes. -- Litecoin Core v0.10.1.3 is protocol version 70003 (instead of 70002) +- Litecoin Core v0.10.2.1 is protocol version 70003 (instead of 70002) Relay: - Litecoin Core rounds transaction size up to the nearest 1000 bytes before calculating fees. This size rounding behavior is to mimic fee calculation of Litecoin v0.6 and v0.8. - Bitcoin's IsDust() is disabled in favor of Litecoin's fee-based dust penalty. - Fee-based Dust Penalty: For each transaction output smaller than DUST_THRESHOLD (currently 0.001 LTC) the default relay/mining policy will expect an additional 1000 bytes of fee. Otherwise the transaction will be rejected from relay/mining. Such transactions are also disqualified from the free/high-priority transaction rule. -- Miners and relays can adjust the expect fee per-KB with the -minrelaytxfee parameter. +- Miners and relays can adjust the expected fee per-KB with the -minrelaytxfee parameter. Wallet: - Coins smaller than 0.00001 LTC are by default ignored by the wallet. Use the -mininput parameter if you want to see smaller coins.