Add ability to propogate result of vote and making a vote.

This commit is contained in:
Michael Pivato
2019-03-01 15:44:58 +10:30
parent 0b04588161
commit ede1ec4500
3 changed files with 30 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
import time
from DecisionSystem.messages import Message, CommanderWill, RequestVote, GetSwarmParticipants, deserialise
from DecisionSystem.messages import Message, CommanderWill, RequestVote, GetSwarmParticipants, deserialise, ClientVoteRequest, VoteResult
import json
import numpy as np
@@ -62,6 +62,7 @@ class Commander:
print("published message")
time.sleep(self.timeout)
self._taking_votes = False
# TODO: Work out how to broadcast votes back to the swarm, maybe using raft?
return self.make_decision()
def on_message(self, message):
@@ -90,6 +91,9 @@ class Commander:
# Only add vote to list if the client has not already voted.
if messageD.sender not in self._votes:
self._votes[messageD.sender] = int(messageD.data["vote"])
elif messageD.type == ClientVoteRequest().type:
# received a request to get votes/consensus.
self.get_votes()
elif messageD.type == "disconnected":
print("Voter disconnected :(")
@@ -109,4 +113,7 @@ class Commander:
# self.client.publish("swarm1/voters", CommanderWill(self.client._client_id).serialise())
def on_disconnect(self, rc):
pass
pass
def propogate_result(self, result):
self._messenger.broadcast_message(self._messenger.swarm, )