-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNode.cpp
66 lines (43 loc) · 1.01 KB
/
Node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Node.h"
using namespace std;
//add new node
void Node::addNewNode(char * ip, int port){
bool alreadyExists = false;
for (int i = 0; (i < qtd_nos) && !(alreadyExists); i++)
if (strcmp(ips[i],ip) == 0)
alreadyExists = true;
if (!alreadyExists){
ips[qtd_nos] = ip;
ports[qtd_nos] = port;
qtd_nos++;
}
}
//remove node
void Node::removeNode(char * ip){
for (int i = 0; i < qtd_nos; i++){
if (strcmp(ips[i],ip) == 0){
qtd_nos--;
if(i != qtd_nos){
ips[i] = ips[qtd_nos];
ports[i] = ports[qtd_nos];
}
}
}
}
//returns ip
char * Node::getIP(int i){
return ips[i];
}
//returns port number
int Node::getPorta(int i){
return ports[i];
}
//show friend list
void Node::exibirNos(){
for (int i = 0; i<qtd_nos; i++)
cout<<"Node number "<<i<<endl<<"ip = "<<ips[i]<<endl<<"port= "<<ports[i]<<endl;
}
//returns total quantity of nodes in network
int Node::getQtdNos(){
return qtd_nos;
}