Also added some logging messages.
Also fixed a problem that caused the application to be loaded twice.
else:
uid,gid = None,None
+log.msg('Starting application')
application = service.Application("apt-dht", uid, gid)
-print service.IProcess(application).processName
-service.IProcess(application).processName = 'apt-dht'
+#print service.IProcess(application).processName
+#service.IProcess(application).processName = 'apt-dht'
+log.msg('Starting DHT')
DHT = __import__(config.get('DEFAULT', 'DHT')+'.DHT', globals(), locals(), ['DHT'])
assert(IDHT.implementedBy(DHT.DHT), "You must provide a DHT implementation that implements the IDHT interface.")
myDHT = DHT.DHT()
myDHT.join()
if not config.getboolean('DEFAULT', 'DHT-only'):
+ log.msg('Starting main application server')
from apt_dht.apt_dht import AptDHT
myapp = AptDHT(myDHT)
site = myapp.getSite()
from twisted.internet import defer
from twisted.web2 import server, http, http_headers
+from twisted.python import log
from apt_dht_conf import config
from PeerManager import PeerManager
class AptDHT:
def __init__(self, dht):
+ log.msg('Initializing the main apt_dht application')
self.dht = dht
self.http_server = TopLevel(config.get('DEFAULT', 'cache_dir'), self)
self.http_site = server.Site(self.http_server)
DHT_DEFAULTS = {
# bootstrap nodes to contact to join the DHT
'BOOTSTRAP': """www.camrdale.org:9977
- steveholt.hopto.org:9977""",
+ steveholt.hopto.org:9976""",
# whether this node is a bootstrap node
'BOOTSTRAP_NODE': "no",
import os, sha, random
-from twisted.internet import defer
+from twisted.internet import defer, reactor
+from twisted.internet.abstract import isIPAddress
from twisted.trial import unittest
from zope.interface import implements
for node in self.bootstrap:
host, port = node.rsplit(':', 1)
port = int(port)
- self.khashmir.addContact(host, port, self._join_single)
+ if isIPAddress(host):
+ self._join_gotIP(host, port)
+ else:
+ reactor.resolve(host).addCallback(self._join_gotIP, port)
return self.joining
+
+ def _join_gotIP(self, ip, port):
+ """Called after an IP address has been found for a single bootstrap node."""
+ self.khashmir.addContact(ip, port, self._join_single)
def _join_single(self):
"""Called when a single bootstrap node has been added."""
## connection
class KRPC:
- noisy = 0
+ noisy = 1
def __init__(self, addr, server, transport):
self.transport = transport
self.factory = server
if self.noisy:
print "response decode error: " + `e`
else:
- #if self.noisy:
- # print msg
+ if self.noisy:
+ print msg
# look at msg type
if msg[TYP] == REQ:
ilen = len(str)