Add message implementations and make private variables have underscore

This commit is contained in:
DSTO\pivatom
2019-01-14 08:56:34 +10:30
parent f101bf61bf
commit 6444d6d3a0

View File

@@ -7,9 +7,9 @@ class Commander:
# Stores voters that connect to maintain a majority.
# Voters who do not vote in latest round are removed.
connectedVoters = {}
votes = []
taking_votes = False
_connectedVoters = []
_votes = []
_taking_votes = False
def __init__(self, timeout = 60):
'''
@@ -47,7 +47,7 @@ class Commander:
return max_vote
def get_votes():
def get_votes(self):
message = {"type": "reqVote"}
message_packed = umsgpack.packb(message)
# Publish a message that votes are needed.
@@ -64,19 +64,21 @@ class Commander:
def on_message(self, client, userdata, message):
messageDict = umsgpack.unpackb()
if "type" in messageDict.keys:
# Need to consider that a malicious message may have a type with incorrect subtypes.
if messageDict["type"] == "connect":
# Voter just connected/reconnnected.
pass
if not messageDict["client"] in self._connectedVoters:
self._connectedVoters.append(messageDict["client"])
elif messageDict["type"] == "vote":
# Voter is sending in their vote.
if messageDict[""]
# Only add vote to list if the client has not already voted.
pass
elif messageDict["type"] == "disconnected":
self._connectedVoters.remove(messageDict["type"])
else:
# Not a message we should be using.
NotImplementedError
pass
def on_connect(client, userdata, flags, rc):
def on_connect(self, client, userdata, flags, rc):
self.client.subscribe("swarm1/commander")