| @ -0,0 +1,82 @@ | |||
| /* | |||
| * Node.cpp | |||
| * | |||
| * Created on: 10.01.2017 | |||
| * Author: piotrek | |||
| */ | |||
| #include "Node.h" | |||
| Node::Node() | |||
| { | |||
| // TODO Auto-generated constructor stub | |||
| } | |||
| Node::~Node() | |||
| { | |||
| // TODO Auto-generated destructor stub | |||
| } | |||
| /* | |||
| * funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki | |||
| * z jednej strony | |||
| */ | |||
| bool Node::connectNode(Node *node) | |||
| { | |||
| vector<Node*>::iterator it = this->connectedNodes.begin(); | |||
| for (; it != this->connectedNodes.end(); ++it) //sprawdzamy, czy połączenia już przypadkiem nie ma | |||
| { | |||
| if (*it == node) | |||
| return false; | |||
| } | |||
| this->connectedNodes.push_back(node); // podłączamy drugi węzeł | |||
| node->connectNode(this); // podłączamy drugą stronę | |||
| return true; | |||
| } | |||
| void Node::send(Packet packet) | |||
| { | |||
| } | |||
| Packet Node::recv() | |||
| { | |||
| } | |||
| void Node::setHostname(string hostname) | |||
| { | |||
| } | |||
| void Node::setIp(string ip) | |||
| { | |||
| } | |||
| void Node::setMask(string mask) | |||
| { | |||
| } | |||
| string Node::getHostname() | |||
| { | |||
| } | |||
| string Node::getIp() | |||
| { | |||
| } | |||
| string Node::getMask() | |||
| { | |||
| } | |||
| void Node::onRecv() | |||
| { | |||
| } | |||
| @ -0,0 +1,46 @@ | |||
| /* | |||
| * Node.h | |||
| * | |||
| * Created on: 10.01.2017 | |||
| * Author: piotrek | |||
| */ | |||
| #ifndef NODE_H_ | |||
| #define NODE_H_ | |||
| #include "common.h" | |||
| #include "Packet.h" | |||
| typedef struct { | |||
| string ip; | |||
| string mask; | |||
| } NetConf; | |||
| class Node | |||
| { | |||
| queue<Packet>rcvPackets; // kolejka z pakietami do przetworzenia | |||
| vector<Node*> connectedNodes; // referencje do węzłów, z którymi jest podłączony | |||
| NetConf netConf; // konfiguracja sieciowa | |||
| string hostname; // nazwa węzła | |||
| public: | |||
| Node(); | |||
| virtual ~Node(); | |||
| bool connectNode(Node *node); | |||
| void send(Packet packet); | |||
| Packet recv(); | |||
| // settery | |||
| void setHostname(string hostname); | |||
| void setIp(string ip); | |||
| void setMask(string mask); | |||
| // gettery | |||
| string getHostname(); | |||
| string getIp(); | |||
| string getMask(); | |||
| virtual void onRecv(); // wirtualna metoda na odbiór i dalszą akcję | |||
| }; | |||
| #endif /* NODE_H_ */ | |||
| @ -0,0 +1,19 @@ | |||
| /* | |||
| * common.h | |||
| * | |||
| * Created on: 10.01.2017 | |||
| * Author: piotrek | |||
| */ | |||
| #ifndef COMMON_H_ | |||
| #define COMMON_H_ | |||
| #include <iostream> | |||
| #include <queue> | |||
| #include <map> | |||
| #include <functional> | |||
| using namespace std; | |||
| #endif /* COMMON_H_ */ | |||