From b97ebe43ab4ca6b1ff290bfbf0c86aa92695068f Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sun, 13 Oct 2019 12:37:01 +0100 Subject: [PATCH] Only start one relay with the auto command We only need one initial relay, as ChanKeep will automatically add as many as it needs when receiving a LIST response. --- commands/auto.py | 42 ++++++++++++++++-------------------------- conf/help.json | 2 +- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/commands/auto.py b/commands/auto.py index 9dde92c..29bd3a8 100644 --- a/commands/auto.py +++ b/commands/auto.py @@ -7,38 +7,28 @@ class AutoCommand: def auto(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: - if length == 3: - if not spl[1] in main.network.keys(): - failure("No such network: %s" % spl[1]) - return - if not spl[2].isdigit(): - failure("Must be a number, not %s" % spl[2]) - return - relayNum = int(spl[2]) - num, alias = main.network[spl[1]].add_relay(relayNum) - success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias)) + if length == 1: + for i in main.network.keys(): + if 1 in main.network[i].relays.keys(): + info("Skipping %s - first relay exists" % i) + else: + num, alias = main.network[i].add_relay(1) + success("Successfully created first relay on network %s with alias %s" % (i, alias)) + provision.provisionRelay(num, i) + success("Started provisioning network %s on first relay for alias %s" % (i, alias)) main.saveConf("network") - provision.provisionRelay(relayNum, spl[1]) - success("Started provisioning network %s on relay %s for alias %s" % (spl[1], spl[2], alias)) return elif length == 2: if not spl[1] in main.network.keys(): failure("No such network: %s" % spl[1]) return - for i in main.alias.keys(): - num, alias = main.network[spl[1]].add_relay(i) - success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias)) - provision.provisionRelay(num, spl[1]) - success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, alias)) - main.saveConf("network") - return - elif length == 1: - for i in main.network.keys(): - for x in main.alias.keys(): - num, alias = main.network[i].add_relay(x) - success("Successfully created relay %i on network %s with alias %s" % (num, i, alias)) - provision.provisionRelay(num, i) - success("Started provisioning network %s on relay %s for alias %s" % (i, num, alias)) + if 1 in main.network[spl[1]].relays.keys(): + failure("First relay exists on %s" % spl[1]) + return + num, alias = main.network[spl[1]].add_relay(1) + success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias)) + provision.provisionRelay(num, spl[1]) + success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, alias)) main.saveConf("network") return else: diff --git a/conf/help.json b/conf/help.json index 0f561c4..f97448f 100644 --- a/conf/help.json +++ b/conf/help.json @@ -20,7 +20,7 @@ "relay": "relay [] []", "network": "network [
]", "alias": "alias [] []", - "auto": "auto [] []", + "auto": "auto []", "cmd": "cmd ", "token": "token [] []", "all": "all ",