From eef3246c3e73078193310f8ebeb17013c83d0b2e Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Thu, 3 Jan 2008 17:43:14 -0800 Subject: [PATCH] Made the DHT bootstrapping use IPs instead of DNS names. Also added some logging messages. Also fixed a problem that caused the application to be loaded twice. --- apt-dht.py | 7 +++++-- apt_dht/apt_dht.py | 2 ++ apt_dht/apt_dht_conf.py | 2 +- apt_dht_Khashmir/DHT.py | 12 ++++++++++-- apt_dht_Khashmir/krpc.py | 6 +++--- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/apt-dht.py b/apt-dht.py index 67f7ab5..a532527 100644 --- a/apt-dht.py +++ b/apt-dht.py @@ -50,10 +50,12 @@ if config.has_option('DEFAULT', 'username') and config.get('DEFAULT', 'username' 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() @@ -61,6 +63,7 @@ myDHT.loadConfig(config, config.get('DEFAULT', '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() diff --git a/apt_dht/apt_dht.py b/apt_dht/apt_dht.py index 50d79c7..448d44f 100644 --- a/apt_dht/apt_dht.py +++ b/apt_dht/apt_dht.py @@ -1,6 +1,7 @@ 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 @@ -9,6 +10,7 @@ from MirrorManager import MirrorManager 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) diff --git a/apt_dht/apt_dht_conf.py b/apt_dht/apt_dht_conf.py index 7ad5d9d..dd474bf 100644 --- a/apt_dht/apt_dht_conf.py +++ b/apt_dht/apt_dht_conf.py @@ -40,7 +40,7 @@ DEFAULTS = { 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", diff --git a/apt_dht_Khashmir/DHT.py b/apt_dht_Khashmir/DHT.py index 51fccc4..dd4d5c4 100644 --- a/apt_dht_Khashmir/DHT.py +++ b/apt_dht_Khashmir/DHT.py @@ -1,7 +1,8 @@ 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 @@ -59,9 +60,16 @@ class DHT: 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.""" diff --git a/apt_dht_Khashmir/krpc.py b/apt_dht_Khashmir/krpc.py index 8910ac5..8972c6c 100644 --- a/apt_dht_Khashmir/krpc.py +++ b/apt_dht_Khashmir/krpc.py @@ -56,7 +56,7 @@ class hostbroker(protocol.DatagramProtocol): ## connection class KRPC: - noisy = 0 + noisy = 1 def __init__(self, addr, server, transport): self.transport = transport self.factory = server @@ -72,8 +72,8 @@ class KRPC: 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) -- 2.39.5