Fix channel allocation when relays are provisioned

Fix a bug where the channel allocation algorithm failed due to
necessary relays not having been provisioned yet.
Passed the newly created relay numbers to the allocation function
and assumed their CHANMAX would be the same as all other relays for
the same network.
This commit is contained in:
Mark Veidemanis 2019-10-12 21:40:50 +01:00
parent 0321651c20
commit 6ad6d6dc50
2 changed files with 29 additions and 14 deletions

View File

@ -5,7 +5,6 @@ from copy import deepcopy
from math import ceil
from modules.provision import provisionMultipleRelays
from twisted.internet.threads import deferToThread
from numpy import array_split
def allRelaysActive(net):
relayNum = len(main.network[net].relays.keys())
@ -19,22 +18,35 @@ def allRelaysActive(net):
return True
return False
def getChanFree(net):
def getChanFree(net, new):
chanfree = {}
chanlimits = set()
for i in main.network[net].relays.keys():
if i in new:
continue
name = net+str(i)
chanfree[i] = main.IRCPool[name].chanlimit-len(main.IRCPool[name].channels)
return chanfree
chanlimits.add(main.IRCPool[name].chanlimit)
def emptyChanAllocate(net, flist, relay):
chanfree = getChanFree(net)
if not len(chanlimits) == 1:
error("Network %s has servers with different CHANMAX values" % net)
return False
return (chanfree, chanlimits.pop())
def emptyChanAllocate(net, flist, relay, new):
chanfree = getChanFree(net, new)
if not chanfree:
return
for i in new:
chanfree[0][i] = chanfree[1]
print("chanfree", chanfree)
allocated = {}
toalloc = len(flist)
if toalloc > sum(chanfree.values()):
if toalloc > sum(chanfree[0].values()):
error("Too many channels to allocate for %s - this is probably a bug" % net)
return False
for i in chanfree.keys():
for x in range(chanfree[i]):
for i in chanfree[0].keys():
for x in range(chanfree[0][i]):
if not len(flist):
break
if i in allocated.keys():
@ -43,9 +55,9 @@ def emptyChanAllocate(net, flist, relay):
allocated[i] = [flist.pop()]
return allocated
def populateChans(net, clist, relay):
def populateChans(net, clist, relay, new):
#divided = array_split(clist, relay)
allocated = emptyChanAllocate(net, clist, relay)
allocated = emptyChanAllocate(net, clist, relay, new)
if not allocated:
return
for i in allocated.keys():
@ -91,15 +103,15 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
return
if coverAll:
needed = relay-len(main.network[net].relays.keys())
newNums = provisionMultipleRelays(net, needed)
flist = [i[0] for i in listinfo]
populateChans(net, flist, relay)
populateChans(net, flist, relay, newNums)
else:
needed = sigrelay-len(main.network[net].relays.keys())
newNums = provisionMultipleRelays(net, needed)
siglist = [i[0] for i in listinfo if int(i[1]) > mean]
populateChans(net, siglist, sigrelay)
populateChans(net, siglist, sigrelay, newNums)
notifyJoin(net)
if needed > 0:
provisionMultipleRelays(net, needed)
#print("coverall", coverAll)
#print("needed", needed)

View File

@ -63,8 +63,11 @@ def provisionRelay(num, network):
return
def provisionMultipleRelays(net, relaysNeeded):
numsProvisioned = []
for i in range(relaysNeeded):
num, alias = main.network[net].add_relay()
numsProvisioned.append(num)
provisionRelay(num, net)
main.saveConf("network")
return numsProvisioned