Skip to content

Commit

Permalink
added --disable-advertise option to disable advertising local IP addr…
Browse files Browse the repository at this point in the history
…ess for incoming connections
  • Loading branch information
forrestv committed Sep 4, 2013
1 parent d4f5cc2 commit b671a57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions p2pool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def parse(host):
addr_store=addrs,
connect_addrs=connect_addrs,
desired_outgoing_conns=args.p2pool_outgoing_conns,
advertise_ip=args.advertise_ip,
)
node.p2p_node.start()

Expand Down Expand Up @@ -413,6 +414,9 @@ def run():
p2pool_group.add_argument('--outgoing-conns', metavar='CONNS',
help='outgoing connections (default: 6)',
type=int, action='store', default=6, dest='p2pool_outgoing_conns')
parser.add_argument('--disable-advertise',
help='''don't advertise local IP address as being available for incoming connections. useful for running a dark node, along with multiple -n ADDR's and --outgoing-conns 0''',
action='store_false', default=True, dest='advertise_ip')

worker_group = parser.add_argument_group('worker interface')
worker_group.add_argument('-w', '--worker-port', metavar='PORT or ADDR:PORT',
Expand Down
13 changes: 8 additions & 5 deletions p2pool/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ def new_dataReceived(data):
self.send_ping(),
random.expovariate(1/100)][-1])

self._stop_thread2 = deferral.run_repeatedly(lambda: [
self.send_addrme(port=self.node.serverfactory.listen_port.getHost().port) if self.node.serverfactory.listen_port is not None else None,
random.expovariate(1/(100*len(self.node.peers) + 1))][-1])
if self.node.advertise_ip:
self._stop_thread2 = deferral.run_repeatedly(lambda: [
self.send_addrme(port=self.node.serverfactory.listen_port.getHost().port) if self.node.serverfactory.listen_port is not None else None,
random.expovariate(1/(100*len(self.node.peers) + 1))][-1])

if best_share_hash is not None:
self.node.handle_share_hashes([best_share_hash], self)
Expand Down Expand Up @@ -424,7 +425,8 @@ def connectionLost(self, reason):
if self.connected2:
self.factory.proto_disconnected(self, reason)
self._stop_thread()
self._stop_thread2()
if self.node.advertise_ip:
self._stop_thread2()
self.connected2 = False
self.factory.proto_lost_connection(self, reason)
if p2pool.DEBUG:
Expand Down Expand Up @@ -581,7 +583,7 @@ def proto_disconnected(self, proto, reason):
self.node.lost_conn(proto, reason)

class Node(object):
def __init__(self, best_share_hash_func, port, net, addr_store={}, connect_addrs=set(), desired_outgoing_conns=10, max_outgoing_attempts=30, max_incoming_conns=50, preferred_storage=1000, known_txs_var=variable.Variable({}), mining_txs_var=variable.Variable({})):
def __init__(self, best_share_hash_func, port, net, addr_store={}, connect_addrs=set(), desired_outgoing_conns=10, max_outgoing_attempts=30, max_incoming_conns=50, preferred_storage=1000, known_txs_var=variable.Variable({}), mining_txs_var=variable.Variable({}), advertise_ip=True):
self.best_share_hash_func = best_share_hash_func
self.port = port
self.net = net
Expand All @@ -590,6 +592,7 @@ def __init__(self, best_share_hash_func, port, net, addr_store={}, connect_addrs
self.preferred_storage = preferred_storage
self.known_txs_var = known_txs_var
self.mining_txs_var = mining_txs_var
self.advertise_ip = advertise_ip

self.traffic_happened = variable.Event()
self.nonce = random.randrange(2**64)
Expand Down

0 comments on commit b671a57

Please sign in to comment.