Beispiel #1
0
    def refreshUser(self, publicKey, callback=None):
        pubKeyData = publicKey.toDER_PublicKey()
        entry = self.d.get(pubKeyData)
        if entry is None:
            entry = _Entry(publicKey)
            self.d[pubKeyData] = entry
        assert entry.state != ES_NOTIFYING
        if entry.state == ES_DEFAULT:
            assert entry.lookupOp is None
            assert entry.notifyOps is None

            def onLookupUser(location):
                self._onLookupUser(entry, location)

            entry.lookupOp = lookupUser(
                publicKey, self.dhtClient, self.nodeTable,
                lambda loc: self._onLookupUser(entry, loc))
            entry.state = ES_LOOKINGUP
            entry.notifyOps = set()

        def doCancel():
            entry.notifyOps.remove(op)

        op = AsyncOp(callback, doCancel)
        entry.notifyOps.add(op)
        return op
Beispiel #2
0
def getLocation( publicKey ) :
    reactor = SelectReactor()
    udpSock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
    udpSock.bind( ('',0) )
    rpcSocket = RPCSocket( udpSock, reactor )
    dhtClient = DHTClient( rpcSocket )
    nodeAddr = ('210.210.1.102',10001)
    nodeTable = NodeTable( [nodeAddr] )
    locList = []
    def onLookup( location ) :
        locList.append( location )
        reactor.stop()
    lookupUser( publicKey, dhtClient, nodeTable, onLookup )
    reactor.run()
    rpcSocket.close()
    return locList[0]
Beispiel #3
0
 def refreshUser( self, publicKey, callback=None ) :
     pubKeyData = publicKey.toDER_PublicKey()
     entry = self.d.get( pubKeyData )
     if entry is None :
         entry = _Entry( publicKey )
         self.d[pubKeyData] = entry
     assert entry.state != ES_NOTIFYING
     if entry.state == ES_DEFAULT :
         assert entry.lookupOp is None
         assert entry.notifyOps is None
         def onLookupUser( location ) :
             self._onLookupUser( entry, location )
         entry.lookupOp = lookupUser( publicKey, self.dhtClient,
                 self.nodeTable,
                 lambda loc : self._onLookupUser(entry,loc) )
         entry.state = ES_LOOKINGUP
         entry.notifyOps = set()
     def doCancel() :
         entry.notifyOps.remove( op )
     op = AsyncOp( callback, doCancel )
     entry.notifyOps.add( op )
     return op