Implement relay, channel and alias management

This commit is contained in:
2022-07-27 22:03:42 +01:00
parent b30a3a535d
commit 8409a39e57
3 changed files with 135 additions and 10 deletions

View File

@@ -23,6 +23,15 @@ def allRelaysActive(net):
def getChanFree(net, new):
"""
Get a dictionary with the free channel spaces for
each relay, and a channel limit.
Example return:
({1: 99}, 100)
:param net: network
:param new: list of newly provisioned relays to skip
:return: ({relay: channel spaces}, channel limit)
"""
chanfree = {}
chanlimits = set()
for i in main.network[net].relays.keys():
@@ -123,16 +132,38 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
def joinSingle(net, channel):
if allRelaysActive(net):
chanfree = getChanFree(net, [])
print("chanfree", chanfree)
for i in chanfree[0]:
if chanfree[0][i] < 0:
print("JOIN CHAN")
# Use the algorithm to allocate our channel to a relay
eca = emptyChanAllocate(net, [channel], None, [])
if not len(eca.keys()) == 1:
return False
num = list(eca.keys())[0]
name = f"{net}{num}"
if name not in main.IRCPool:
return False
main.IRCPool[name].join(channel)
return num
else:
error("All relays for %s are not active" % net)
return False
def partSingle(net, channel):
"""
Iterate over all the relays of net and part channels matching channel.
:param net:
:param channel:
:return:
"""
parted = []
for i in main.network[net].relays.keys():
name = f"{net}{i}"
if name in main.IRCPool.keys():
if channel in main.IRCPool[name].channels:
main.IRCPool[name].part(channel)
parted.append(str(i))
return parted
def nukeNetwork(net):
# purgeRecords(net)
# p = main.g.pipeline()