Commit 409ebea5 authored by Guillaume Bury's avatar Guillaume Bury

Bootstrap problem solved ( not tested though )

parent 483e034f
...@@ -42,9 +42,10 @@ def main(): ...@@ -42,9 +42,10 @@ def main():
req.sign(pkey, 'sha1') req.sign(pkey, 'sha1')
req = crypto.dump_certificate_request(crypto.FILETYPE_PEM, req) req = crypto.dump_certificate_request(crypto.FILETYPE_PEM, req)
# Get certificates # Get certificates and bootstrap peers
ca = s.getCa() ca = s.getCa()
cert = s.requestCertificate(token, req) cert = s.requestCertificate(token, req)
boot_ip, boot_port, boot_proto = s.getBootstrapPeer()
# Generating dh file # Generating dh file
subprocess.call(['openssl', 'dhparam', '-out', os.path.join(config.dir, 'dh2048.pem'), '2048']) subprocess.call(['openssl', 'dhparam', '-out', os.path.join(config.dir, 'dh2048.pem'), '2048'])
...@@ -57,6 +58,21 @@ def main(): ...@@ -57,6 +58,21 @@ def main():
with open(os.path.join(config.dir, 'ca.pem'), 'w') as f: with open(os.path.join(config.dir, 'ca.pem'), 'w') as f:
f.write(ca) f.write(ca)
# Create and initialize peers DB
self.db = sqlite3.connect(os.path.join(config.dir, 'peers.db'), isolation_level=None)
try:
self.db.execute("""CREATE TABLE peers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ip TEXT NOT NULL,
port INTEGER NOT NULL,
proto TEXT NOT NULL,
used INTEGER NOT NULL default 0)""")
self.db.execute("CREATE INDEX _peers_used ON peers(used)")
self.db.execute("INSERT INTO peers (ip, port, proto) VALUES (?,?,?)", (boot_ip, boot_port, boot_proto))
except sqlite3.OperationalError, e:
if e.args[0] == 'table peers already exists':
print "Table peers already exists, leaving it as it is"
print "Certificate setup complete." print "Certificate setup complete."
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -16,26 +16,21 @@ free_interface_set = set(('client1', 'client2', 'client3', 'client4', 'client5', ...@@ -16,26 +16,21 @@ free_interface_set = set(('client1', 'client2', 'client3', 'client4', 'client5',
class PeersDB: class PeersDB:
def __init__(self, dbPath): def __init__(self, dbPath):
self.proxy = xmlrpclib.ServerProxy('http://%s:%u' % (config.server, config.server_port))
log.log('Connectiong to peers database', 4) log.log('Connectiong to peers database', 4)
self.db = sqlite3.connect(dbPath, isolation_level=None) self.db = sqlite3.connect(dbPath, isolation_level=None)
log.log('Initializing peers database', 4) log.log('Preparing peers database', 4)
try: try:
self.db.execute("""CREATE TABLE peers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ip TEXT NOT NULL,
port INTEGER NOT NULL,
proto TEXT NOT NULL,
used INTEGER NOT NULL default 0)""")
self.db.execute("CREATE INDEX _peers_used ON peers(used)")
self.db.execute("UPDATE peers SET used = 0") self.db.execute("UPDATE peers SET used = 0")
except sqlite3.OperationalError, e: except sqlite3.OperationalError, e:
if e.args[0] != 'table peers already exists': if e.args[0] != 'no such table: peers':
raise RuntimeError raise RuntimeError
def populateDB(self, n): def populate(self, n):
log.log('Connecting to remote server', 3)
self.proxy = xmlrpclib.ServerProxy('http://%s:%u' % (config.server, config.server_port))
log.log('Populating Peers DB', 2) log.log('Populating Peers DB', 2)
# TODO: determine port and proto
port = 1194 port = 1194
proto = 'udp' proto = 'udp'
new_peer_list = self.proxy.getPeerList(n, (config.external_ip, port, proto)) new_peer_list = self.proxy.getPeerList(n, (config.external_ip, port, proto))
...@@ -90,6 +85,7 @@ def getConfig(): ...@@ -90,6 +85,7 @@ def getConfig():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Resilient virtual private network application') description='Resilient virtual private network application')
_ = parser.add_argument _ = parser.add_argument
# Server address MUST be a vifib address ( else requests will be denied )
_('--server', required=True, _('--server', required=True,
help='Address for peer discovery server') help='Address for peer discovery server')
_('--server-port', required=True, type=int, _('--server-port', required=True, type=int,
...@@ -213,13 +209,13 @@ def main(): ...@@ -213,13 +209,13 @@ def main():
getConfig() getConfig()
log.verbose = config.verbose log.verbose = config.verbose
# TODO: how do we decide which protocol we use ? # TODO: how do we decide which protocol we use ?
(externalIp, externalPort) = upnpigd.GetExternalInfo(1194) # (externalIp, externalPort) = upnpigd.GetExternalInfo(1194)
# Setup database # Setup database
global peers_db # stop using global variables for everything ? global peers_db # stop using global variables for everything ?
peers_db = PeersDB(config.db) peers_db = PeersDB(config.db)
# Launch babel on all interfaces # Launch babel on all interfaces. WARNING : you have to be root to start babeld
log.log('Starting babel', 3) log.log('Starting babel', 3)
babel = startBabel(stdout=os.open(os.path.join(config.log, 'vifibnet.babeld.log'), os.O_WRONLY | os.O_CREAT | os.O_TRUNC), stderr=subprocess.STDOUT) babel = startBabel(stdout=os.open(os.path.join(config.log, 'vifibnet.babeld.log'), os.O_WRONLY | os.O_CREAT | os.O_TRUNC), stderr=subprocess.STDOUT)
...@@ -241,7 +237,7 @@ def main(): ...@@ -241,7 +237,7 @@ def main():
# main loop # main loop
try: try:
while True: while True:
ready, tmp1, tmp2 = select.select([read_pipe], [], [], ready, tmp1, tmp2 = select.select([read_pipe], [], [],
max(0, next_refresh - time.time())) max(0, next_refresh - time.time()))
if ready: if ready:
handle_message(read_pipe.readline()) handle_message(read_pipe.readline())
......
Markdown is supported
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