Subset of #9897, with the goal to decouple command line arg parsing and make AppInitMain() smaller.
Add Binds, WhiteBinds, Whitelistedrange to CConnman::Options #10496
pull benma wants to merge 2 commits into bitcoin:master from benma:connman_options changing 3 files +103 −79-
benma commented at 10:43 AM on June 1, 2017: none
- fanquake added the label Refactoring on Jun 1, 2017
-
in src/net.cpp:68 in 7313bfec53 outdated
63 | @@ -64,6 +64,14 @@ 64 | #endif 65 | #endif 66 | 67 | +/** Used to pass flags to the Bind() function */ 68 | +enum BindFlags {
practicalswift commented at 10:48 AM on June 1, 2017:Minor nit, but what about switching to C++11 strongly typed enumerations (
enum class) while we are at it?
benma commented at 11:12 AM on June 1, 2017:Great idea, but unfortunately, bitwise operations don't work with those (unless you manually add those functions to the class) :(
See http://blog.bitwigglers.org/using-enum-classes-as-type-safe-bitmasks/
practicalswift commented at 11:24 AM on June 1, 2017:Ah, of course. Sorry!
fanquake requested review from theuni on Jun 1, 2017ryanofsky commented at 3:25 PM on June 1, 2017: memberutACK 7313bfec5354f44571929249ee3672b8c38675a3. This seems like an improvement, though I also think it might be a little better if the connman options were vectors of strings, so AppInit would only be dealing with translating arguments (and the loops could be eliminated), and connman would deal with everything network related (lookups).
benma commented at 3:36 PM on June 1, 2017: none@ryanofsky thanks. I actually did it like this in a first iteration, but changed it because I figured that the arguments should be evaluated as much as possible before entering ConnMan. After all, ConnMan doesn't particularly care about the command line string representation.
It was a bit weird having the error messages that relate to
-whitelist,-bind,-whitebindstill in ConnMan as opposed to where the arguments are actually parsed.Edit: I see the point though that
Lookup()etc. are network functions and shouldn't be used in init.cpp. But refactoring all of that sounds like a separate issue, so I propose to defer this to another PR.theuni commented at 8:09 PM on June 5, 2017: memberI believe this is OK. I have a PR coming up which (after lots of thought) moves resolving into its own class, of which CConnman is one user. This way other layers are able to use the resolver without necessarily having to go through CConnman.
So, concept ACK. Reviewing.
in src/init.cpp:1610 in 7313bfec53 outdated
1593 | @@ -1644,6 +1594,28 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) 1594 | connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe; 1595 | connOptions.nMaxOutboundLimit = nMaxOutboundLimit; 1596 | 1597 | + if (gArgs.IsArgSet("-bind")) {
theuni commented at 8:17 PM on June 5, 2017:This looks like a change in behavior when setting "-bind=foo -listen=0". Granted, that combination makes no sense.
I think we should probably just check for that combination, and exit with an error in that case.
benma commented at 2:14 PM on June 10, 2017:Done.
in src/net.cpp:2209 in 7313bfec53 outdated
2205 | + } 2206 | + return true; 2207 | +} 2208 | + 2209 | +bool CConnman::InitBinds(const std::vector<CService>& binds, const std::vector<CService>& whiteBinds) { 2210 | + if (fListen) {
theuni commented at 8:19 PM on June 5, 2017:See other comment. It doesn't make sense to have binds/whitebinds set at all if !fListen.
benma commented at 2:14 PM on June 10, 2017:Done.
in src/net.cpp:2211 in 7313bfec53 outdated
2207 | +} 2208 | + 2209 | +bool CConnman::InitBinds(const std::vector<CService>& binds, const std::vector<CService>& whiteBinds) { 2210 | + if (fListen) { 2211 | + bool fBound = false; 2212 | + for (const auto& addrBind : binds) {
theuni commented at 8:30 PM on June 5, 2017:Mm, this moves the logic away from the caller and into CConnman, which is what we're trying to avoid by adding the heaps of options.
I think I'd prefer to see flags passed in along with CServices, so that CConnman can just do what it's told. So either a tiny struct, or just a pair.
Then, CConnman will try to bind the BF_EXPLICIT addresses, and if it fails, tries to bind the rest.
Also, in that case, the last failed bind wouldn't need to have BF_REPORT_ERROR set, we'd just notice the false return and act on it accordingly.
Sound reasonable?
benma commented at 2:13 PM on June 10, 2017:Mm, this moves the logic away from the caller and into CConnman, which is what we're trying to avoid by adding the heaps of options. I think I'd prefer to see flags passed in along with CServices, so that CConnman can just do what it's told. So either a tiny struct, or just a pair.
The logic would be in
CConnmanall the same, just the data structure you pass the info with is changed from two vectors to one vector of pairs, which is equivalent. The code looks more complicated from what I can tell. Or did I misunderstand your request?I added this in a separate commit to see the diff, I drop it again if needed.
Then, CConnman will try to bind the BF_EXPLICIT addresses, and if it fails, tries to bind the rest.
At the moment, the rest is only attempted if no explicit binds are specified. If they fail, all fails, which makes sense to me.
Also, in that case, the last failed bind wouldn't need to have BF_REPORT_ERROR set, we'd just notice the false return and act on it accordingly.
Act how, apart from reporting the error (which this flag does)?
theuni commented at 6:26 PM on June 13, 2017:Mm, this moves the logic away from the caller and into CConnman, which is what we're trying to avoid by adding the heaps of options. I think I'd prefer to see flags passed in along with CServices, so that CConnman can just do what it's told. So either a tiny struct, or just a pair.
The logic would be in CConnman all the same, just the data structure you pass the info with is changed from two vectors to one vector of pairs, which is equivalent. The code looks more complicated from what I can tell. Or did I misunderstand your request?
The logic would still be in CConnman, but the caller would have the ability to dictate exactly how the binds are setup. For example, there's no way to specify "listen on this address as well as the localhost fallbacks".
I think this is ok for now, though. We can add options as things come up.
benma commented at 10:45 PM on June 13, 2017:For example, there's no way to specify "listen on this address as well as the localhost fallbacks".
But that wasn't possible before either.
Do you prefer the commit which passes the whitelist flag in the pair (https://github.com/bitcoin/bitcoin/pull/10496/commits/768c7f72d9fac542a45ad788713faa1a3f46897c), or should I drop it? I don't mind either way, but the new code seems less readable than the code before, but it is semantically exactly the same.
theuni commented at 10:59 PM on June 13, 2017:But that wasn't possible before either.
Sure, but we've been slowly moving these config options out to the caller so that less is hard-coded.
In the near-future, I'm looking forward to creating 2 CConnman instances and running them against each-other for testing. The more we can control via setup options, the better. I have no problem with adding those options incrementally, I'd just like to make sure we're not making future changes tougher.
As for the whitelist flag, either way is fine for this PR. Whichever you think is more readable. We'll expand on the options when needed.
benma commented at 11:30 PM on June 13, 2017::+1: I reverted it as I find the previous version more readable.
theuni changes_requestedtheuni commented at 8:32 PM on June 5, 2017: memberConcept ACK. Thanks for working on this!
benma force-pushed on Jun 10, 2017in src/net.cpp:2236 in 521bfa71e6 outdated
2236 | +bool CConnman::Bind(const CService &addr, unsigned int flags) { 2237 | + if (!(flags & BF_EXPLICIT) && IsLimited(addr)) 2238 | + return false; 2239 | + std::string strError; 2240 | + if (!BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) { 2241 | + if ((flags & BF_REPORT_ERROR) && clientInterface) {
theuni commented at 6:31 PM on June 13, 2017:Well done! Thanks for using the local instance.
in src/net.cpp:2252 in 521bfa71e6 outdated
2252 | + unsigned int flags = BF_EXPLICIT | BF_REPORT_ERROR; 2253 | + if (addrBind.second == Options::BindType::WhiteBind) 2254 | + flags |= BF_WHITELIST; 2255 | + fBound |= Bind(addrBind.first, flags); 2256 | + } 2257 | + if (binds.empty()) {
theuni commented at 6:41 PM on June 13, 2017:Looks like there's no way to run without listening now.
Sorry for not being more clear here: #10496 (review). I was suggesting that we shouldn't get into InitBinds in the first place if binding isn't allowed.
We'll either need to change this so that its caller uses the ugly global as before:
if(fListen && !InitBinds(...)) { ... }or add a flag for fallback connections, which InitBinds() only uses if nothing else is already bound.
benma commented at 10:39 PM on June 13, 2017:Oops, was a bit too eager here. Re-added the
fListencheck as you suggested.in src/net.cpp:2290 in 521bfa71e6 outdated
2283 | @@ -2252,11 +2284,19 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c 2284 | 2285 | SetBestHeight(connOptions.nBestHeight); 2286 | 2287 | + clientInterface = connOptions.uiInterface; 2288 | + 2289 | + if (!InitBinds(connOptions.vBinds)) { 2290 | + strError = _("Failed to listen on any port. Use -listen=0 if you want this.");
theuni commented at 6:46 PM on June 13, 2017:This strError param is clunky (my fault!). We should do away with it and just use clientInterface->InitError() directly. That can be done as a follow-up though.
benma commented at 10:39 PM on June 13, 2017:Done.
in src/init.cpp:888 in 521bfa71e6 outdated
878 | @@ -898,10 +879,16 @@ bool AppInitParameterInteraction() 879 | return InitError(_("Prune mode is incompatible with -txindex.")); 880 | } 881 | 882 | + // -bind and -whitebind can't be set when not listening 883 | + size_t nUserBind = 884 | + (gArgs.IsArgSet("-bind") ? gArgs.GetArgs("-bind").size() : 0) + 885 | + (gArgs.IsArgSet("-whitebind") ? gArgs.GetArgs("-whitebind").size() : 0); 886 | + if (nUserBind != 0 && !GetBoolArg("-listen", DEFAULT_LISTEN)) {
theuni commented at 6:57 PM on June 13, 2017:s/GetBoolArg/gArgs.GetBoolArg/
benma commented at 10:39 PM on June 13, 2017:GetBoolArg() is simply wrapping gArgs.GetBoolArg(), and both variants are already used in the function. Could make that consistent in a separate PR.
theuni commented at 10:50 PM on June 13, 2017:gArgs is the new (as of very recently) way of handling these args, it'd be helpful if new code didn't reintroduce the former usage as I assume the wrappers are intended to be temporary.
theuni commented at 7:05 PM on June 13, 2017: memberlooks good aside from those few issues.
benma force-pushed on Jun 13, 2017benma force-pushed on Jun 13, 2017ce79f32518add WhitelistedRange to CConnman::Options
Part of a series of changes to clean up the instantiation of connman by decoupling the command line arguments.
07b2afef10add Binds, WhiteBinds to CConnman::Options
Part of a series of changes to clean up the instantiation of connman by decoupling the command line arguments. We also now abort with an error when explicit binds are set with -listen=0.
benma force-pushed on Jun 15, 2017benma commented at 9:11 PM on June 15, 2017: noneRebased.
theuni approvedtheuni commented at 10:09 PM on June 20, 2017: memberutACK 07b2afef10bb6366a270e325fd41a8bc526c9ef3
ryanofsky commented at 3:43 PM on June 21, 2017: memberutACK 07b2afef10bb6366a270e325fd41a8bc526c9ef3. There were many changes since last review, all discussed above.
laanwj commented at 1:03 PM on June 26, 2017: memberutACK 07b2afe
laanwj merged this on Jun 26, 2017laanwj closed this on Jun 26, 2017laanwj referenced this in commit 22a0aca329 on Jun 26, 2017PastaPastaPasta referenced this in commit fe08ba40ff on Jul 6, 2019PastaPastaPasta referenced this in commit b0e97004dd on Jul 6, 2019PastaPastaPasta referenced this in commit 2855297a36 on Jul 6, 2019PastaPastaPasta referenced this in commit 04e88d9602 on Jul 8, 2019PastaPastaPasta referenced this in commit ec3f26ea86 on Jul 9, 2019PastaPastaPasta referenced this in commit 4b2f270703 on Jul 11, 2019barrystyle referenced this in commit a4537d76d4 on Jan 22, 2020DrahtBot locked this on Sep 8, 2021
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-22 06:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me