-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGossipDASBuilder.java
More file actions
82 lines (69 loc) · 2.61 KB
/
GossipDASBuilder.java
File metadata and controls
82 lines (69 loc) · 2.61 KB
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
package peersim.kademlia.das;
import java.util.Arrays;
import peersim.config.Configuration;
import peersim.kademlia.Message;
import peersim.kademlia.gossipsub.GossipSubProtocol;
public class GossipDASBuilder extends GossipDAS {
protected boolean started;
public GossipDASBuilder(String prefix) {
super(prefix);
started = false;
bw = Configuration.getInt(prefix + "." + PAR_BW, KademliaCommonConfigDas.BUILDER_UPLOAD_RATE);
}
@Override
public Object clone() {
GossipDASBuilder dolly = new GossipDASBuilder(GossipDASBuilder.prefix);
return dolly;
}
protected void handleInitNewBlock(Message m, int myPid) {
currentBlock = (Block) m.body;
logger.warning("Builder Init block");
if (!started) {
started = true;
String rowTopic = "", columnTopic = "";
for (int j = 1; j <= KademliaCommonConfigDas.BLOCK_DIM_SIZE; j++) {
String topic = topicMap.getRowTopic(j);
if (rowTopic != topic) {
gossipsub.Join(topic);
GossipSubProtocol.getTable().addPeer(topic, gossipsub.getGossipNode().getId());
}
rowTopic = topic;
topic = topicMap.getColumnTopic(j);
if (columnTopic != topic) {
gossipsub.Join(topic);
GossipSubProtocol.getTable().addPeer(topic, gossipsub.getGossipNode().getId());
}
columnTopic = topic;
}
} else {
for (int i = 1; i <= KademliaCommonConfigDas.BLOCK_DIM_SIZE; i++) {
Sample[] samples = currentBlock.getSamplesByRow(i);
String topic = topicMap.getRowTopic(i);
Message msg =
Message.makePublishMessage(topic, Arrays.copyOfRange(samples, 0, samples.length / 2));
msg.src = this.gossipsub.node;
gossipsub.Publish(msg, myPid);
samples = currentBlock.getSamplesByColumn(i);
topic = topicMap.getColumnTopic(i);
msg = Message.makePublishMessage(topic, Arrays.copyOfRange(samples, 0, samples.length / 2));
msg.src = this.gossipsub.node;
gossipsub.Publish(msg, myPid);
}
}
}
@Override
protected void handleGetSample(Message m, int myPid) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'handleGetSample'");
}
@Override
protected void handleGetSampleResponse(Message m, int myPid) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'handleGetSampleResponse'");
}
@Override
public void messageReceived(Message m) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'messageReceived'");
}
}