Skip to content

Instantly share code, notes, and snippets.

@devos50
Created February 11, 2018 10:40
Show Gist options
  • Save devos50/be0a660b592a1e44d2762a4dcfdb5885 to your computer and use it in GitHub Desktop.
Save devos50/be0a660b592a1e44d2762a4dcfdb5885 to your computer and use it in GitHub Desktop.
Hidden services diff
diff --git a/ipv8/messaging/anonymization/hidden_services.py b/ipv8/messaging/anonymization/hidden_services.py
index 3c52520..88ed2f3 100644
--- a/ipv8/messaging/anonymization/hidden_services.py
+++ b/ipv8/messaging/anonymization/hidden_services.py
@@ -23,11 +23,10 @@ TUNNEL_PREFIX = "ffffffff".decode("HEX")
class HiddenTunnelCommunity(TunnelCommunity):
def __init__(self, *args, **kwargs):
+ self.dht_provider = kwargs.pop('dht_provider', None)
+ self.service_callbacks = kwargs.pop('service_callbacks', {})
super(HiddenTunnelCommunity, self).__init__(*args, **kwargs)
- self.dht_provider = kwargs.get('dht_provider', None)
- self.service_callbacks = kwargs.get('service_callbacks', {})
-
self.session_keys = {}
self.my_intro_points = defaultdict(list)
@@ -227,7 +226,7 @@ class HiddenTunnelCommunity(TunnelCommunity):
source_address,
payload.info_hash))
- self.tunnel_data(relay_circuit, source_address, u"key-request",
+ self.tunnel_data(relay_circuit, self.my_estimated_wan, u"key-request",
KeyRequestPayload(cache.number, payload.info_hash))
else:
# The seeder responds with keys back to the intropoint
@@ -244,12 +243,13 @@ class HiddenTunnelCommunity(TunnelCommunity):
def check_key_response(self, payload):
self.logger.info("Check key response")
request = self.request_cache.get(u"key-request", payload.identifier)
- return not not request
+ return request
def on_key_response(self, source_address, data, circuit_id=''):
dist, payload = self._ez_unpack_noauth(KeyResponsePayload, data)
if not self.check_key_response(payload):
+ self.logger.error("Key response packet invalid!")
return
if not circuit_id.startswith(u"circuit_"):
@@ -300,7 +300,7 @@ class HiddenTunnelCommunity(TunnelCommunity):
self.logger.info('On create e2e: forward message because received over socket')
relay_circuit = self.intro_point_for[payload.info_hash]
- self.tunnel_data(relay_circuit, self.my_estimated_wan, u'create-e2e', payload)
+ self.tunnel_data(relay_circuit, source_address, u'create-e2e', payload)
else:
self.logger.info('On create e2e: create rendezvous point')
self.create_rendezvous_point(self.hops[payload.info_hash],
@@ -353,6 +353,8 @@ class HiddenTunnelCommunity(TunnelCommunity):
# Since it is the seeder that chose the rendezvous_point, we're essentially losing 1 hop of anonymity
# at the downloader end. To compensate we add an extra hop.
required_exit = Peer(rp_info[2], rp_info[:2])
+ self.logger.info("My address: %s:%d", self.my_estimated_wan)
+ self.logger.info("Required exit: %s:%d", required_exit)
self.create_circuit(self.hops[cache.info_hash] + 1,
CIRCUIT_TYPE_RENDEZVOUS,
callback=lambda circuit, cookie=cookie, session_keys=session_keys,
@@ -439,6 +441,8 @@ class HiddenTunnelCommunity(TunnelCommunity):
return self.service_callbacks[service]
def create_introduction_point(self, info_hash, amount=1):
+ self.logger.info("Creating %d introduction points", amount)
+
# Create a separate key per infohash
if info_hash not in self.session_keys:
self.session_keys[info_hash] = self.crypto.generate_key(u"curve25519")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment