-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block requests from Tor to Marketplace.
- Loading branch information
Showing
6 changed files
with
59 additions
and
3 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from caravel.utils.principals import Principal, Device | ||
from caravel.utils.emails import send_mail | ||
from caravel.utils.emails import send_mail | ||
from caravel.utils.tor import TorDetector |
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,37 @@ | ||
import threading | ||
import time | ||
import urllib | ||
import re | ||
|
||
EXIT_NODES_URL = "https://check.torproject.org/exit-addresses" | ||
|
||
class TorDetector(object): | ||
def __init__(self): | ||
""" | ||
Initializes this Tor detector object. | ||
""" | ||
|
||
self.lock = threading.Lock() | ||
self.exit_nodes = [] | ||
self.last_update = None | ||
|
||
def _update(self): | ||
""" | ||
Updates the list of Tor exit nodes from the Tor project. | ||
""" | ||
|
||
if not self.last_update or (time.time() - self.last_update) > 3600: | ||
data = urllib.urlopen(EXIT_NODES_URL).read() | ||
matches = re.finditer(r'ExitAddress ([^ ]+)', data) | ||
|
||
self.exit_nodes = set([x.group(1) for x in matches]) | ||
self.last_update = time.time() | ||
|
||
def is_tor_exit_node(self, ip_address): | ||
""" | ||
Returns True if the given IP address is a Tor exit node. | ||
""" | ||
|
||
with self.lock: | ||
self._update() | ||
return ip_address in self.exit_nodes |
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 |
---|---|---|
|
@@ -15,4 +15,3 @@ indexes: | |
- name: keywords | ||
- name: posted_at | ||
direction: desc | ||
|