twisted.web.client.sendGetID

Here are the examples of the python api twisted.web.client.sendGetID taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

Example 1

Project: flud Source File: FludCommUtil.py
def updateNode(client, config, host, port, nKu=None, nID=None):
    """
    Updates this node's view of the given node.  This includes updating
    the known-nodes record, trust, and routing table information
    """
    def updateNodeFail(failure, host, port):
        logging.getLogger('flud').log(logging.INFO,
                "couldn't get nodeID from %s:%d: %s" % (host, port, failure))

    def callUpdateNode(nKu, client, config, host, port, nID):
        return updateNode(client, config, host, port, nKu, nID)

    if isinstance(nID, long):
        nID = "%064x" % nID

    if nKu is None:
        #print "updateNode, no nKu"
        if nID is None:
            d = client.sendGetID(host, port)
            d.addCallback(callUpdateNode, client, config, host, port, nID)
            d.addErrback(updateNodeFail, host, port)
        else:
            #print "updateNode, no nKu but got a nID"
            if config.nodes.has_key(nID):
                return updateNode(client, config, host, port, 
                        FludRSA.importPublicKey(config.nodes[nID]['Ku']), nID)
            elif updateNodePendingGETID.has_key(nID):
                pass
            else:
                #print "updateNode, sending GETID"
                updateNodePendingGETID[nID] = True
                d = client.sendGetID(host, port)
                d.addCallback(callUpdateNode, client, config, host, port, nID)
                d.addErrback(updateNodeFail, host, port)
    elif isinstance(nKu, FludRSA):
        #print "updateNode with nKu"
        if updateNodePendingGETID.has_key(nID):
            del updateNodePendingGETID[nID]
        if nID == None:
            nID = nKu.id()
        elif nID != nKu.id():
            raise ValueError("updateNode: given nID doesn't match given nKu."
                    " '%s' != '%s'" % (nID, nKu.id()))
            # XXX: looks like an imposter -- instead of raising, mark host:port
            # pair as bad (trust-- on host:port alone, since we don't know id).
        if config.nodes.has_key(nID) == False:
            config.addNode(nID, host, port, nKu)
        # XXX: trust
        # routing
        node = (host, port, long(nID, 16), nKu.exportPublicKey()['n'])
        replacee = config.routing.updateNode(node)
        #logger.info("knownnodes now: %s" % config.routing.knownNodes())
        #print "knownnodes now: %s" % config.routing.knownNodes()
        if replacee != None:
            logging.getLogger('flud').info(
                    "determining if replacement in ktable is needed")
            s = SENDGETID(replacee[0], replacee[1])
            s.addErrback(replaceNode, config.routing, replacee, node)
    else:
        #print "updateNode nKu=%s, type=%s" % (nKu, type(nKu))
        logging.getLogger('flud').warn( 
                "updateNode can't update without a public key or nodeID")
        frame = inspect.currentframe()
        # XXX: try/except here for debugging only
        try:
            stack = inspect.stack()
            for i in stack:
                print "from %s:%d" % (i[1], i[2])
        except:
            print "couldn't get stack trace"
        raise ValueError("updateNode needs an nKu of type FludRSA"
            " (received %s) or an nID of type long or str (received %s)" 
            % (type(nKu), type(nID)))