24 #ifndef GROUPMANAGEMENT_HPP_ 25 #define GROUPMANAGEMENT_HPP_ 32 #include "messages/ModuleMessage.pb.h" 34 #include <boost/interprocess/sync/interprocess_mutex.hpp> 35 #include <boost/shared_ptr.hpp> 36 #include <boost/thread/mutex.hpp> 88 void Check(
const boost::system::error_code& err );
90 void Timeout(
const boost::system::error_code& err );
92 void Recovery(
const boost::system::error_code& err );
94 void Premerge(
const boost::system::error_code &err );
96 void Merge(
const boost::system::error_code& err );
114 ModuleMessage
PeerList(std::string requester=
"all");
133 void Reorganize(
const boost::system::error_code& err );
137 void StartMonitor(
const boost::system::error_code& err);
144 const GroupManagementMessage& message, std::string recipient =
"gm");
void Merge(const boost::system::error_code &err)
Sends invitations to all known nodes.
Definition: GroupManagement.cpp:710
static ModuleMessage PeerListQuery(std::string requester)
Generates a CMessage that can be used to query for the group.
Definition: GroupManagement.cpp:327
int GetStatus() const
Gets the status of a node.
Definition: GroupManagement.cpp:1333
void Premerge(const boost::system::error_code &err)
Waits a time period determined by UUID for merge.
Definition: GroupManagement.cpp:563
ModuleMessage AreYouCoordinatorResponse(std::string payload, int seq)
Creates A Response message.
Definition: GroupManagement.cpp:219
void HandlePeerList(const PeerListMessage &msg, CPeerNode peer)
Hadles recieving peerlists.
Definition: GroupManagement.cpp:938
void HandleInvite(const InviteMessage &msg, CPeerNode peer)
Handles recieving invite messages.
Definition: GroupManagement.cpp:1072
void HandleResponseAYT(const AreYouThereResponseMessage &msg, CPeerNode peere)
Handles recieving AYT responses.
Definition: GroupManagement.cpp:1210
unsigned int m_GrpCounter
The number of groups being formed.
Definition: GroupManagement.hpp:160
ModuleMessage PeerList(std::string requester="all")
Generates a peer list.
Definition: GroupManagement.cpp:300
void StartMonitor(const boost::system::error_code &err)
Start the monitor after transient is over.
boost::posix_time::time_duration TIMEOUT_TIMEOUT
How long beteween AYT checks.
Definition: GroupManagement.hpp:174
Definition: GroupManagement.hpp:50
std::string m_GroupLeader
The uuid of the group leader.
Definition: GroupManagement.hpp:158
boost::asio::io_service m_localservice
The io_service used.
Definition: GroupManagement.hpp:164
ModuleMessage AreYouThere()
Creates a AYT, used for Timeout.
Definition: GroupManagement.cpp:281
void Reorganize(const boost::system::error_code &err)
Puts the system into the working state.
Definition: GroupManagement.cpp:815
void HandleAccept(const AcceptMessage &msg, CPeerNode peer)
Handles recieving accept messsages.
Definition: GroupManagement.cpp:982
Base interface for agents/broker modules.
Definition: CPeerNode.hpp:37
std::map< std::string, bool > m_fidstate
A store for the state of attached FIDs.
Definition: GroupManagement.hpp:199
void Recovery()
Resets the algorithm to the default startup state.
Definition: GroupManagement.cpp:437
ModuleMessage Invitation()
Creates Group Invitation Message.
Definition: GroupManagement.cpp:198
void SystemState()
Outputs information about the current state to the logger.
Definition: GroupManagement.cpp:341
Definition: GroupManagement.hpp:50
int m_groupsjoined
Number of accepts sent.
Definition: GroupManagement.hpp:191
void HandleResponseAYC(const AreYouCoordinatorResponseMessage &msg, CPeerNode peer)
Handles recieving AYC responses.
Definition: GroupManagement.cpp:1149
int Run()
Called to start the system.
Definition: GroupManagement.cpp:1304
TimedPeerSet m_AYTResponse
Nodes expecting AYT response from.
Definition: GroupManagement.hpp:153
Definition: GroupManagement.hpp:50
std::map< std::string, std::pair< CPeerNode, boost::posix_time::ptime > > TimedPeerSet
Similar to a PeerSet, but also tracks the time a peer was inserted.
Definition: PeerSets.hpp:49
Definition: GroupManagement.hpp:50
Declaration of Garcia-Molina Invitation Leader Election algorithm.
Definition: GroupManagement.hpp:45
boost::posix_time::time_duration AYT_RESPONSE_TIMEOUT
How long to wait for responses from other nodes.
Definition: GroupManagement.hpp:180
CBroker::TimerHandle m_fidtimer
Timer for checking FIDs.
Definition: GroupManagement.hpp:168
PeerSet m_UpNodes
Nodes In My Group.
Definition: GroupManagement.hpp:147
boost::posix_time::time_duration FID_TIMEOUT
How long to wait before checking attached FIDs.
Definition: GroupManagement.hpp:176
ModuleMessage AreYouCoordinator()
Creates AYC Message.
Definition: GroupManagement.cpp:179
static ModuleMessage PrepareForSending(const GroupManagementMessage &message, std::string recipient="gm")
Wraps a GroupManagementMessage in a ModuleMessage.
Definition: GroupManagement.cpp:1363
int m_groupsbroken
Number of groups broken.
Definition: GroupManagement.hpp:187
void Timeout(const boost::system::error_code &err)
Checks that the leader is still alive and working.
Definition: GroupManagement.cpp:851
int m_membershipchecks
Number of membership checks.
Definition: GroupManagement.hpp:195
~GMAgent()
Module destructor.
Definition: GroupManagement.cpp:105
ModuleMessage Accept()
Creates an Accept Message.
Definition: GroupManagement.cpp:266
int m_status
A store for the status of this node.
Definition: GroupManagement.hpp:197
ModuleMessage AreYouThereResponse(std::string payload, int seq)
Creates A Response message.
Definition: GroupManagement.cpp:247
unsigned int TimerHandle
Definition: CBroker.hpp:66
void HandlePeerListQuery(const PeerListQueryMessage &msg, CPeerNode peer)
Handles recieving peerlist requests.
Definition: GroupManagement.cpp:1252
Definition: GroupManagement.hpp:50
void PushPeerList()
Sends the peer list to all group members.
Definition: GroupManagement.cpp:416
CPeerNode AddPeer(std::string uuid)
Adds a peer to the peer set from UUID.
Definition: GroupManagement.cpp:1265
An interface for an object which can handle recieving incoming messages.
Definition: IDGIModule.hpp:36
boost::posix_time::time_duration AYC_RESPONSE_TIMEOUT
How long to wait for responses from other nodes.
Definition: GroupManagement.hpp:178
PeerSet m_Coordinators
Known Coordinators.
Definition: GroupManagement.hpp:149
CPeerNode GetPeer(const std::string &uuid)
Gets a pointer to a peer from UUID.
Definition: GroupManagement.cpp:1294
int m_groupsformed
Number of groups formed.
Definition: GroupManagement.hpp:185
void HandleIncomingMessage(boost::shared_ptr< const ModuleMessage > msg, CPeerNode peer)
Handles received messages.
Definition: GroupManagement.cpp:121
void HandleAreYouThere(const AreYouThereMessage &msg, CPeerNode peer)
Handles recieving are you there messsages.
Definition: GroupManagement.cpp:1038
GMAgent()
Constructor for using this object as a module.
Definition: GroupManagement.cpp:78
std::string GetUUID() const
Gets the UUID of this process.
Definition: IDGIModule.cpp:45
General FREEDM Namespace.
Definition: CBroker.cpp:53
void HandleAreYouCoordinator(const AreYouCoordinatorMessage &msg, CPeerNode peer)
Handles recieving are you coordinator messages.
Definition: GroupManagement.cpp:1009
static PeerSet ProcessPeerList(const PeerListMessage &msg)
Handles Processing a PeerList.
Definition: GroupManagement.cpp:895
std::string Coordinator() const
Returns the coordinators uuid.
Definition: GroupManagement.hpp:139
void Check(const boost::system::error_code &err)
Checks for other up leaders.
Definition: GroupManagement.cpp:513
CBroker::TimerHandle m_timer
A timer for stepping through the election process.
Definition: GroupManagement.hpp:166
bool IsCoordinator() const
Returns true if this node considers itself a coordinator.
Definition: GroupManagement.hpp:64
int m_membership
Total size of groups after all checks.
Definition: GroupManagement.hpp:193
int m_groupselection
Number of elections started.
Definition: GroupManagement.hpp:189
void InviteGroupNodes(const boost::system::error_code &err, PeerSet p_tempSet)
Sends invitations to all group members.
Definition: GroupManagement.cpp:775
void SetStatus(int status)
Sets the status of the node.
Definition: GroupManagement.cpp:1347
TimedPeerSet m_AYCResponse
Nodes expecting AYC response from.
Definition: GroupManagement.hpp:151
boost::posix_time::time_duration INVITE_RESPONSE_TIMEOUT
How long to wait for responses from other nodes.
Definition: GroupManagement.hpp:182
std::map< std::string, CPeerNode > PeerSet
Provides a PeerSet type for a module templated on T.
Definition: PeerSets.hpp:35
boost::posix_time::time_duration CHECK_TIMEOUT
How long between AYC checks.
Definition: GroupManagement.hpp:172
google::protobuf::uint32 m_GroupID
The ID number of the current group (Never initialized for fun)
Definition: GroupManagement.hpp:156