-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the beginnings of anti-DoS resource scheduling.
This adds code that takes effect if a node gets completely full (this should never happen unless there's an attack or the number of nodes falls dangerously low). Peers now have a priority that attempts to estimate their importance. Currently it is just based on IP address. The default score is zero. In future it may take into account things like how many blocks were relayed, etc. When a node reaches its max connection slots, it will attempt to find a peer with a lower priority than the one trying to connect and disconnect it, to stay below the max connection limit. Peer priorities are based on matching the connecting IP against a set of IP groups. For now, the only IP group is one that gives Tor exits a score of -10. This is to address DoS attacks that are being reported on the main network in which an attacker builds many connections via Tor to use up all the connection slots and jam the node for clearnet users. It's a more robust approach than simply banning abused proxies altogether. The code has both a static list and a list that's downloaded when the node starts. Other anonymizing proxy networks that are attractive to DoS attackers may also be added as alternative IP groups, as a quick fix. Eventually peer priority can be calculated in a more free floating and dynamic manner and the hardcoded IP approach may become unneeded.
- Loading branch information
Showing
15 changed files
with
1,577 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| # Script to generate a C++ source file containing known Tor exits. | ||
| # This is used to help nodes treat Tor traffic homogenously. | ||
|
|
||
| import urllib2, time | ||
|
|
||
| data = urllib2.urlopen("https://check.torproject.org/exit-addresses").read() | ||
| exitlines = [line for line in data.split('\n') if line.startswith("ExitAddress")] | ||
| ipstrs = [line.split()[1] for line in exitlines] | ||
| ipstrs.sort() | ||
|
|
||
| contents = """// Generated at %s by gen-tor-ips.py: DO NOT EDIT | ||
| static const char *pszTorExits[] = { | ||
| "0.1.2.3", // For unit testing | ||
| %s | ||
| NULL | ||
| }; | ||
| """ % (time.asctime(), "\n".join([" \"%s\"," % ip for ip in ipstrs])) | ||
|
|
||
| print contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package=curl | ||
| $(package)_version=7.43.0 | ||
| $(package)_file_name=$(package)-$($(package)_version).tar.gz | ||
| $(package)_download_path=http://curl.haxx.se/download | ||
| $(package)_sha256_hash=1a084da1edbfc3bd632861358b26af45ba91aaadfb15d6482de55748b8dfc693 | ||
| $(package)_dependencies=openssl | ||
|
|
||
| define $(package)_set_vars | ||
| $(package)_config_opts=--disable-shared --with-ssl | ||
| endef | ||
|
|
||
| define $(package)_config_cmds | ||
| $($(package)_autoconf) | ||
| endef | ||
|
|
||
| define $(package)_build_cmds | ||
| $(MAKE) | ||
| endef | ||
|
|
||
| define $(package)_stage_cmds | ||
| $(MAKE) DESTDIR=$($(package)_staging_dir) install | ||
| endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
73c9efeThere 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.
Someone was complaining about lack of peer review of this feature on the mailing list, so I took a look at it. Now you have one more.
It looks fine. I just did some nitpicking.
If the unittest framework allows, I think it would be nice to have test that checks that InitTorIPGroups is not called if any of the conditions we don't want it in exist (disableipprio, !fListen, proxy for ipv4 or ipv6 or tor)
73c9efeThere 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.
Thanks. It was actually reviewed by Gavin, a Tor developer, and I got some comments via private email too, but more is always welcome.
The Core/XT code base is a bit hard to unit test because so much state is in global variables and there's no easy way to reset things. But yeah testing the init path would be a good improvement too.