def querySeed(self, list_seed_pubkey): """ Query an HTTP seed and return a `list` if (ip, port) `tuple` pairs. Args: Receives a list of one or more tuples Example [(seed, pubkey)] seed: A `string` consisting of "ip:port" or "hostname:port" pubkey: The hex encoded public key to verify the signature on the response """ nodes = [] if not list_seed_pubkey: self.log.error('failed to query seed {0} from ob.cfg'.format(list_seed_pubkey)) return nodes else: for sp in list_seed_pubkey: seed, pubkey = sp try: self.log.info("querying %s for peers" % seed) c = httplib.HTTPConnection(seed) c.request("GET", "/") response = c.getresponse() self.log.debug("Http response from %s: %s, %s" % (seed, response.status, response.reason)) data = response.read() reread_data = data.decode("zlib") proto = peers.PeerSeeds() proto.ParseFromString(reread_data) for peer in proto.serializedNode: n = objects.Node() n.ParseFromString(peer) tup = (str(n.nodeAddress.ip), n.nodeAddress.port) nodes.append(tup) verify_key = nacl.signing.VerifyKey(pubkey, encoder=nacl.encoding.HexEncoder) verify_key.verify("".join(proto.serializedNode), proto.signature) self.log.info("%s returned %s addresses" % (seed, len(nodes))) except Exception, e: self.log.error("failed to query seed: %s" % str(e)) return nodes
def initTable(results): nodes = [] for addr, result in results.items(): if result[0]: n = objects.Node() try: n.ParseFromString(result[1][0]) pubkey = n.signedPublicKey[len(n.signedPublicKey) - 32:] verify_key = nacl.signing.VerifyKey(pubkey) verify_key.verify(n.signedPublicKey) h = nacl.hash.sha512(n.signedPublicKey) hash_pow = h[64:128] if int(hash_pow[:6], 16) >= 50 or hexlify( n.guid) != h[:40]: raise Exception('Invalid GUID') nodes.append( Node(n.guid, addr[0], addr[1], n.signedPublicKey)) except Exception: self.log.msg("Bootstrap node returned invalid GUID") spider = NodeSpiderCrawl(self.protocol, self.node, nodes, self.ksize, self.alpha) return spider.find()
def querySeed(self, list_seed_pubkey): """ Query an HTTP seed for known vendors and save the vendors to the db. Args: Receives a list of one or more tuples Example [(seed, pubkey)] seed: A `string` consisting of "ip:port" or "hostname:port" pubkey: The hex encoded public key to verify the signature on the response """ for sp in list_seed_pubkey: seed, pubkey = sp try: self.log.debug("querying %s for vendors" % seed) c = httplib.HTTPConnection(seed) c.request("GET", "/?type=vendors") response = c.getresponse() self.log.debug("Http response from %s: %s, %s" % (seed, response.status, response.reason)) data = response.read() reread_data = data.decode("zlib") proto = peers.PeerSeeds() proto.ParseFromString(reread_data) verify_key = nacl.signing.VerifyKey( pubkey, encoder=nacl.encoding.HexEncoder) verify_key.verify("".join(proto.serializedNode), proto.signature) v = self.db.VendorStore() for peer in proto.serializedNode: try: n = objects.Node() n.ParseFromString(peer) v.save_vendor(n.guid.encode("hex"), peer) except Exception: pass except Exception, e: self.log.error("failed to query seed: %s" % str(e))
def parse_results(values): if values is not None: for v in values: try: val = Value() val.ParseFromString(v) n = objects.Node() n.ParseFromString(val.serializedData) node_to_ask = Node(n.guid, n.nodeAddress.ip, n.nodeAddress.port, n.publicKey, None if not n.HasField("relayAddress") else (n.relayAddress.ip, n.relayAddress.port), n.natType, n.vendor) if n.guid == KeyChain(self.factory.db).guid: proto = self.factory.db.listings.get_proto() l = Listings() l.ParseFromString(proto) for listing in l.listing: if listing.contract_hash == val.valueKey: respond(listing, node_to_ask) else: self.factory.mserver.get_contract_metadata(node_to_ask, val.valueKey)\ .addCallback(respond, node_to_ask) except Exception: pass