Don't create connection to blacklisted peer

This commit is contained in:
shortcutme 2018-01-27 12:19:37 +01:00
parent cc48a0ad86
commit fd14a4ac80
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -1,12 +1,12 @@
import logging import logging
import time import time
import sys import sys
from collections import defaultdict
import gevent import gevent
import msgpack import msgpack
from gevent.server import StreamServer from gevent.server import StreamServer
from gevent.pool import Pool from gevent.pool import Pool
from collections import defaultdict
from Debug import Debug from Debug import Debug
from Connection import Connection from Connection import Connection
@ -14,6 +14,7 @@ from Config import config
from Crypt import CryptConnection from Crypt import CryptConnection
from Crypt import CryptHash from Crypt import CryptHash
from Tor import TorManager from Tor import TorManager
from Site import SiteManager
class ConnectionServer: class ConnectionServer:
@ -23,6 +24,7 @@ class ConnectionServer:
self.last_connection_id = 1 # Connection id incrementer self.last_connection_id = 1 # Connection id incrementer
self.log = logging.getLogger("ConnServer") self.log = logging.getLogger("ConnServer")
self.port_opened = None self.port_opened = None
self.peer_blacklist = SiteManager.peer_blacklist
if config.tor != "disabled": if config.tor != "disabled":
self.tor_manager = TorManager(self.ip, self.port) self.tor_manager = TorManager(self.ip, self.port)
@ -137,6 +139,10 @@ class ConnectionServer:
if create: # Allow to create new connection if not found if create: # Allow to create new connection if not found
if port == 0: if port == 0:
raise Exception("This peer is not connectable") raise Exception("This peer is not connectable")
if (ip, port) in self.peer_blacklist:
raise Exception("This peer is blacklisted")
try: try:
if ip.endswith(".onion") and self.tor_manager.start_onions and site: # Lock connection to site if ip.endswith(".onion") and self.tor_manager.start_onions and site: # Lock connection to site
connection = Connection(self, ip, port, target_onion=site_onion) connection = Connection(self, ip, port, target_onion=site_onion)