Implement best effort allocation

This commit is contained in:
Mark Veidemanis 2022-08-11 21:44:19 +01:00
parent 1ef600a9df
commit 719f014265
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 24 additions and 15 deletions

View File

@ -5,7 +5,7 @@ from twisted.internet.threads import deferToThread
import main
import modules.provision
from utils.logging.debug import debug
from utils.logging.debug import debug, trace
from utils.logging.log import error, log, warn
@ -77,6 +77,7 @@ def emptyChanAllocate(net, flist, relay, new):
chans_not_covered = toalloc - sum_free # 2148 - 250 = 1898
relays_needed = chans_not_covered / chanfree[1] # 1898 / 250 = 7.592
correction = ceil(relays_needed)
if main.config["ChanKeep"]["Provision"]:
debug(
(
f"emptyChanAllocate() secondary allocation sum_free:{sum_free} "
@ -93,6 +94,14 @@ def emptyChanAllocate(net, flist, relay, new):
warn("Ran out of channel spaces, provisioning additional %i relays for %s" % (correction, net))
modules.provision.provisionMultipleRelays(net, correction)
return False
else:
# We don't have enough spaces and we can't add any.
# Let's do the best we can in the circumstances.
debug(f"emptyChanAllocate() cannot create additional relays for {net}")
debug(f"emptyChanAllocate() {chans_not_covered} channels cannot be covered")
flist = flist[:sum_free]
debug(f"emptyChanAllocate() flist truncated to {sum_free}, length nis now {len(flist)}")
trace(f"emptyChanAllocate() best effort allocation: {flist}")
for i in chanfree[0].keys():
for x in range(chanfree[0][i]):
if not len(flist):