Skip to content

0xMegaByte/MasterSlaveFramework

Repository files navigation

MSF LOGO

OS badge C++ badge GPLv3 License

Overview

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.

Features

  • 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.

Getting started

Clone Repository

git clone https://github.com/0xMegaByte/MasterSlaveFramework.git
cd MasterSlaveFramework

Build

The solution was originally built with:

Tasks

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.

Create you own task (MakeABeep)

To add new task a few implementations need to take place in the Slave files and Utils library.

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
	};
}

Slave Files

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");

Contributing

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.

Authors

This project was created by Matan Shitrit @0xMegaByte.

License

This project is licensed under the GPL-3.0. See the LICENSE file for more information.

About

A socket-based master-slaves framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors