Commit 35e585dc authored by Guillaume Bury's avatar Guillaume Bury

Script starts babel

parent aa7588d7
#!/usr/bin/python -S #!/usr/bin/python -S
import os, sys import os, sys
import pdb; pdb.set_trace()
os.write(int(sys.argv[1]), 'CLIENT_CONNECTED ' + os.environ['trusted_ip'] + '\n') os.write(int(sys.argv[1]), 'CLIENT_CONNECTED ' + os.environ['trusted_ip'] + '\n')
...@@ -29,7 +29,7 @@ class PeersDB: ...@@ -29,7 +29,7 @@ class PeersDB:
used INTEGER NOT NULL)""") used INTEGER NOT NULL)""")
self.db.execute("CREATE INDEX IF NOT EXISTS _peers_used ON peers(used)") self.db.execute("CREATE INDEX IF NOT EXISTS _peers_used ON peers(used)")
self.db.execute("UPDATE peers SET used = 0") self.db.execute("UPDATE peers SET used = 0")
def getUnusedPeers(self, nPeers): def getUnusedPeers(self, nPeers):
return self.db.execute("SELECT id, ip, port, proto FROM peers WHERE used = 0 " return self.db.execute("SELECT id, ip, port, proto FROM peers WHERE used = 0 "
"ORDER BY RANDOM() LIMIT ?", (nPeers,)) "ORDER BY RANDOM() LIMIT ?", (nPeers,))
...@@ -37,22 +37,21 @@ class PeersDB: ...@@ -37,22 +37,21 @@ class PeersDB:
def usePeer(self, id): def usePeer(self, id):
log_message('Updating peers database : using peer ' + str(id), 5) log_message('Updating peers database : using peer ' + str(id), 5)
self.db.execute("UPDATE peers SET used = 1 WHERE id = ?", (id,)) self.db.execute("UPDATE peers SET used = 1 WHERE id = ?", (id,))
def unusePeer(self, id): def unusePeer(self, id):
log_message('Updating peers database : unusing peer ' + str(id), 5) log_message('Updating peers database : unusing peer ' + str(id), 5)
self.db.execute("UPDATE peers SET used = 0 WHERE id = ?", (id,)) self.db.execute("UPDATE peers SET used = 0 WHERE id = ?", (id,))
def startBabel():
def babel(network_ip, network_mask):
args = ['babeld', args = ['babeld',
'-C', 'redistribute local ip %s/%s' % (network_ip, network_mask), '-C', 'redistribute local ip %s' % (config.ip),
'-C', 'redistribute local deny', '-C', 'redistribute local deny',
# Route VIFIB ip adresses # Route VIFIB ip adresses
'-C', 'in ip %s' % VIFIB_NET, '-C', 'in ip %s' % VIFIB_NET,
# Route only addresse in the 'local' network, # Route only addresse in the 'local' network,
# or other entire networks # or other entire networks
'-C', 'in ip %s/%s' % (network_ip,network_mask), #'-C', 'in ip %s' % (config.ip),
#'-C', 'in ip ::/0 le %s' % network_mask, #'-C', 'in ip ::/0 le %s' % network_mask,
# Don't route other addresses # Don't route other addresses
'-C', 'in ip deny', '-C', 'in ip deny',
...@@ -169,6 +168,10 @@ def main(): ...@@ -169,6 +168,10 @@ def main():
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
log_message('Starting babel', 3)
babel = startBabel()
# Create and open read_only pipe to get connect/disconnect events from openvpn # Create and open read_only pipe to get connect/disconnect events from openvpn
log_message('Creating pipe for openvpn events', 3) log_message('Creating pipe for openvpn events', 3)
r_pipe, write_pipe = os.pipe() r_pipe, write_pipe = os.pipe()
......
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