-
Notifications
You must be signed in to change notification settings - Fork 648
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
Add P2P security options #1764
Add P2P security options #1764
Conversation
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.
AFAICS this resolves only the second point in #659 .
The first point (connect only to trusted peers) should be addressed, too.
I was thinking that listing seed_nodes, along with turning off Other than the connection database, is there another way that connections are built? Do peers automatically ask each other for peers and attempt to connect? Or must they be prompted? I haven't looked, but will do so. |
Peers do talk to each other about possible new peers and try to connect to each other. I don't remember whether one peer will ask other peers for more peers though. |
I can either add code to clear the database, or add code to not use it. Any opinion on which is better? I am thinking clearing the database is better. Who wants a stale database sitting around? Or perhaps someone has a better idea to allow a node operator to only connect to the nodes he wants to. |
The program will add new entries to the in-memory database when running, but not only load data when starting, so only clearing on start doesn't make much sense. Actually we're digging into the details now. I think you can find more from the code. IIRC, according to the p2p protocol, your connected peers may
|
I will add code to not connect if accept-incoming-connections is false.
I will have to research if a response is required, or if I can simply ignore the request without consequences.
That can now be controlled by the ToDo:
|
IMHO, these are outgoing connections but not incoming connections. |
Please use a different flag. These should be two distinct settings. (A node operator might want to have his own internal network of interconnected nodes that only connect to each other, and to some trusted public nodes.) |
How about a new parameter:
|
I began to think about dropped connections to nodes. As it stands now, the parameters could be set up to where they will not get reconnected. I believe that if seed nodes are passed, and I believe that in such a situation, we must store the seed nodes (in memory?), and sort-of "replace" the currently implemented database of addresses with that list. That way reconnects (or perhaps initial connections) can happen if they are on the list. As often happens, the implementation goes deeper than I expected. To make things clear, I will attempt to spec-out the parameters as I see how they should work, and let others review and adjust. |
Posted a spec here: #659 (comment) Please comment there, we'll hammer out the details, and then I'll attempt to implement. Thanks all for the input! |
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.
At a glance the code looks good. However the coding style is not the best, sometime indentation is 2, sometimes it's 3, sometimes it's 4.
@abitmore thank you for the critiques. My apologies for the sloppy spacing. I believe I have corrected that and improved the readability of the code. No real functionality changes, the biggest change here is the moving of the node utility functions into its own file. Please scrutinize. |
I just noticed a thing: if a peer is in our exclude list, we shouldn't ask another peer to check this peer's firewall status, otherwise we'll expose this peer's address. Is this the current behavior? |
... from successfully bound local port. BTW add logging.
Kudos, SonarCloud Quality Gate passed! |
Fixes #659
This PR adds startup options (available via both command line and the
config.ini
configuration file) towitness_node
:p2p-accept-incoming-connections
will allow peers to request a connection to your node (default istrue
). Set tofalse
, your node will not listen for incoming connections. The "accept-incoming-connections" is an existing field in the node configuration file (p2p/node_config.json
), now accessible from the command line and theconfig.ini
configuration file.p2p-inbound-endpoint
, used to specify the node's "external" IP address and listening port when it is behind DNAT or a reverse proxy.p2p-connect-to-new-peers
will allow the node to connect to new peers advertised by other peers (default istrue
). Set tofalse
, the node will ignore all peer advertisements.p2p-advertise-peer-algorithm
determines how peers are selected to be advertised.p2p-advertise-peer-endpoint
andp2p-exclude-peer-endpoint
work in conjunction with some of the peer algorithms.The peer algorithms that can be used are:
nothing
which will respond to the requesting peer with an empty listlist
which will respond with a list of connected peers which are also in the list provided byp2p-advertise-peer-endpoint
exclude_list
which will respond with a list of connected peers which are not in the list provided byp2p-exclude-peer-endpoint
all
, or any other value, or if no peer algorithm is provided, all connected peers are advertised as they were before this enhancement.Other changes and improvements:
1776
) by default, rather than a random port. Ifp2p-endpoint
option is not specified, when the default port is unavailable, the node will listen on a random port.address_message
if it has just requested one200
addresses for eachaddress_message
number_of_failed_connection_attempts
will be halved on successful outbound connectionnetwork_mapper
programfc::ip::address::is_loopback_address()
(127.*.*.*
), fixedis_public_address()
to detect loopback addresses