[node] implement everything...

This commit is contained in:
lare 2022-12-21 21:21:57 +01:00
parent 1fda3c11a4
commit 99809e1139
9 changed files with 527 additions and 12 deletions

View file

@ -21,7 +21,7 @@
"port": 8042,
"domain": "example.org", // domain to use for kioubit verification service (with protocol)
"base-dir": "/", //optional:directury for which it is reachable (if behind some sort of reverse proxy) default "/"
"peerings": "/path/to/peering-config.json", // optional; default "$PWD/peerings", directory to save existing peerings to
"peerings": "/path/to/peerings.json", // optional; default "$PWD/peerings.json", file to save existing peerings to
"production": true, //optional, default true;
"debug-mode": false, // optional; whethet to enable debugging; default false
"flask-secret-key": "<secret-please-replace>", // secret key for session cookies

View file

@ -3,6 +3,8 @@ import os
import base64
import logging
import random
import threading
import requests
class NodeCommunicator:
@ -10,6 +12,10 @@ class NodeCommunicator:
self.name = name
self.__config = config
self.__api_addr = config["api-con"]
def update(self, action:str, updated_peering:dict):
print(requests.api.post(self.__api_addr+"peerings", json=updated_peering).content)
input()
class PeeringManager:
@ -24,6 +30,7 @@ class PeeringManager:
self._nodes[node] = NodeCommunicator(name=node, config=self.__config["nodes"][node])
self._amounts = None
self._threads = []
def __load_peerings(self):
if not os.path.exists(self.__peering_file):
@ -56,12 +63,18 @@ class PeeringManager:
json.dump(self.peerings, p, indent=4)
self._amounts = None
def _update_nodes(self, mode, peering, new_peering=None):
def _update_nodes(self, action:str, peering, new_peering=None):
"""mode: "add","update","delete
peering: peering to send to node (included in peering)
new_peering: if mode=="update" the new peering to update to
"""
pass
if peering["node"] in self._nodes:
thread = threading.Thread(target=self._nodes[peering["node"]].update,kwargs={"action":action,"updated_peering":peering if not new_peering else new_peering,})
thread.start()
self._threads.append(thread)
else: return False
def _update_amounts(self):
__new = {}
for asn in self.peerings["asn"]:
@ -154,12 +167,15 @@ class PeeringManager:
success = False
for pNr in range(len(self.peerings["asn"][asn])):
if self.peerings["asn"][asn][pNr]["node"] == node:
self.peerings["asn"][asn][pNr] = {"MNT": mnt, "ASN": asn, "node": node, "wg_key": wg_key,
old_peering = self.peerings["asn"][asn][pNr]
new_peering = self.peerings["asn"][asn][pNr] = {"MNT": mnt, "ASN": asn, "node": node, "wg_key": wg_key,
"endpoint": endpoint, "ipv6ll": ipv6ll, "ipv4": ipv4, "ipv6": ipv6, "bgp_mp": bgp_mp, "bgp_enh": bgp_enh}
success = True
if not success:
return False
self._save_peerings()
self._update_nodes("update", old_peering, new_peering=new_peering)
return True
def delete_peering(self, asn, node, mnt, wg_key=None):

View file

@ -65,13 +65,6 @@ footer.flex {
/* # index.html */
/* based on https://codepen.io/t_afif/pen/RwQZLYb */
.progress-bar {
--w: 100px; /* the width*/
--background: lightgrey; /* the background color */
width: var(--w);
margin: 0 10px;
}
.progress {
-webkit-appearance: none;
-moz-appearance: none;
@ -81,6 +74,13 @@ footer.flex {
border-radius: 10em;
background: var(--background);
}
.progress-bar {
--w: 100px; /* the width*/
--background: lightgrey; /* the background color */
width: var(--w);
margin: 0 10px;
}
.progress-value[value]{
--color: /* the progress color */