Skip to content

Commit

Permalink
Merge pull request #3 from NielsZeilemaker/coroutines
Browse files Browse the repository at this point in the history
Request cache stuff
  • Loading branch information
Devristo committed Dec 16, 2013
2 parents 6827a6b + a6d5f59 commit 3d1e440
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _try_request(self):
# We use same IP as the single socket, but the port number comes from the newly created UDP listening socket
ip, port = self.single_socket.get_myip(), socket.getsockname()[1]

logger.error("Accepting UDP ASSOCIATE request, direct client to %s:%d", ip, port)
logger.info("Accepting UDP ASSOCIATE request, direct client to %s:%d", ip, port)

response = structs.encode_reply(0x05, 0x00, 0x00, structs.ADDRESS_TYPE_IPV4, ip, port)
self.write(response)
Expand Down
22 changes: 10 additions & 12 deletions Tribler/community/anontunnel/Socks5Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class Socks5Server(object, TunnelObserver):

def __init__(self):
self._tunnel = None
self._accept_incoming = False
Expand All @@ -34,18 +34,18 @@ def __init__(self):

self.routes = {}
self.udp_relays = {}

@property
def accept_incoming(self):
return self._accept_incoming

@accept_incoming.setter
def accept_incoming(self, value):
if value and not self._accept_incoming:
logger.error("Accepting SOCKS5 connections now!")
logger.info("Accepting SOCKS5 connections now!")

if not value:
logger.error("DISCONNECTING SOCKS5 !")
logger.info("DISCONNECTING SOCKS5 !")

for key in self.socket2connection.keys():
self.socket2connection[key].close()
Expand Down Expand Up @@ -89,7 +89,7 @@ def create_udp_relay(self):
:rtype : socket.socket
"""

udp_relay_socket = self.raw_server.create_udpsocket(0,"0.0.0.0")
udp_relay_socket = self.raw_server.create_udpsocket(0, "0.0.0.0")
handler = UdpRelayTunnelHandler(udp_relay_socket, self)
self.raw_server.start_listening_udp(udp_relay_socket, handler)

Expand All @@ -101,9 +101,8 @@ def on_client_udp_packets(self, socket, packets):

self.udp_relays[source_address] = socket

if __debug__:
logger.info("Relaying UDP packets from %s:%d to %s:%d", source_address[0], source_address[1],
request.destination_address, request.destination_port)
logger.debug("Relaying UDP packets from %s:%d to %s:%d", source_address[0], source_address[1],
request.destination_address, request.destination_port)

self.routes[(request.destination_address, request.destination_port)] = source_address
self.tunnel.send_data(
Expand Down Expand Up @@ -140,9 +139,8 @@ def on_tunnel_data(self, community, source_address, data):
if socks5_socket.sendto(encapsulated, destination_address) < len(encapsulated):
logger.error("Not sending package!")

if __debug__:
logger.info("Returning UDP packets from %s to %s using proxy port %d", source_address, destination_address,
socks5_socket.getsockname()[1])
logger.info("Returning UDP packets from %s to %s using proxy port %d", source_address, destination_address,
socks5_socket.getsockname()[1])

def external_connection_made(self, s):
if not self.accept_incoming:
Expand Down Expand Up @@ -192,4 +190,4 @@ def shutdown(self):
tcp_connection.shutdown()

def on_state_change(self, community, state):
self.accept_incoming = state
self.accept_incoming = state
Loading

0 comments on commit 3d1e440

Please sign in to comment.