-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeighborInfo.java
157 lines (124 loc) · 3.71 KB
/
NeighborInfo.java
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import java.net.Socket;
// This class is used to store the information of each peer such as choked or unchoked and so on. Besides
// this class also creates the comparator according to the download speed.
public class NeighborInfo implements Comparable {
private int peerID;
private Socket socket;
private String hostName;
private int port;
private boolean preferred;
private boolean optimisticallyUnchoked;
private double downloadRate;
private boolean hasCompleteFile;
private boolean isInterested;
private boolean interest;
private boolean isChoked = true;
private boolean choke = true;
private Client client;
private int downloadedPieceNum = 0;
public int getDownloadedPieceNum() {
return downloadedPieceNum;
}
public void setDownloadedPieceNum(int downloadedPieceNum) {
this.downloadedPieceNum = downloadedPieceNum;
}
public void downloadedPieceNumIncrement() {
this.downloadedPieceNum += 1;
}
public NeighborInfo(int peerID, String hostName, int port, Boolean hasCompleteFile, Client client) {
this.peerID = peerID;
this.hostName = hostName;
this.port = port;
this.hasCompleteFile = hasCompleteFile;
this.client = client;
}
public NeighborInfo(int peerID, String hostName, int port, Boolean hasCompleteFile) {
this.peerID = peerID;
this.hostName = hostName;
this.port = port;
this.hasCompleteFile = hasCompleteFile;
}
public int getPeerID() {
return peerID;
}
public void setPeerID(int peerID) {
this.peerID = peerID;
}
public Socket getSocket() {
return socket;
}
public void setSocket(Socket socket) {
this.socket = socket;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public boolean isPreferred() {
return preferred;
}
public void setPreferred(boolean preferred) {
this.preferred = preferred;
}
public boolean isOptimisticallyUnchoked() {
return optimisticallyUnchoked;
}
public void setOptimisticallyUnchoked(boolean optimisticallyUnchoked) {
this.optimisticallyUnchoked = optimisticallyUnchoked;
}
public double getDownloadRate() {
return downloadRate;
}
public void setDownloadRate(double downloadRate) {
this.downloadRate = downloadRate;
}
public boolean isHasCompleteFile() {
return hasCompleteFile;
}
public void setHasCompleteFile(boolean hasCompleteFile) {
this.hasCompleteFile = hasCompleteFile;
}
public boolean isInterested() {
return isInterested;
}
public void setInterested(boolean isInterested) {
this.isInterested = isInterested;
}
public boolean isInterest() {
return interest;
}
public void setInterest(boolean interest) {
this.interest = interest;
}
public boolean isChoked() {
return isChoked;
}
public void setChoked(boolean isChoked) {
this.isChoked = isChoked;
}
public boolean isChoke() {
return choke;
}
public void setChoke(boolean choke) {
this.choke = choke;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
@Override
public int compareTo(Object o) {
NeighborInfo neighborInfo = (NeighborInfo) o;
return (int) (this.downloadRate - neighborInfo.downloadRate);
}
}