-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeer.java
72 lines (59 loc) · 1.67 KB
/
Peer.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
import java.util.BitSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
public class Peer {
private int id;
private int port;
private String address;
private boolean hasCompleteFile;
private BitSet bitSet;
public AtomicLong bytesDownloadedFrom;
public Peer(int id){
this.id = id;
}
public Peer(int id, int port, String address, boolean hasCompleteFile){
this.id = id;
this.port = port;
this.address = address;
this.hasCompleteFile = hasCompleteFile;
int totalPieces = ApplicationProperties.getInstance().getTotalPieces();
this.bitSet = new BitSet(totalPieces);
if(hasCompleteFile){
this.bitSet.set(0, totalPieces);
}
this.bytesDownloadedFrom = new AtomicLong(0);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void setHasCompleteFile(boolean hasCompleteFile){
this.hasCompleteFile = hasCompleteFile;
}
public boolean getHasCompleteFile(){
return this.hasCompleteFile;
}
public String toString(){
return this.id + ":" + this.address + ":" + this.port + ":" + this.hasCompleteFile;
}
public BitSet getBitSet(){
return this.bitSet;
}
public void setBitSet(BitSet bitSet){
this.bitSet = bitSet;
}
}