These two methods have had the same meaning, but inverted, since 110b62f06992d0fb989153afff2dc3aea62a674f. Having one name for a single concept simplifies the code.
Drop IsLimited in favor of IsReachable #15138
pull Empact wants to merge 1 commits into bitcoin:master from Empact:is-reachable changing 6 files +44 −65-
Empact commented at 12:50 AM on January 10, 2019: member
-
laanwj commented at 1:11 AM on January 10, 2019: member
I like
IsReachablebetter thanIsLimitedtbh, I think it's clearer, if we have to do this (I'm not convinced) I'd pefer to go for that. - laanwj added the label P2P on Jan 10, 2019
-
DrahtBot commented at 1:48 AM on January 10, 2019: member
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #14856 ([WIP] net: remove more CConnman globals (theuni) by dongcarl)
- #14425 (Net: Do not re-enable Onion network when it was disabled via onlynet by wodry)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
- Empact force-pushed on Jan 10, 2019
-
Empact commented at 1:57 AM on January 10, 2019: member
Fair enough, I agree that's clearer.
- I removed the
SetReachabledefault arg because I don't think it clarifies the call sites. - I switched from
bool[]tostd::vector<bool>because it enables easy initialization.
- I removed the
- laanwj renamed this:
Drop IsReachable in favor of IsLimited
Drop IsLimited in favor of IsReachable
on Jan 10, 2019 -
laanwj commented at 11:58 AM on January 10, 2019: member
Thanks, concept ACK.
I switched from bool[] to std::vector<bool> because it enables easy initialization.
What is the reasoning behind this? What what difficult about the old initialization?
-
in src/net.cpp:95 in 5937619ec9 outdated
91 | @@ -92,7 +92,7 @@ bool fListen = true; 92 | bool fRelayTxes = true; 93 | CCriticalSection cs_mapLocalHost; 94 | std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); 95 | -static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; 96 | +static std::vector<bool> nets_reachable GUARDED_BY(cs_mapLocalHost)(NET_MAX, true);
MarcoFalke commented at 2:55 PM on January 10, 2019:nit:
std::array<...> g_nets_reachable?
promag commented at 3:48 PM on January 10, 2019:static auto g_nets_reachable GUARDED_BY(cs_mapLocalHost)(std::bitset<NET_MAX>{}.set());promag commented at 3:50 PM on January 10, 2019: memberConcept ACK, +1 reachable.
Empact force-pushed on Jan 10, 2019Empact commented at 8:04 PM on January 10, 2019: memberEmpact force-pushed on Jan 10, 2019Empact force-pushed on Jan 10, 2019promag commented at 8:49 PM on January 10, 2019: memberAs of now, using std::bitset with an integer initializer, plus a static_assert to assure the int covers all bits.
What is the problem with initializing it with
std::bitset<NET_MAX>{}.set()?Empact commented at 9:34 PM on January 10, 2019: memberWhat is the problem with initializing it with
std::bitset<NET_MAX>{}.set()?Switched to your approach after I wrote that - int + static_assert is nice because it's a compile-time operation, but decided that's a form of micro-optimization, not worth the cost in readability.
promag commented at 12:28 AM on January 11, 2019: memberJust noting that
SetReachablenow throwsstd::out_of_range(for instanceSetReachable((Network)100, true)). It would be similar withstd::array::atinstead ofstd::array::operator[].ACK a7d6098.
in src/net.cpp:96 in a7d6098edf outdated
92 | @@ -92,7 +93,7 @@ bool fListen = true; 93 | bool fRelayTxes = true; 94 | CCriticalSection cs_mapLocalHost; 95 | std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); 96 | -static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; 97 | +static std::bitset<NET_MAX> g_nets_reachable GUARDED_BY(cs_mapLocalHost)(std::bitset<NET_MAX>().set());
promag commented at 12:35 AM on January 11, 2019:nit, I still have a preference for
static auto g_nets_reachable GUARDED_BY(cs_mapLocalHost){std::bitset<NET_MAX>().set()};since it doesn't repeat the type — here the type is obvious.
Empact commented at 1:45 AM on January 11, 2019:It's a small difference, but I included it because I think it makes the declaration more readable - after GUARDED_BY seems a bit buried if you're scanning down the page.
laanwj commented at 8:57 AM on January 12, 2019:This is the first use of
std::bitsetin this project. It's a small set, the memory savings here are minimal compared to the extra code that is being introduced to handle it. I think the original code here was fine.
Empact commented at 11:52 PM on January 12, 2019:Yeah - I think of
bitsetas justvector<bool>without the interface requirements ofvector, thus able to be more constrained (e.g. fixed size). But I'll revert to the array to narrow the focus of this PR.Empact commented at 1:51 AM on January 11, 2019: memberFYI I double-checked that
NET_TEREDO, which would be out of bounds, does not extend into these apis.sipa commented at 6:22 PM on January 11, 2019: memberutACK a7d6098edff439bc26b811b8f11852eb792e6082
Empact force-pushed on Jan 12, 2019Empact commented at 11:57 PM on January 12, 2019: memberDropped
std::bitsetin favor of the original array, as per #15138 (review)diff --git a/src/net.cpp b/src/net.cpp index 95177fbae..40ec17d8e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -37,7 +37,6 @@ #include <miniupnpc/upnperrors.h> #endif -#include <bitset> #include <unordered_map> #include <math.h> @@ -93,7 +92,7 @@ bool fListen = true; bool fRelayTxes = true; CCriticalSection cs_mapLocalHost; std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); -static std::bitset<NET_MAX> g_nets_reachable GUARDED_BY(cs_mapLocalHost)(std::bitset<NET_MAX>().set()); +static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; std::string strSubVersion; limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ); @@ -258,13 +257,13 @@ void SetReachable(enum Network net, bool reachable) if (net == NET_UNROUTABLE || net == NET_INTERNAL) return; LOCK(cs_mapLocalHost); - g_nets_reachable.set(net, reachable); + vfLimited[net] = !reachable; } bool IsReachable(enum Network net) { LOCK(cs_mapLocalHost); - return g_nets_reachable.test(net); + return !vfLimited[net]; } bool IsReachable(const CNetAddr &addr)in src/net.h:32 in ccaf355a5a outdated
28 | @@ -29,6 +29,7 @@ 29 | #include <thread> 30 | #include <memory> 31 | #include <condition_variable> 32 | +#include <vector>
promag commented at 12:25 AM on January 13, 2019:Remove?
Empact commented at 2:44 AM on January 13, 2019:Originally added because I used std::vector, but left it in because vector is used in the header irrespective of other changes / iwyu. Still remove?
promag commented at 9:32 PM on January 13, 2019:I'd say yes, since there are no ack's yet and it's unrelated to this PR.
Empact force-pushed on Jan 13, 2019ajtowns commented at 6:18 AM on January 14, 2019: memberutACK 04a1b53661a71c240a9244e70e5f990ae767a0bf
nit: comment for
SetReachableseems like it's a bit inverted (describes SetLimited` better)d6b076c17bDrop IsLimited in favor of IsReachable
These two methods have had the same meaning, but inverted, since 110b62f06992d0fb989153afff2dc3aea62a674f. Having one name for a single concept simplifies the code.
Empact force-pushed on Jan 14, 2019in src/net.h:525 in d6b076c17b
519 | @@ -520,17 +520,23 @@ enum 520 | 521 | bool IsPeerAddrLocalGood(CNode *pnode); 522 | void AdvertiseLocal(CNode *pnode); 523 | -void SetLimited(enum Network net, bool fLimited = true); 524 | -bool IsLimited(enum Network net); 525 | -bool IsLimited(const CNetAddr& addr); 526 | + 527 | +/** 528 | + * Mark a network as reachable or unreachable (no automatic connects to it)
laanwj commented at 1:22 PM on January 14, 2019:I think the
SetReachablecomment is ok…? (oh it was updated, good)laanwj commented at 1:25 PM on January 14, 2019: memberutACK d6b076c17bc7d513243711563b262524ef0ba74c
laanwj merged this on Jan 14, 2019laanwj closed this on Jan 14, 2019laanwj referenced this in commit 43a79d22c1 on Jan 14, 2019PastaPastaPasta referenced this in commit b8bc9e9643 on Jul 18, 2021PastaPastaPasta referenced this in commit 325aff4094 on Jul 18, 2021random-zebra referenced this in commit b4751e10ce on Aug 11, 2021DrahtBot locked this on Feb 15, 2022Empact deleted the branch on Apr 18, 2022
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 21:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me