The MasterSlaveFramework demonstrates a basic setup for a Master-Slave architecture where a master node distributes tasks to multiple slave nodes for independent processing.
This framework was designed for educational purposes to serve better understanding regarding Master-Slave architecture and socket communication.
- Master Node: Responsible for task distribution, coordination and connection storage.
- Slave Node: Execute assigned tasks by the Master Node.
- Task Queue: Tasks are placed in a queue and processed by the slave node.
- Task Delegation: Allows the master node to assign tasks to a slave node for execution.
- Easy Task Implementation: With a few lines of code, a new task can be easily added.
- Simple Communication Protocol: Uses Winsocket for inter-node communication.
git clone https://github.com/0xMegaByte/MasterSlaveFramework.git
cd MasterSlaveFramework
The solution was originally built with:
- Visual Studio 2022
- Windows 10 SDK
- Toolset v143
In MSF (MasterSlaveFramework), task functionalities are implemented within the slave nodes and are triggered for execution upon receiving a MSFPacket task from the master node.
When a slave node recieves a MSFPacket task, it parses the packet and creates a new task object.
Then pushes the newly created task to its TaskExecutor instance, which in its turn executes tasks' callbacks by their TaskId.
To add new task a few implementations need to take place in the Slave files and Utils library.
Under Communication.h file, add a new task id under EPACKET::Task.
This addition to the communication engine gives both the master and slave nodes the ability to send/receive/execute a task packet.
namespace EPACKET
{
enum class Task
{
TASK_BEEP = 2000,
TASK_OPEN_CMD
};
}
In the Task.cpp file, create your task's callback using the TASK_CALLBACK_THREAD macro. For example:
TASK_CALLBACK_THREAD(MakeABeep)
{
Beep(1000, 100);
return 0;
}
Than, insert a new pair of <EPACKET::Task::TASK_BEEP,&MakeABeep> to the TaskCallbacks map
void TaskExecutor::MakeTaskCallbacks()
{
if (this->m_pTaskCallbacks)
{
TaskCallbacks& TaskCallbacks = *this->m_pTaskCallbacks;
TaskCallbacks.insert({ EPACKET::Task::TASK_BEEP,&MakeABeep });
}
}
Now you can create a new MSFPacket task in the master and send it to a slave node.
MSFPacket* pTaskPacket = new MSFPacket(
EPACKET::PacketType::TaskPacket,
ulSlaveId,
EPACKET::Task::TASK_BEEP,
(unsigned char*)"SomeData");
If you would like to contribute to this project, please feel free to submit a pull request. I welcome any suggestions or improvements that you may have.
This project was created by Matan Shitrit @0xMegaByte.
This project is licensed under the GPL-3.0. See the LICENSE file for more information.
