From b40b4c53443bf1a7b99b721d0aa2cbbf65d1157c Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Tue, 17 Jan 2012 16:02:59 -0500 Subject: [PATCH] differentiate between incoming and outgoing connections in log messages --- p2pool/main.py | 3 ++- p2pool/p2p.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/p2pool/main.py b/p2pool/main.py index 11d8b84..b557559 100644 --- a/p2pool/main.py +++ b/p2pool/main.py @@ -771,7 +771,7 @@ def main(args, net, datadir_path): stale_prop = p2pool_data.get_average_stale_prop(tracker, current_work.value['best_share_hash'], min(720, height)) real_att_s = att_s / (1 - stale_prop) my_att_s = real_att_s*weights.get(my_script, 0)/total_weight - this_str = 'Pool: %sH/s in %i shares (%i/%i verified) Recent: %.02f%% >%sH/s Shares: %i (%i orphan, %i dead) Peers: %i' % ( + this_str = 'Pool: %sH/s in %i shares (%i/%i verified) Recent: %.02f%% >%sH/s Shares: %i (%i orphan, %i dead) Peers: %i (%i incoming)' % ( math.format(int(real_att_s)), height, len(tracker.verified.shares), @@ -782,6 +782,7 @@ def main(args, net, datadir_path): stale_orphan_shares, stale_doa_shares, len(p2p_node.peers), + sum(1 for peer in p2p_node.peers.itervalues() if peer.incoming), ) + (' FDs: %i R/%i W' % (len(reactor.getReaders()), len(reactor.getWriters())) if p2pool.DEBUG else '') this_str += '\nAverage time between blocks: %.2f days' % ( 2**256 / current_work.value['bits'].target / real_att_s / (60 * 60 * 24), diff --git a/p2pool/p2p.py b/p2pool/p2p.py index 9e04941..6b60200 100644 --- a/p2pool/p2p.py +++ b/p2pool/p2p.py @@ -16,8 +16,9 @@ class Protocol(bitcoin_p2p.BaseProtocol): version = 2 sub_version = p2pool.__version__ - def __init__(self, node): + def __init__(self, node, incoming): self.node = node + self.incoming = incoming self._prefix = self.node.net.PREFIX @@ -242,7 +243,7 @@ class ServerFactory(protocol.ServerFactory): def buildProtocol(self, addr): if len(self.conns) >= self.max_conns: return None - p = Protocol(self.node) + p = Protocol(self.node, True) p.factory = self return p @@ -279,7 +280,7 @@ class ClientFactory(protocol.ClientFactory): self.running = False def buildProtocol(self, addr): - p = Protocol(self.node) + p = Protocol(self.node, False) p.factory = self return p @@ -388,7 +389,7 @@ class Node(object): raise ValueError('already have peer') self.peers[conn.nonce] = conn - print 'Connected to peer %s:%i. p2pool version: %i %r' % (conn.addr[0], conn.addr[1], conn.other_version, conn.other_sub_version) + print '%s connection to peer %s:%i established. p2pool version: %i %r' % ('Incoming' if conn.incoming else 'Outgoing', conn.addr[0], conn.addr[1], conn.other_version, conn.other_sub_version) def lost_conn(self, conn): if conn.nonce not in self.peers: -- 1.7.1