-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynSender.java
56 lines (33 loc) · 1.34 KB
/
SynSender.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
/* Le Hénaff Pablo ; Basudan Hossam*/
public class SynSender implements SimpleMessageHandler, Runnable {
MuxDemuxSimple myMuxDemux;
@Override
public void run() {
// periodically send SYN messages to peers to become synchronized
while(true) {
try {
Thread.sleep(Test.SENDINGPERIOD);
for (PeerRecord pr : myMuxDemux.getPeerTable()) {
// checks whether pr has state = synchronized
if (!pr.getPeerState().equals("synchronized") && pr.getPeerSeqNum()!=-1) {
// senderId = myID
SynMessage toBeSent = new SynMessage(myMuxDemux.getMyID(), pr.getPeerID() ,pr.getPeerSeqNum());
myMuxDemux.send(toBeSent.getSynMessageAsEncodedString());
}
}
} catch (Exception e) { // catches InterruptedException and exceptions for badly formated SynMessage
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void handleMessage(String m) {
// nothing to do here
}
@Override
public void setMuxDemux(MuxDemuxSimple muxDemuxSimple) {
// we need to store a reference to our main component in order to access the peertable
myMuxDemux = muxDemuxSimple;
}
}