-
Notifications
You must be signed in to change notification settings - Fork 35.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network activity toggle #2412
Network activity toggle #2412
Conversation
Nice feature, but for the GUI I think it should a) show the current state in the debug window and b) allow a click or double-klick on the connection symbol in the main window, instead of a new button in the debug window. What do you think? |
@@ -5,6 +5,8 @@ | |||
#include "bitcoinrpc.h" | |||
#include "guiutil.h" | |||
|
|||
#include "net.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid direct access to net.h here... best way perhaps is to use the ClientModel and introduce a setNetworkActive()
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Using ClientModel would be a better solution.
Regarding a: The debug window actually shows the state (but maybe not in the best way), in that it appends "(Disabled)" to the number of connections when network activity is disabled. Are you suggesting a row in the debug window showing for example "Network state: "? I think double clicking on the connection symbol could also be a solution. I'm wondering though if the feature will be too hard to discover in that case, since it is not apparent that the symbol can be clicked. Also, if somebody clicked it by accident (maybe not likely?) they would not know how to get connected again. |
if(networkActive) | ||
ui->numberOfConnections->setText(QString::number(count)); | ||
else | ||
ui->numberOfConnections->setText(tr("%1 (Disabled)").arg(count)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest to use something like:
ui->numberOfConnections->setText(QString::number(count) + " (" + tr("Network activity disabled") + ")");
This has the advantage to re-use the string (and translation of) Network activity disabled
without the need for another translation + it is clearer than just (Disabled)
.
The button |
I've updated the patches: 1) ToggleNetworkActive() renamed to SetNetworkActive(). I think this name makes more sense and is more consistent with naming of other functions. 2) SetNetworkActive() prints log ouput if fDebug is set, 3) ClientModel now has a method to control network activity state setNetworkActive(). This is used by RPCConsole. 4) The string in RPCConsole is the same as the string in the status bar tooltip so they can share translations. I'll look into the rest of the suggestions on the gui later. |
@@ -199,3 +199,14 @@ Value getaddednodeinfo(const Array& params, bool fHelp) | |||
return ret; | |||
} | |||
|
|||
Value togglenetwork(const Array& params, bool fHelp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to query via RPC if the network was disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not currently. Do you think this could be returned in "getinfo" or should there rather be a separate command? Perhaps togglenetwork itself should return the new state as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The state is returned now in "getinfo" and as the return value of "togglenetwork".
I'm no core-developer, but did some Qt things, so thanks for your update. I like the pull and when I have more time I'll compile it and see how it feels when using it :). @laanwj What do you think? |
I'm OK with the GUI code changes -- nice work. About the general idea:
|
Use case: Sometimes the bitcoin client can put a lot of load on the internet connection of the user resulting in a high latency for other internet activities. This may be acceptable for the user most of the time, but in some cases the user temporarily needs a low latency connection. In this case the only option currently is to close the client and reopen it later, which can take quite a while and create a lot of disk activity when the block chain is reloaded. Being able to temporarily close all connections provides a solution for this. |
Update: 1) RPC commands togglenetwork and getinfo return info on current network state. 2) Signal about network active state change is sent with a separate signal NotifyNetworkActiveChanged. This means that the gui will update immediately when the button is clicked. I've looked into adding the suggestion of having the connection symbol toggle the network state as well, however the Qt label does not allow mouse clicks to be detected. This could be worked around by implementing a custom subclass of label. |
I also think this is nice during IBD to get a new peer from which the client is downloading it's blocks. |
Can transactions still be sent while the network activity is switched off? It might be nice to be able to do this still at least, and optionally download new blocks too. (I recently added an "-antisocial" command line option which stops transaction relaying due to using a limited internet connection here which charges per MB, but a toggleable version of this would be much nicer - for when I switch to a different internet provider). |
@rebroad Ok, but that seems to require a different implementation. This patch simply cuts all connections, so I think your proposal is better suited for another issue. Also it seems that any kind of throttling or filtering of the connections eventually end up being too controversial to get anywhere (e.g. #273). |
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/b1ff0108f94a2a6365f9957708041269c63a351c for binaries and test log. |
IMO the current implementation of simply cutting the whole connection is best. It is also clearest to the user. Once you start making exceptions there's a large chance of introducing bugs or even network-breaking bugs, which are why such features are unlikely to make it into the reference client. |
@sipa @gavinandresen I'm asking myself, if the core-devs are willing to pull such a thing or if this should be GUI-only? |
Needs rebase. |
@luke-jr I will be happy to do rebases if this has a chance of actually being pulled but so far I'm not sure. Whet do you think? |
Testing is our bottleneck. This gives use Yet Another State to test, which is a bad thing because it just makes one more thing that can break. I'm against it. |
Haven't tested but the code changes to core look sane to me. |
I still like the idea! |
Rebased. |
@gavinandresen What do you think about that? Would be sad to just forget about it :). |
I missed the rebase, I'll test it some. |
@jonls could you rebase once more? |
@jonasschnelli done |
Added the function SetNetworkActive() which when called with argument set to false disconnects all nodes and sets the flag fNetworkActive to false. As long as this flag is false no new connections are attempted and no incoming connections are accepted. Network activity is reenabled by calling the function with argument true.
RPC command "togglenetwork" toggles network and returns new state after command. RPC command "getinfo" returns "networkactive" field in output.
Add getNetworkActive()/setNetworkActive() method to client model. Send network active status through NotifyNetworkActiveChanged. Indicate in tool tip of gui status bar network indicator whether network activity is disabled. Indicate in debug window whether network activity is disabled and add button to allow user to toggle network activity state.
What is the current state for this? |
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/22570316ad74df51e459c17d72e02ce76e03751d for binaries and test log. |
Needs testing, and a test plan that has tests like: Toggle networking on and off as rapidly as possible eleven times using the GUI. EXPECT: no crashes, always ends up in properly connected or disconnected state. Toggle networking on and off using the JSON-RPC call. EXPECT: no crashes... Toggle networking off, send a transaction. EXPECT: ??? what is reasonable to expect here? Message to user? Transaction gets broadcast when network is turned on or client restarted ??? |
Closing due to inactivity. Feel free to bring back a rebased version that has a test plan. |
@jonls Do you plan to update this? |
@luke-jr No, I have no plans to update it. |
Allow the network activity of the client to be toggled temporarily.
When network activity is disabled the client will close all connections, stop accepting inbound connections, and stop opening new outbound connections, until the network activity is reenabled. The first commit adds this feature to the core, accessed through SetNetworkActive().
Second commit adds an RPC command "togglenetwork" to toggle on/off.
Third commit adds further connections to the gui. When the network activity is disabled the status bar and the debug window will show this. In addition the commit adds a button to the debug window to toggle network activity.
Open issues: