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:
parent
0321651c20
commit
6ad6d6dc50
|
@ -5,7 +5,6 @@ from copy import deepcopy
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from modules.provision import provisionMultipleRelays
|
from modules.provision import provisionMultipleRelays
|
||||||
from twisted.internet.threads import deferToThread
|
from twisted.internet.threads import deferToThread
|
||||||
from numpy import array_split
|
|
||||||
|
|
||||||
def allRelaysActive(net):
|
def allRelaysActive(net):
|
||||||
relayNum = len(main.network[net].relays.keys())
|
relayNum = len(main.network[net].relays.keys())
|
||||||
|
@ -19,22 +18,35 @@ def allRelaysActive(net):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getChanFree(net):
|
def getChanFree(net, new):
|
||||||
chanfree = {}
|
chanfree = {}
|
||||||
|
chanlimits = set()
|
||||||
for i in main.network[net].relays.keys():
|
for i in main.network[net].relays.keys():
|
||||||
|
if i in new:
|
||||||
|
continue
|
||||||
name = net+str(i)
|
name = net+str(i)
|
||||||
chanfree[i] = main.IRCPool[name].chanlimit-len(main.IRCPool[name].channels)
|
chanfree[i] = main.IRCPool[name].chanlimit-len(main.IRCPool[name].channels)
|
||||||
return chanfree
|
chanlimits.add(main.IRCPool[name].chanlimit)
|
||||||
|
|
||||||
def emptyChanAllocate(net, flist, relay):
|
if not len(chanlimits) == 1:
|
||||||
chanfree = getChanFree(net)
|
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 = {}
|
allocated = {}
|
||||||
toalloc = len(flist)
|
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)
|
error("Too many channels to allocate for %s - this is probably a bug" % net)
|
||||||
return False
|
return False
|
||||||
for i in chanfree.keys():
|
for i in chanfree[0].keys():
|
||||||
for x in range(chanfree[i]):
|
for x in range(chanfree[0][i]):
|
||||||
if not len(flist):
|
if not len(flist):
|
||||||
break
|
break
|
||||||
if i in allocated.keys():
|
if i in allocated.keys():
|
||||||
|
@ -43,9 +55,9 @@ def emptyChanAllocate(net, flist, relay):
|
||||||
allocated[i] = [flist.pop()]
|
allocated[i] = [flist.pop()]
|
||||||
return allocated
|
return allocated
|
||||||
|
|
||||||
def populateChans(net, clist, relay):
|
def populateChans(net, clist, relay, new):
|
||||||
#divided = array_split(clist, relay)
|
#divided = array_split(clist, relay)
|
||||||
allocated = emptyChanAllocate(net, clist, relay)
|
allocated = emptyChanAllocate(net, clist, relay, new)
|
||||||
if not allocated:
|
if not allocated:
|
||||||
return
|
return
|
||||||
for i in allocated.keys():
|
for i in allocated.keys():
|
||||||
|
@ -91,15 +103,15 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||||
return
|
return
|
||||||
if coverAll:
|
if coverAll:
|
||||||
needed = relay-len(main.network[net].relays.keys())
|
needed = relay-len(main.network[net].relays.keys())
|
||||||
|
newNums = provisionMultipleRelays(net, needed)
|
||||||
flist = [i[0] for i in listinfo]
|
flist = [i[0] for i in listinfo]
|
||||||
populateChans(net, flist, relay)
|
populateChans(net, flist, relay, newNums)
|
||||||
else:
|
else:
|
||||||
needed = sigrelay-len(main.network[net].relays.keys())
|
needed = sigrelay-len(main.network[net].relays.keys())
|
||||||
|
newNums = provisionMultipleRelays(net, needed)
|
||||||
siglist = [i[0] for i in listinfo if int(i[1]) > mean]
|
siglist = [i[0] for i in listinfo if int(i[1]) > mean]
|
||||||
populateChans(net, siglist, sigrelay)
|
populateChans(net, siglist, sigrelay, newNums)
|
||||||
notifyJoin(net)
|
notifyJoin(net)
|
||||||
if needed > 0:
|
|
||||||
provisionMultipleRelays(net, needed)
|
|
||||||
|
|
||||||
#print("coverall", coverAll)
|
#print("coverall", coverAll)
|
||||||
#print("needed", needed)
|
#print("needed", needed)
|
||||||
|
|
|
@ -63,8 +63,11 @@ def provisionRelay(num, network):
|
||||||
return
|
return
|
||||||
|
|
||||||
def provisionMultipleRelays(net, relaysNeeded):
|
def provisionMultipleRelays(net, relaysNeeded):
|
||||||
|
numsProvisioned = []
|
||||||
for i in range(relaysNeeded):
|
for i in range(relaysNeeded):
|
||||||
num, alias = main.network[net].add_relay()
|
num, alias = main.network[net].add_relay()
|
||||||
|
numsProvisioned.append(num)
|
||||||
provisionRelay(num, net)
|
provisionRelay(num, net)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
|
return numsProvisioned
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue