Commit graph

25630 commits

Author SHA1 Message Date
MarcoFalke facb41bf1d
test: Remove unused p2p_lock in VersionBitsWarningTest 2020-08-27 11:41:40 +02:00
Jon Atack 407175e0c2
p2p: change CInv::type from int to uint32_t
fixes issue #19678 UBSan implicit-integer-sign-change

Credit to Eugene (Crypt-iQ) for finding and reporting the issue
and to Vasil Dimov (vasild) for the original suggestion
2020-08-27 10:57:20 +02:00
fanquake 2562d5d238
Merge #19761: build: improve sed robustness by not using sed
3de365e4f1 build: replace wingenminiupnpcstrings sed with a patch in miniupnpc package (fanquake)
bbc01a753d build: replace qtranslations lrelease sed with a patch in qt package (fanquake)
c723e4176e build: replace FreeType back-compat sed with a patch in qt package (fanquake)
3aaa39d436 build: replace pwd sed in qt package with a patch (fanquake)
9d440f4e11 build: remove no-longer needed qt workaround (fanquake)
bf85eace1a build: remove no-longer needed qt configure workaround (fanquake)
4af59a407a build: use patch rather than sed in zeromq package (fanquake)
cc107a3af1 build: use patch rather than sed in native_cctools package (fanquake)
865cb23a48 build: use patch rather than sed in fontconfig package (fanquake)
335bd7f8bc build: use patch rather than sed in Boost package (fanquake)
f36140d00c build: use patch rather than sed in bdb package (fanquake)

Pull request description:

  While using `sed` can be handy to use for a quick-fix, these instances accumulate, and can become unmaintainable. Not only that, but using sed isn't necessarily robust and it can fail silently. Most of our usage is also missing any documentation explaining why something is being done, when it should be updated/removed etc.

  Rather than relying on sed going forward, where possible, I've converted our sed usage into patches. These are easier to maintain, contain documentation, and should fail loudly when they don't apply.

  The remaining sed usage, (1 in miniupnpc, the rest in qt), are non-trivial to remove, as they are using build-time variables, or some input from the environment.

  This also steals 2 related commits out of #19716.

  Related to #16838.

ACKs for top commit:
  hebasto:
    re-ACK 3de365e4f1, only `drop_lrelease_dependency.patch` updated. Travis makes ARM build without errors now.
  theuni:
    ACK 3de365e4f1.

Tree-SHA512: b39afcb237e4421f9caabbd665af93fd2e749a1cdd42b1d5ee2261059120005c0e82994d315e679c317d23794eab5c7727f51cae403c94a9c4e4fd7eee9e7ee6
2020-08-27 16:03:14 +08:00
MarcoFalke 28f4e53e16
Merge #19752: test: Update wait_until usage in tests not to use the one from utils
d841301010 test: Add docstring to wait_until() in util.py to warn about its usage (Seleme Topuz)
1343c86c7c test: Update wait_until usage in tests not to use the one from utils (Seleme Topuz)

Pull request description:

  Replace global (from [test_framework/util.py](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/util.py#L228)) `wait_until()` usages with the ones provided by `BitcoinTestFramework` and `P2PInterface` classes.

  The motivation behind this change is that the `util.wait_until()` expects a timeout, timeout_factor and lock and it is not aware of the context of the test framework. `BitcoinTestFramework` offers a `wait_until()` which has an understandable amount of default `timeout` and a shared `timeout_factor`. Moreover, on top of these, `mininode.wait_until()` also has a shared lock.

  closes #19080

ACKs for top commit:
  MarcoFalke:
    ACK d841301010 🦆
  kallewoof:
    utACK d841301010

Tree-SHA512: 81604f4cfa87fed98071a80e4afe940b3897fe65cf680a69619a93e97d45f25b313c12227de7040e19517fa9c003291b232f1b40b2567aba0148f22c23c47a88
2020-08-27 08:21:59 +02:00
MarcoFalke 30568d3f1e
Merge #19778: test: Fix intermittent issue in wallet_bumpfee
fafc9d5af4 test: Fix intermittent issue in wallet_bumpfee (MarcoFalke)
fa347b2f25 test: Select at least the fee in wallet_bumpfee to avoid negative amounts (MarcoFalke)

Pull request description:

  With a "dirty" mempool a transaction might fail to be accepted intermittently. For example,

  * https://travis-ci.org/github/bitcoin-core/gui/jobs/719916499#L6773 Fails acceptance
  * https://travis-ci.org/github/bitcoin-core/gui/jobs/719916499#L6954 Test fails

  Fix the issue by clearing the mempool between subtests

ACKs for top commit:
  promag:
    Code review ACK fafc9d5af4.

Tree-SHA512: 23fb6decb6343d19eafddcbdb7da0551f6be11325d1c97c30e563944000aeb02bcc4b24904d204b132c093dc1acf28445fa1fd08bfe8d8b52ddd1de51c33eeb6
2020-08-26 19:25:38 +02:00
Seleme Topuz d841301010 test: Add docstring to wait_until() in util.py to warn about its usage 2020-08-26 18:01:59 +02:00
Seleme Topuz 1343c86c7c test: Update wait_until usage in tests not to use the one from utils
Replace "wait_until()" usage from utils, with the ones from BitcoinTestFramework and P2PInterface.
closes #19080
2020-08-26 18:01:59 +02:00
MarcoFalke 93ab136a33
Merge bitcoin-core/gui#35: Parse params directly instead of through node (partial revert #10244)
519cae8fd6 gui: Delay interfaces::Node initialization (Russell Yanofsky)
102abff9eb gui: Replace interface::Node references with pointers (Russell Yanofsky)
91aced7c7e gui: Remove unused interfaces::Node references (Russell Yanofsky)
e133631625 gui: Partially revert #10244 gArgs and Params changes (Russell Yanofsky)

Pull request description:

  This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10).

  ---

  This is a partial revert of https://github.com/bitcoin/bitcoin/pull/10244. It changes gui code to go back to using gArgs and Params() functions directly instead of using interfaces::Node to handle arguments.

  These changes were originally pushed as part of https://github.com/bitcoin/bitcoin/pull/19461. Motivation is to support a new GUI process connecting to an already running node process. Details are explained in commit messages, but in addition to spawning a new bitcoin-node process, we want bitcoin-gui to connect to an existing bitcoin-node process. So for that reason it should be able to parse its own parameters, rather than rely on the node.

ACKs for top commit:
  MarcoFalke:
    re-ACK 519cae8fd6, only change is rebase and addressed nits of my previous review last week 🌄

Tree-SHA512: 9c339dd82ba78bcc7b887b84d872f35ccc7dfa3d271691e6eafe8a2048cbbe3bdde1e810ce33d0714d75d048c9de3470e9e9b6f8306a6047d1cb3548f6858dc8
2020-08-26 16:32:44 +02:00
Hennadii Stepanov 3edc4e34fe
bench: Prevent thread oversubscription
This change decreases the variance of benchmark results.
2020-08-26 13:00:00 +03:00
John Newbery fb56d37612
p2p: ensure inv is GenMsgTx before ToGenTxid in inv processing
and otherwise log that an unknown INV type was received.

In INV processing, when handling transaction type inv messages,
ToGenTxid() expects that we constructed the CInv ourselves or
that we verified that it is for a transaction type CInv.

Therefore, change this `else` branch into an `else if (inv.GenMsgTx())`
to make this safer and log any INVs that fall through.
2020-08-26 11:57:30 +02:00
Jon Atack aa3621385e
test: use CInv::MSG_WITNESS_TX flag in p2p_segwit 2020-08-26 11:57:27 +02:00
Jon Atack 24ee4f01ea
p2p: make gtxid(.hash) and fAlreadyHave localvars const 2020-08-26 11:57:23 +02:00
Jon Atack b1c855453b
p2p: use CInv block message helpers in net_processing.cpp 2020-08-26 11:57:19 +02:00
John Newbery acd6642167
[net processing] Change AlreadyHaveTx() to take a GenTxid 2020-08-26 11:57:15 +02:00
John Newbery 5fdfb80b86
[net processing] Change AlreadyHaveBlock() to take block_hash argument 2020-08-26 11:57:11 +02:00
John Newbery 430e183b89
[net processing] Remove mempool argument from AlreadyHaveBlock() 2020-08-26 11:57:07 +02:00
John Newbery 42ca5618ca
[net processing] Split AlreadyHave() into separate block and tx functions 2020-08-26 11:57:03 +02:00
Jon Atack 39f1dc9445
p2p: remove nFetchFlags from NetMsgType TX and INV processing
The nFetchFlags code can be removed here because GetFetchFlags() can only add
the MSG_WITNESS_FLAG, which is added to the CInv::type field. That CInv is only
passed to AlreadyHave() or ToGenTxid(), and neither of those functions do
anything different depending on whether the CInv type is MSG_TX or
MSG_WITNESS_TX.

Co-authored by: John Newbery <john@johnnewbery.com>
2020-08-26 11:56:59 +02:00
Jon Atack 471714e1f0
p2p: add CInv block message helper methods 2020-08-26 11:56:55 +02:00
MarcoFalke a12d9e5fd2
Merge #19687: refactor: make EncodeBase{32,64} consume Spans
e2aa1a585a util: make EncodeBase64 consume Spans (Sebastian Falbesoner)
2bc207190e util: make EncodeBase32 consume Spans (Sebastian Falbesoner)

Pull request description:

  To simplify the interface of the Base32/Base64 encoding functions for raw data, this PR changes them from taking two arguments (pointer and length) to just one Span. Most calls to `EncodeBase64` pass data from `CDataStream` instances, which unfortunately internally work with `char*` pointers rather than `unsigned char*`, but thanks to the recently introduced `MakeUCharSpan` helper, converting them is quite easy.

ACKs for top commit:
  MarcoFalke:
    ACK e2aa1a585a 🐮
  vasild:
    ACK e2aa1a585

Tree-SHA512: 43bd3bd2ee8e3be2474db0a81dae9d9e88fac2464b96d1b042147106ed7433799dcba3000c69990511ecfc697b0c7306ce85f2ecb2293e2e44fd356c9694b150
2020-08-26 11:52:31 +02:00
Russell Yanofsky 519cae8fd6 gui: Delay interfaces::Node initialization
This is needed to allow bitcoin-gui to connect to existing node process with
-ipcconnect instead of spawning a new process. It's possible to spawn a new
bitcoin-node process without knowing the current data dir or network, but
connecting to an existing bitcoin-node requires knowing the datadir and network
first.
2020-08-26 05:52:31 -04:00
Russell Yanofsky 102abff9eb gui: Replace interface::Node references with pointers
No change in behavior. Replacing references with pointers allows Node interface
creation to be delayed until later during gui startup next commit to support
implementing -ipcconnect option
2020-08-26 05:52:31 -04:00
Russell Yanofsky 91aced7c7e gui: Remove unused interfaces::Node references
Remove Node references no longer needed after previous commit
2020-08-26 05:52:31 -04:00
Russell Yanofsky e133631625 gui: Partially revert #10244 gArgs and Params changes
Change gui code to use gArgs, Params() functions directly instead of going
through interfaces::Node.

Remotely accessing bitcoin-node ArgsManager from bitcoin-gui works fine in
https://github.com/bitcoin/bitcoin/pull/10102, when bitcoin-gui spawns a new
bitcoin-node process and controls its startup, but for bitcoin-gui to support
-ipcconnect option in https://github.com/bitcoin/bitcoin/pull/19461 and connect
to an existing bitcoin-node process, it needs ability to parse arguments itself
before connecting out.

This change also simplifies https://github.com/bitcoin/bitcoin/pull/10102 a
bit, by making the bitcoin-gui -> bitcoin-node startup sequence more similar to
the bitcoin-node -> bitcoin-wallet startup sequence where the parent process
parses arguments and passes them to the child process instead of the parent
process using the child process to parse arguments.
2020-08-26 05:52:31 -04:00
fanquake e80e5b3e4f
Merge #19760: test: Remove confusing mininode terminology
d5800da519 [test] Remove final references to mininode (John Newbery)
5e8df3312e test: resort imports (John Newbery)
85165d4332 scripted-diff: Rename mininode to p2p (John Newbery)
9e2897d020 scripted-diff: Rename mininode_lock to p2p_lock (John Newbery)

Pull request description:

  New contributors are often confused by the terminology in the test framework, and what the difference between a _node_ and a _peer_ is. To summarize:

  - a 'node' is a bitcoind instance. This is the thing whose behavior is being tested. Each bitcoind node is managed by a python `TestNode` object which is used to start/stop the node, manage the node's data directory, read state about the node (eg process status, log file), and interact with the node over different interfaces.
  - one of the interfaces that we can use to interact with the node is the p2p interface. Each connection to a node using this interface is managed by a python `P2PInterface` or derived object (which is owned by the `TestNode` object). We can open zero, one or many p2p connections to each bitcoind node. The node sees these connections as 'peers'.

  For historic reasons, the word 'mininode' has been used to refer to those p2p interface objects that we use to connect to the bitcoind node (the code was originally taken from the 'mini-node' branch of https://github.com/jgarzik/pynode/tree/mini-node). However that name has proved to be confusing for new contributors, so rename the remaining references.

ACKs for top commit:
  amitiuttarwar:
    ACK d5800da519
  MarcoFalke:
    ACK d5800da519 🚞

Tree-SHA512: 2c46c2ac3c4278b6e3c647cfd8108428a41e80788fc4f0e386e5b0c47675bc687d94779496c09a3e5ea1319617295be10c422adeeff2d2bd68378e00e0eeb5de
2020-08-26 15:43:17 +08:00
fanquake 6a2ba62685
Merge #19779: Remove gArgs global from init
fa9d5902f7 scripted-diff: gArgs -> args (MarcoFalke)
fa33bc2dab init: Capture copy of blocknotify setting for BlockNotifyCallback (MarcoFalke)
fa40017706 init: Pass reference to ArgsManager around instead of relying on global (MarcoFalke)

Pull request description:

  The gArgs global has several issues:

  * gArgs is used by each process (bitcoind, bitcoin-qt, bitcoin-wallet, bitcoin-cli, bitcoin-tx, ...), but it is hard to determine which arguments are actually used by each process. For example arguments that have never been registered, but are still used, will always return the fallback value.
  * Tests may run several sub-tests, which need different settings. So globals will have to be overwritten, but that is fragile on its own: e.g. https://github.com/bitcoin/bitcoin/pull/19704#issuecomment-678259092 or #19511

  The goal is to remove gArgs, but as a first step in that direction this pull will change gArgs in init to use a passed-in reference instead.

ACKs for top commit:
  ryanofsky:
    Code review ACK fa9d5902f7. Looks good. Nice day to remove some globals, and add some lambdas 👍
  fanquake:
    ACK fa9d5902f7 - I'm not as familiar with the settings & argument handling code, but this make sense, and is a step in the right direction towards a reduction in the usage of globals. Not a huge fan of the clang-formatting in the scripted diff.
  jonasschnelli:
    Concept ACK fa9d5902f7

Tree-SHA512: ed00db5f826566c7e3b4d0b3d2ee0fc1a49a6e748e04e5c93bdd694ac7da5598749e73937047d5fce86150d764a067d2ca344ba4ae3eb2704cc5c4fa0d20940f
2020-08-26 15:18:38 +08:00
fanquake 92735e45ba
Merge #19775: test: Activate segwit in TestChain100Setup
fad84b7e14 test: Activate segwit in TestChain100Setup (MarcoFalke)
fa11ff2980 test: Pass empty tx pool to block assembler (MarcoFalke)
fa96574b0d test: Move doxygen comment to header (MarcoFalke)

Pull request description:

  This fixes not only a TODO in the code, but also prevents a never ending source of uninitialized reads. E.g.

  * #18376
  * https://github.com/bitcoin/bitcoin/pull/19704#issuecomment-678259092
  * ...

ACKs for top commit:
  jnewbery:
    utACK fad84b7e14

Tree-SHA512: 64cf16a59656d49e022b603f3b06441ceae35a33a4253b4382bc8a89a56e08ad5412c8fa734d0fc7b58586f40ea6d57b348a3b4838bc6890a41ae2ec3902e378
2020-08-26 13:17:35 +08:00
fanquake 3de365e4f1
build: replace wingenminiupnpcstrings sed with a patch in miniupnpc package
We should be able to drop this once we are using 2.1 or later. See
upstream commit: 9663c55c61408fdcc39a82987d2243f816b22932.
2020-08-26 11:27:31 +08:00
fanquake bbc01a753d
build: replace qtranslations lrelease sed with a patch in qt package 2020-08-26 11:27:12 +08:00
Andrew Chow 0bbe26a1af wallet: filter for keys only before record deser in salvage
When salvaging a wallet, avoid deserializing any records that we don't
care about, i.e. filter for keys only before the deserialization.
2020-08-25 13:23:40 -04:00
Andrew Chow 544e12a4e8 walletdb: Add KeyFilterFn to ReadKeyValue
Add a KeyFilterFn callback to ReadKeyValue which allows the caller to
specify which types to actually deserialize. A KeyFilterFn takes the
type as the parameter and returns a bool indicating whether
deserialization should continue.
2020-08-25 13:23:40 -04:00
Sebastian Falbesoner e2aa1a585a util: make EncodeBase64 consume Spans 2020-08-25 18:52:57 +02:00
Sebastian Falbesoner 2bc207190e util: make EncodeBase32 consume Spans 2020-08-25 18:52:51 +02:00
Luke Dashjr c4b85ba704 Bugfix: Define and use HAVE_FDATASYNC correctly outside LevelDB 2020-08-25 16:46:00 +00:00
MarcoFalke 8d6224fefe
Merge #19628: net: change CNetAddr::ip to have flexible size
102867c587 net: change CNetAddr::ip to have flexible size (Vasil Dimov)
1ea57ad674 net: don't accept non-left-contiguous netmasks (Vasil Dimov)

Pull request description:

  (chopped off from #19031 to ease review)

  Before this change `CNetAddr::ip` was a fixed-size array of 16 bytes,
  not being able to store larger addresses (e.g. TORv3) and encoded
  smaller ones as 16-byte IPv6 addresses.

  Change its type to `prevector`, so that it can hold larger addresses and
  do not disguise non-IPv6 addresses as IPv6. So the IPv4 address
  `1.2.3.4` is now encoded as `01020304` instead of
  `00000000000000000000FFFF01020304`.

  Rename `CNetAddr::ip` to `CNetAddr::m_addr` because it is not an "IP" or
  "IP address" (TOR addresses are not IP addresses).

  In order to preserve backward compatibility with serialization (where
  e.g. `1.2.3.4` is serialized as `00000000000000000000FFFF01020304`)
  introduce `CNetAddr` dedicated legacy serialize/unserialize methods.

  Adjust `CSubNet` accordingly. Still use `CSubNet::netmask[]` of fixed 16
  bytes, but use the first 4 for IPv4 (not the last 4). Do not accept
  invalid netmasks that have 0-bits followed by 1-bits and only allow
  subnetting for IPv4 and IPv6.

  Co-authored-by: Carl Dong <contact@carldong.me>

ACKs for top commit:
  sipa:
    utACK 102867c587
  MarcoFalke:
    Concept ACK 102867c587
  ryanofsky:
    Code review ACK 102867c587. Just many suggested updates since last review. Thanks for following up on everything!
  jonatack:
    re-ACK 102867c587 diff review, code review, build/tests/running bitcoind with ipv4/ipv6/onion peers
  kallewoof:
    ACK 102867c587

Tree-SHA512: d60bf716cecf8d3e8146d2f90f897ebe956befb16f711a24cfe680024c5afc758fb9e4a0a22066b42f7630d52cf916318bedbcbc069ae07092d5250a11e8f762
2020-08-25 18:10:25 +02:00
fanquake f8462a6d27
Merge #19601: Refactoring CHashWriter & Get{Prevouts,Sequence,Outputs}Hash to SHA256 (Alternative to #18071)
9ab4cafabd Refactor Get{Prevout,Sequence,Outputs}Hash to Get{Prevouts,Sequences,Outputs}SHA256. (Jeremy Rubin)
6510d0ff41 Add SHA256Uint256 helper functions (Jeremy Rubin)
b475d7d0fa Add single sha256 call to CHashWriter (Jeremy Rubin)

Pull request description:

  Opened as an alternative to #18071 to be more similar to #17977.

  I'm fine with either, deferring to others.

  cc jnewbery Sjors

ACKs for top commit:
  jnewbery:
    Code review ACK 9ab4cafabd
  jonatack:
    Tested ACK 9ab4caf
  fjahr:
    tested ACK 9ab4cafabd
  instagibbs:
    reACK 9ab4cafabd

Tree-SHA512: 93a7a47697f1657f027b18407bdcce16963f6b23d12372e7ac8fd4ee96769b3e2639369f9956fee669cc881b6338641cddfeeef1516c7104cb50ef4b880bb0a7
2020-08-25 20:18:40 +08:00
John Newbery d5800da519 [test] Remove final references to mininode 2020-08-25 10:04:25 +01:00
fanquake c723e4176e
build: replace FreeType back-compat sed with a patch in qt package 2020-08-25 14:37:45 +08:00
fanquake 3aaa39d436
build: replace pwd sed in qt package with a patch 2020-08-25 14:37:45 +08:00
fanquake 9d440f4e11
build: remove no-longer needed qt workaround 2020-08-25 14:37:45 +08:00
fanquake bf85eace1a
build: remove no-longer needed qt configure workaround
This was fixed upstream in c45595d64831990311f92fcebc4e34e2797f5352.
2020-08-25 14:37:44 +08:00
fanquake 4af59a407a
build: use patch rather than sed in zeromq package 2020-08-25 14:37:44 +08:00
fanquake cc107a3af1
build: use patch rather than sed in native_cctools package 2020-08-25 14:37:44 +08:00
fanquake 865cb23a48
build: use patch rather than sed in fontconfig package 2020-08-25 14:37:35 +08:00
fanquake 335bd7f8bc
build: use patch rather than sed in Boost package
The depends comment is actually incorrect, and this can be dropped once
we move to 1.71.0 or later.
2020-08-25 13:19:56 +08:00
fanquake f36140d00c
build: use patch rather than sed in bdb package 2020-08-25 13:19:55 +08:00
fanquake 8e0f341779
Merge #15704: Move Win32 defines to configure.ac to ensure they are globally defined
1ccb9f30c0 Move Win32 defines to configure.ac to ensure they are globally defined (Luke Dashjr)

Pull request description:

  #9245 no longer needs this, since the main `_WIN32_WINNT` got bumped by something else.

  So rather than just lose it, might as well get it merged in independently.

  I'm not aware of any practical effects, but it seems safer to use the same API versions everywhere.

ACKs for top commit:
  fanquake:
    ACK 1ccb9f30c0 - checked that the binaries produced are the same.

Tree-SHA512: 273e9186579197be01b443b6968e26b9a8031d356fabc5b73aa967fcdb837df195b7ce0fc4e4529c85d9b86da6f2d7ff1bf56a3ff0cbbcd8cee8a9c2bf70a244
2020-08-25 11:52:52 +08:00
fanquake c6b730dbfc
Merge #18405: build: Drop all of the ZeroMQ patches
f642b49af7 build: Drop ZeroMQ patch for glibc < 2.12 (Hennadii Stepanov)
079df9609e build: Drop ZeroMQ patch for Mingw-w64 < 4.0 (Hennadii Stepanov)

Pull request description:

  This PR gets rid of the all patches for ZeroMQ:
  - the [Mingw-w64 5.0 (Ubuntu 18.04 bionic)](https://packages.ubuntu.com/bionic/mingw-w64) is used to build the [Windows](https://github.com/bitcoin/bitcoin/blob/master/doc/build-windows.md) binaries
  - it is safe to use `pthread_setname_np` since #17538 when the minimal `glibc` version is set to 2.17; see: https://github.com/bitcoin/bitcoin/pull/11986#issuecomment-366105050

ACKs for top commit:
  fanquake:
    ACK f642b49af7.

Tree-SHA512: a2c97cdb682cd7d96a666ad099f20725a32bf8fda0842fc5534ca08a1634c90ba80afde92f9054595ed2501fbc5c02abbe3da765934ecff12d836ff25e277fc5
2020-08-25 10:26:16 +08:00
Vasil Dimov 102867c587
net: change CNetAddr::ip to have flexible size
Before this change `CNetAddr::ip` was a fixed-size array of 16 bytes,
not being able to store larger addresses (e.g. TORv3) and encoded
smaller ones as 16-byte IPv6 addresses.

Change its type to `prevector`, so that it can hold larger addresses and
do not disguise non-IPv6 addresses as IPv6. So the IPv4 address
`1.2.3.4` is now encoded as `01020304` instead of
`00000000000000000000FFFF01020304`.

Rename `CNetAddr::ip` to `CNetAddr::m_addr` because it is not an "IP" or
"IP address" (TOR addresses are not IP addresses).

In order to preserve backward compatibility with serialization (where
e.g. `1.2.3.4` is serialized as `00000000000000000000FFFF01020304`)
introduce `CNetAddr` dedicated legacy serialize/unserialize methods.

Adjust `CSubNet` accordingly. Still use `CSubNet::netmask[]` of fixed 16
bytes, but use the first 4 for IPv4 (not the last 4). Only allow
subnetting for IPv4 and IPv6.

Co-authored-by: Carl Dong <contact@carldong.me>
2020-08-24 21:50:59 +02:00
Vasil Dimov 1ea57ad674
net: don't accept non-left-contiguous netmasks
A netmask that contains 1-bits after 0-bits (the 1-bits are not
contiguous on the left side) is invalid [1] [2].

The code before this PR used to parse and accept such
non-left-contiguous netmasks. However, a coming change that will alter
`CNetAddr::ip` to have flexible size would make juggling with such
netmasks more difficult, thus drop support for those.

[1] https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#Subnet_masks
[2] https://tools.ietf.org/html/rfc4632#section-5.1
2020-08-24 21:50:59 +02:00