Commit aea0b891 authored by Nick Mathewson's avatar Nick Mathewson 🐻
Browse files

r17148@catbus: nickm | 2007-12-14 14:10:17 -0500

 More tweaks on bridgedb


svn:r12811
parent 6a85d691
For dec:
- make mail get configured right.
- actually invoke server stuff.
- reload bridges on sighup
- write a README
......@@ -15,3 +13,4 @@ Later:
- decent template for web interface
- decent template for mail interface
- implement 'help' command
\ No newline at end of file
......@@ -9,6 +9,8 @@ import sys
import bridgedb.Bridges as Bridges
import bridgedb.Dist as Dist
import bridgedb.Time as Time
import bridgedb.Server as Server
class Conf:
def __init__(self, **attrs):
......@@ -25,9 +27,11 @@ CONFIG = Conf(
HTTPS_DIST = True,
HTTPS_SHARE=10,
HTTPS_BIND_IP=None,
HTTPS_PORT=6789,
HTTPS_CERT_FILE="cert",
HTTPS_KEY_FILE="key",
HTTP_UNENCRYPTED_BIND_IP=None,
HTTP_UNENCRYPTED_PORT=6788,
HTTPS_N_BRIDGES_PER_ANSWER=2,
......@@ -36,7 +40,9 @@ CONFIG = Conf(
EMAIL_DOMAINS = [ "gmail.com", "yahoo.com" ],
EMAIL_DOMAIN_MAP = { "mail.google.com" : "gmail.com",
"googlemail.com" : "gmail.com", },
EMAIL_BIND_IP=None,
EMAIL_PORT=6725,
EMAIL_N_BRIDGES_PER_ANSWER=2,
RESERVED_SHARE=2,
)
......@@ -80,8 +86,9 @@ def load(cfg, splitter):
def startup(cfg):
key = getKey(MASTER_KEY_FILE)
dblogfile = None
store = anydbm.open(cfg.DB_FILE, "c", 0600)
baseStore = store = anydbm.open(cfg.DB_FILE, "c", 0600)
if DB_LOG_FILE:
dblogfile = open(cfg.DB_LOG_FILE, "a+", 0)
store = LogDB("db", store, dblogfile)
......@@ -94,6 +101,7 @@ def startup(cfg):
Dist.N_IP_CLUSTERS,
Bridges.get_hmac(key, "HTTPS-IP-Dist-Key"))
splitter.addRing(ipDistributor, "https", cfg.HTTPS_SHARE)
webSchedule = Time.IntervalSchedule("day", 2)
if cfg.EMAIL_DIST and cfg.EMAIL_SHARE:
for d in cfg.EMAIL_DOMAINS:
......@@ -103,6 +111,7 @@ def startup(cfg):
Bridges.PrefixStore(store, "em|"),
cfg.EMAIL_DOMAIN_MAP.copy())
splitter.addRing(emailDistributor, "email", cfg.EMAIL_SHARE)
emailSchedule = Time.IntervalSchedule("day", 1)
if cfg.RESERVED_SHARE:
splitter.addRing(Bridges.UnallocatedHolder(),
......@@ -115,5 +124,16 @@ def startup(cfg):
load(cfg, splitter)
# XXXX create twisted listeners.
if cfg.HTTPS_DIST and cfg.HTTPS_SHARE:
Server.addWebServer(cfg, ipDistributor, webSchedule)
if cfg.EMAIL_DIST and cfg.EMAIL_SHARE:
Server.addSMTPServer(cfg, emailDistributor, emailSchedule)
try:
Server.run()
finally:
baseStore.close()
if dblogfile is not None:
dblogfile.close()
......@@ -40,13 +40,15 @@ def addWebServer(cfg, dist, sched):
resource = WebResource(dist, sched, cfg.HTTPS_N_BRIDGES_PER_ANSWER)
site = Site(resource)
if cfg.HTTP_UNENCRYPTED_PORT:
reactor.listenTCP(cfg.HTTP_UNENCRYPTED_PORT, site)
ip = cfg.HTTPS_BIND_IP or ""
reactor.listenTCP(cfg.HTTP_UNENCRYPTED_PORT, site, interface=ip)
if cfg.HTTPS_PORT:
from twisted.internet.ssl import DefaultOpenSSLContextFactory
from OpenSSL.SSL import SSLv3_METHOD
ip = cfg.HTTP_UNENCRYPTED_BIND_IP or ""
factory = DefaultOpenSSLContextFactory(cfg.HTTPS_KEY_FILE,
cfg.HTTPS_CERT_FILE)
reactor.listenSSL(cfg.HTTPS_PORT, site, factory)
reactor.listenSSL(cfg.HTTPS_PORT, site, factory, interface=ip)
return site
class MailFile:
......@@ -120,19 +122,20 @@ def replyToMail(lines, ctx):
return d
class MailContext:
def __init__(self, cfg):
def __init__(self, cfg, dist, sched):
self.username = "bridges"
self.maximumSize = 32*1024
self.smtpServer
self.smtpPort
self.fromAddr
self.distributor
self.schedule
self.smtpServer = "127.0.0.1"
self.smtpPort = 25
self.fromAddr = "bridges@bridges.torproject.org"
self.distributor = dist
self.schedule = sched
self.N = cfg.EMAIL_N_BRIDGES_PER_ANSWER
class MailMessage:
implements(twisted.mail.smtp.IMessage)
def __init__(self, ctx)
def __init__(self, ctx):
self.ctx = ctx
self.lines = []
self.nBytes = 0
......@@ -182,8 +185,12 @@ class MailFactory(twisted.mail.smtp.SMTPFactory):
return p
def addSMTPServer(cfg, dist, sched):
ctx = MailContext() #XXXX
ctx = MailContext(cfg)
factory = MailFactory()
factory.setBridgeDBContext(ctx)
reactor.listenTCP(cfg.EMAIL_PORT, factory)
ip = cfg.EMAIL_BIND_IP or ""
reactor.listenTCP(cfg.EMAIL_PORT, factory, interface=ip)
return factory
def runServers():
reactor.run()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment