2

I'm working on a P2P application using twisted. I'm trying to repeatedly search for a specific key in my DHT and add it to a dictionary any time that the value changes. The code is more or less doing what I want to accomplish, except that I still have multiple requests that are running once I get a new value. This sometimes gives me a runtime error saying I've exceeded the maximum recursion depth. How can I change this so that only one get request is running at a time, but that it still constantly searches? I've never used twisted before so I'm still trying to get the hang of it.

#want this to loop repeatedly looking for new ids
def addid(val,server,key):
    print "Val: ",val
    if val:
        if not val in ids:
            print "new id found"
            valhash = hashlib.sha1()
            valhash.update(str(val))
            newval = valhash.hexdigest()
            ids[val]=newval
            server.set(ids[val], str(val))

    server.get(key).addCallback(addid,server,key)

def bootstrapDone(found, server):
    if len(found) == 0:
        print "Could not connect to the bootstrap server."
        reactor.stop()
    key = hashlib.sha1()
    key.update('specialstring')
    keyhash = key.hexdigest()
    server.get(keyhash).addCallback(addid,server,keyhash)
jhoward
  • 404
  • 1
  • 6
  • 16
  • 1
    Any chance you can provide some more of the code? It's hard to see why the error is appearing without some more context. – notorious.no May 04 '16 at 11:52

0 Answers0