| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -7,27 +7,81 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include "Node.h"
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Node::Node() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Node * Node::findConnection(string ip) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						// TODO Auto-generated constructor stub
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						if (ip == "0.0.0.0") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return NULL; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						vector<Node*>::iterator it = this->connectedNodes.begin(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						for (; it != this->connectedNodes.end(); ++it) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							if ((*it)->getIp() == ip) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									return *it; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return NULL; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/* funkcja pobiera i usuwa pakiet z bufora "karty sieciowej" */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Packet Node::recv() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						Packet packet; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						if (!this->rcvBuffer.empty()) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							packet = this->rcvBuffer.front(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							this->rcvBuffer.pop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return packet; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Node::Node() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setHostname(""); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setIp("0.0.0.0"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setMask("0.0.0.0"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setGatewayIp("0.0.0.0"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Node::~Node() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						// TODO Auto-generated destructor stub
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->connectedNodes.clear(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						while(!this->rcvBuffer.empty()) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							this->rcvBuffer.pop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Node::Node(string hostname) : Node() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setHostname(hostname); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Node::Node(string hostname, string ip, string mask) : Node(hostname) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setIp(ip); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setMask(mask); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Node::Node(string hostname, string ip, string mask, string gatewayIp) : Node(hostname, ip, mask) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->setGatewayIp(gatewayIp); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/*
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * z jednej strony | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * @param firstConnected - oznacza, czy pierwsza strona jest podlaczona (jezeli nie to sprawdzamy | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * czy polaczenie juz gdzies zostalo przypadkowo nawiazane, nawiazujemy polaczenie, a nastepnie | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * przekazujemy sterowanie drugiemu wezlowi zeby zrobil to samo) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					bool Node::connectNode(Node *node, bool firstConnected) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						if (node->getIp() == "0.0.0.0")		// jezeli wezel nie ma skonfigurowanej sieci, nie mozna go przylaczyc
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return false; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						if (!firstConnected) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							vector<Node*>::iterator it = this->connectedNodes.begin(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							for (; it != this->connectedNodes.end(); ++it)	//sprawdzamy, czy połączenia już przypadkiem nie ma
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							for (; it != this->connectedNodes.end(); ++it)	// sprawdzamy, czy połączenia już przypadkiem nie ma
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if (*it == node) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									return false; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -41,43 +95,73 @@ bool Node::connectNode(Node *node, bool firstConnected) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return true; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Node::send(Packet packet) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/*
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * funkcja wysyla, czyli przekazuje kopie pakietu kolejnemu wezlowi - docelowemu lub bramie domyslnej | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * o ile jest skonfigurowana i istnieje do niej sciezka | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * TODO zaimplementowac porownywanie z maska - jezeli dstIp z maska nie gra, wysylac na ruter | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					bool Node::send(Packet packet) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						Node *node; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						node = this->findConnection(packet.getDstIp()); // znajdz bezposrednia trase
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						if (!node) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							node = this->findConnection(this->getGatewayIp()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						if (!node) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return false;	//nie ma zadnej trasy do wezla
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						node->putPacket(packet); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return true; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Packet Node::recv() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/*
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * funkcja jest modelem karty sieciowej - odbiera dane z sieci i umieszcza je | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * w swoim buforze (czy tam systemie) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Node::putPacket(Packet packet) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->rcvBuffer.push(packet); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Node::setHostname(string hostname) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->hostname = hostname; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Node::setIp(string ip) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->netConf.ip = ip; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Node::setMask(string mask) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->netConf.mask = mask; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Node::setGatewayIp(string gatewayIp) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						this->netConf.gatewayIp = gatewayIp; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					string Node::getHostname() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return this->hostname; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					string Node::getIp() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return this->netConf.ip; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					string Node::getMask() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return this->netConf.mask; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					string Node::getGatewayIp() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						return this->netConf.gatewayIp; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Node::onRecv() | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
 |