def handle_incoming (self, packet): # request: packet = (kind, qid, path, params) # reply: packet = (kind, qid, error, result) args, plen = decode (packet) try: args, plen = decode (packet) except: LOG ('exception decoding packet, closing rpc', packet) self.conn.close() assert (plen == len(packet)) if args[0] == KIND_REQUEST: self.handle_request (*args[1:]) elif args[0] == KIND_REPLY: self.handle_reply (*args[1:]) else: self.handle_kind (args)
def go(G, s): try: while 1: # what are the per-txn size limits? pktlen = s.recv_exact(4) if not pktlen: break else: pktlen, = struct.unpack('>I', pktlen) packet = s.recv_exact(pktlen) data, size = decode(packet) assert size == pktlen [index, block_timestamp, raw_tx, lock_scripts] = data tx = TX() tx.unpack(raw_tx) result = True for i in range(len(tx.inputs)): lock_script = lock_scripts[i] try: tx.verify(i, lock_script, block_timestamp) except SystemError: result = False pkt = encode((result, index)) s.writev([struct.pack('>I', len(pkt)), pkt]) except EOFError: pass coro.set_exit()
def go (G, s): try: while 1: # what are the per-txn size limits? pktlen = s.recv_exact (4) if not pktlen: break else: pktlen, = struct.unpack ('>I', pktlen) packet = s.recv_exact (pktlen) data, size = decode (packet) assert size == pktlen [index, block_timestamp, raw_tx, lock_scripts] = data tx = TX() tx.unpack (raw_tx) result = True for i in range (len (tx.inputs)): lock_script = lock_scripts[i] try: tx.verify (i, lock_script, block_timestamp) except SystemError: result = False pkt = encode ((result, index)) s.writev ([struct.pack ('>I', len(pkt)), pkt]) except EOFError: pass coro.set_exit()
def handle_incoming(self, packet): # request: packet = (kind, qid, path, params) # reply: packet = (kind, qid, error, result) args, plen = decode(packet) try: args, plen = decode(packet) except: LOG('exception decoding packet, closing rpc', packet) self.conn.close() assert (plen == len(packet)) if args[0] == KIND_REQUEST: self.handle_request(*args[1:]) elif args[0] == KIND_REPLY: self.handle_reply(*args[1:]) else: self.handle_kind(args)
def go (self): while 1: job_id, tx, timestamp, locks = self.fifo.pop() pkt = encode ([job_id, timestamp, tx.raw, locks]) self.sock.writev ([struct.pack ('>I', len(pkt)), pkt]) pktlen = self.sock.recv_exact (4) if not pktlen: break else: pktlen, = struct.unpack ('>I', pktlen) pkt = self.sock.recv_exact (pktlen) (result, index), size = decode (pkt) assert (pktlen == size) G.pool.retire (index, result)
def gen_log (f, limit=10000, follow=False): s = Sync() s.resync (f, limit) while 1: size, = struct.unpack ('>I', f.read (4)) block = f.read (size) if len(block) != size: break try: (timestamp, info), size = decode (block) except Exception: s.resync (f, limit) continue yield size, timestamp / 1000000.0, info if follow: magic = await (f) else: magic = f.read (4) if not magic: break elif magic != Sync.magic: s.resync (f, limit)
if len(ob) > 500: if args.big: return ob.encode ('hex') else: return '<large>' elif len(ob) == 32: return ob[::-1].encode ('hex') return ob else: return ob p = argparse.ArgumentParser() p.add_argument ('-b', '--big', action='store_true', help="show large strings", default=False) args = p.parse_args() s = Sync() s.resync (sys.stdin) while 1: size, = struct.unpack ('>I', sys.stdin.read (4)) block = sys.stdin.read (size) (timestamp, info), size = decode (block) timestamp /= 1000000.0 info = [frob(x) for x in info] print time.ctime (timestamp), info magic = sys.stdin.read (4) if not magic: break elif magic != Sync.magic: s.resync (sys.stdin)