def fragment(f, **kwargs):
try:
- return f(**kwargs)
+ f(**kwargs)
except p2protocol.TooLong:
fragment(f, **dict((k, v[:len(v)//2]) for k, v in kwargs.iteritems()))
- return fragment(f, **dict((k, v[len(v)//2:]) for k, v in kwargs.iteritems()))
+ fragment(f, **dict((k, v[len(v)//2:]) for k, v in kwargs.iteritems()))
class Protocol(p2protocol.Protocol):
max_remembered_txs_size = 2500000
self.connected2 = False
def connectionMade(self):
- p2protocol.Protocol.connectionMade(self)
-
self.factory.proto_made_connection(self)
self.connection_lost_event = variable.Event()
max_id=2**256,
func=lambda id, hashes, parents, stops: self.send_sharereq(id=id, hashes=hashes, parents=parents, stops=stops),
timeout=15,
- on_timeout=self.transport.loseConnection,
+ on_timeout=self.disconnect,
)
self.remote_tx_hashes = set() # view of peer's known_txs # not actually initially empty, but sending txs instead of tx hashes won't hurt
def _connect_timeout(self):
self.timeout_delayed = None
print 'Handshake timed out, disconnecting from %s:%i' % self.addr
- self.transport.loseConnection()
+ self.disconnect()
def packetReceived(self, command, payload2):
try:
def badPeerHappened(self):
if p2pool.DEBUG:
print "Bad peer banned:", self.addr
- self.transport.loseConnection()
+ self.disconnect()
if self.transport.getPeer().host != '127.0.0.1': # never ban localhost
self.node.bans[self.transport.getPeer().host] = time.time() + 60*60
def _timeout(self):
self.timeout_delayed = None
print 'Connection timed out, disconnecting from %s:%i' % self.addr
- self.transport.loseConnection()
+ self.disconnect()
message_version = pack.ComposedType([
('version', pack.IntType(32)),
if nonce in self.node.peers:
if p2pool.DEBUG:
print 'Detected duplicate connection, disconnecting from %s:%i' % self.addr
- self.transport.loseConnection()
+ self.disconnect()
return
self.nonce = nonce
self.node.handle_shares([p2pool_data.load_share(share, self.node.net, self.addr) for share in shares if share['type'] >= 9], self)
def sendShares(self, shares, tracker, known_txs, include_txs_with=[]):
- if not shares:
- return defer.succeed(None)
-
if self.other_version >= 8:
tx_hashes = set()
for share in shares:
fragment(self.send_remember_tx, tx_hashes=[x for x in hashes_to_send if x in self.remote_tx_hashes], txs=[known_txs[x] for x in hashes_to_send if x not in self.remote_tx_hashes])
- res = fragment(self.send_shares, shares=[share.as_share() for share in shares])
+ fragment(self.send_shares, shares=[share.as_share() for share in shares])
if self.other_version >= 8:
- res = self.send_forget_tx(tx_hashes=hashes_to_send)
+ self.send_forget_tx(tx_hashes=hashes_to_send)
self.remote_remembered_txs_size -= sum(100 + bitcoin_data.tx_type.packed_size(known_txs[x]) for x in hashes_to_send)
-
- return res
message_sharereq = pack.ComposedType([
for tx_hash in tx_hashes:
if tx_hash in self.remembered_txs:
print >>sys.stderr, 'Peer referenced transaction twice, disconnecting'
- self.transport.loseConnection()
+ self.disconnect()
return
if tx_hash in self.node.known_txs_var.value:
break
else:
print >>sys.stderr, 'Peer referenced unknown transaction %064x, disconnecting' % (tx_hash,)
- self.transport.loseConnection()
+ self.disconnect()
return
self.remembered_txs[tx_hash] = tx
tx_hash = bitcoin_data.hash256(bitcoin_data.tx_type.pack(tx))
if tx_hash in self.remembered_txs:
print >>sys.stderr, 'Peer referenced transaction twice, disconnecting'
- self.transport.loseConnection()
+ self.disconnect()
return
if tx_hash in self.node.known_txs_var.value and not warned: