Rev2054, Outgoing socket binding support
This commit is contained in:
parent
c5629adf23
commit
fae5d22e86
4 changed files with 25 additions and 4 deletions
|
@ -10,7 +10,7 @@ class Config(object):
|
|||
|
||||
def __init__(self, argv):
|
||||
self.version = "0.5.4"
|
||||
self.rev = 2050
|
||||
self.rev = 2054
|
||||
self.argv = argv
|
||||
self.action = None
|
||||
self.config_file = "zeronet.conf"
|
||||
|
|
|
@ -98,8 +98,7 @@ class Connection(object):
|
|||
raise Exception("Can't connect to onion addresses, no Tor controller present")
|
||||
self.sock = self.server.tor_manager.createSocket(self.ip, self.port)
|
||||
else:
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.connect((self.ip, int(self.port)))
|
||||
self.sock = socket.create_connection((self.ip, int(self.port)))
|
||||
|
||||
# Implicit SSL
|
||||
if self.cert_pin:
|
||||
|
|
|
@ -116,7 +116,7 @@ if config.stack_size:
|
|||
if config.msgpack_purepython:
|
||||
os.environ["MSGPACK_PUREPYTHON"] = "True"
|
||||
|
||||
# Socks Proxy monkey patch
|
||||
# Socket monkey patch
|
||||
if config.proxy:
|
||||
from util import SocksProxy
|
||||
import urllib2
|
||||
|
@ -132,6 +132,13 @@ elif config.tor == "always":
|
|||
config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost
|
||||
SocksProxy.monkeyPatch(*config.tor_proxy.split(":"))
|
||||
config.disable_udp = True
|
||||
elif config.bind:
|
||||
bind = config.bind
|
||||
if ":" not in config.bind:
|
||||
bind += ":0"
|
||||
from util import helper
|
||||
helper.socketBindMonkeyPatch(*bind.split(":"))
|
||||
|
||||
# -- Actions --
|
||||
|
||||
|
||||
|
|
|
@ -179,3 +179,18 @@ def timerCaller(secs, func, *args, **kwargs):
|
|||
|
||||
def timer(secs, func, *args, **kwargs):
|
||||
gevent.spawn_later(secs, timerCaller, secs, func, *args, **kwargs)
|
||||
|
||||
|
||||
def create_connection(address, timeout=None, source_address=None):
|
||||
if address in config.ip_local:
|
||||
sock = socket.create_connection_original(address, timeout, source_address)
|
||||
else:
|
||||
sock = socket.create_connection_original(address, timeout, socket.bind_addr)
|
||||
return sock
|
||||
|
||||
def socketBindMonkeyPatch(bind_ip, bind_port):
|
||||
import socket
|
||||
logging.info("Monkey patching socket to bind to: %s:%s" % (bind_ip, bind_port))
|
||||
socket.bind_addr = (bind_ip, int(bind_port))
|
||||
socket.create_connection_original = socket.create_connection
|
||||
socket.create_connection = create_connection
|
||||
|
|
Loading…
Reference in a new issue