-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveProtocol.java
More file actions
65 lines (43 loc) · 935 Bytes
/
RemoveProtocol.java
File metadata and controls
65 lines (43 loc) · 935 Bytes
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
package example.progetto;
import peersim.util.*;
import peersim.core.*;
import peersim.config.*;
import peersim.cdsim.*;
import java.util.Random;
import peersim.transport.Transport;
import peersim.cdsim.CDProtocol;
import peersim.edsim.EDProtocol;
import peersim.vector.SingleValueHolder;
import java.util.*;
//Classe che estende IdleProtocol e Permette la rimozione di nodi dal protocollo
public class RemoveProtocol extends IdleProtocol {
public RemoveProtocol (String s){
super(s);
}
public boolean remNeighbor(Node n)
{
boolean found = false;
for (int i = 0; i < len; i++)
{
if (neighbors[i] == n)
{neighbors[i] =null;
found = true;}
}
if (found == true)
{
len--;
Node[] temp = new Node[len];
int nw = 0;
for (int i = 0; i<neighbors.length;i++)
{
if (neighbors[i] !=null)
{
temp[nw] = neighbors[i];
nw++;
}
}
neighbors = temp;
}
return true;
}
}