From c77981995a914966d3309cb0eb1d295209ae8c4e Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Thu, 15 Dec 2011 05:47:40 -0500 Subject: [PATCH] made ReplyMatcher not resend queries and made the example in bitcoin.p2p handle timeouts --- p2pool/bitcoin/p2p.py | 5 ++++- p2pool/util/deferral.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/p2pool/bitcoin/p2p.py b/p2pool/bitcoin/p2p.py index a6392e7..7bd2f8c 100644 --- a/p2pool/bitcoin/p2p.py +++ b/p2pool/bitcoin/p2p.py @@ -395,7 +395,10 @@ if __name__ == '__main__': @apply @defer.inlineCallbacks def think(): - print (yield (yield factory.getProtocol()).get_block(0x000000000000003aaaf7638f9f9c0d0c60e8b0eb817dcdb55fd2b1964efc5175)) + try: + print (yield (yield factory.getProtocol()).get_block(0x000000000000003aaaf7638f9f9c0d0c60e8b0eb817dcdb55fd2b1964efc5175)) + except defer.TimeoutError: + print "timeout" reactor.stop() reactor.run() diff --git a/p2pool/util/deferral.py b/p2pool/util/deferral.py index 4a5e1a5..738326a 100644 --- a/p2pool/util/deferral.py +++ b/p2pool/util/deferral.py @@ -41,7 +41,8 @@ class ReplyMatcher(object): self.map = {} def __call__(self, id): - self.func(id) + if id not in self.map: + self.func(id) df = defer.Deferred() def timeout(): self.map[id].remove((df, timer)) -- 1.7.1