11
11
12
12
class LatteAggrement {
13
13
public:
14
- bool active;
15
14
long unsigned current_iter;
16
15
long unsigned ack_count;
17
16
long unsigned nack_count;
@@ -52,11 +51,8 @@ class LatteAggrement{
52
51
}
53
52
54
53
// Trigger the beb of the first proposed_value;
55
-
56
54
Tosend=vector<vector<Message>>(128 );
57
- accepted_value_vec.push_back (set<long unsigned >());
58
-
59
-
55
+ this ->accepted_value_vec .push_back (set<long unsigned >());
60
56
// Add the forst Proposal
61
57
Tobroadcast.push_back (Message (0 ,\
62
58
current_iter,myid,active_proposal_num,proposed_value));
@@ -70,9 +66,11 @@ class LatteAggrement{
70
66
while (1 ){
71
67
// BroadCast
72
68
// cout<<"Broadcast"<<endl;
69
+ unsigned int k=0 ;
73
70
mut_broadcast.lock ();
74
71
for (long unsigned i=0 ;i<Tobroadcast.size ();i++){
75
72
sendrange (Tobroadcast[i]);
73
+
76
74
}
77
75
mut_broadcast.unlock ();
78
76
// Send
@@ -94,13 +92,16 @@ class LatteAggrement{
94
92
// cout<<m.m_type<< " "<<m.value_set[0]<<endl;
95
93
for (long unsigned i=0 ;i<this ->host_num ;i++){
96
94
this ->pl_link .send (m,host_dicts[i]);
95
+ if (m.proposal_num ==1 &&i==2 ){
96
+ // cout<<"To 3"<<endl;
97
+ }
97
98
}
98
99
99
100
}
100
101
101
102
void upon_change_ack_nack (Message & m){
102
103
if (nack_count>0 && (ack_count+nack_count>=host_num/2 +host_num%2 ) &&
103
- m.iter ==current_iter){ // Modify the active bool
104
+ this -> current_iter == m.iter ){
104
105
active_proposal_num++;
105
106
ack_count=0 ;
106
107
nack_count=0 ;
@@ -111,12 +112,15 @@ class LatteAggrement{
111
112
current_iter,myid,active_proposal_num,proposed_value));// WARN: Modify Here
112
113
mut_broadcast.unlock ();
113
114
}
114
- else if (ack_count>=(host_num/2 +host_num%2 ) && m.iter ==current_iter ) {
115
+ else if (ack_count>=(host_num/2 +host_num%2 ) && this -> current_iter == m.iter ) {
115
116
// decide
116
117
Todecide.push_back (proposed_value);
117
118
cout<<" Decide" <<endl;
118
- // Clean the previous things;
119
- // Enter the next proposal stage(iter);
119
+ // this->current_iter++; // Enter the next proposal stage(iter);
120
+ /* ***************************************
121
+ * From last version code
122
+ *
123
+ */
120
124
this ->ack_count =0 ;
121
125
this ->nack_count =0 ;
122
126
this ->active_proposal_num =0 ;
@@ -172,11 +176,10 @@ class LatteAggrement{
172
176
void deliver (){
173
177
Message m;
174
178
while (1 ){
175
-
176
179
// Pay Attention: I would force perfect link only
177
180
// deliver message belonging to the same 'iter'
178
181
// and same 'propose_num'
179
- m=this ->pl_link .deliver ();
182
+ m=this ->pl_link .deliver (current_iter );
180
183
181
184
if (m.original_id !=0 ){
182
185
// ACK
@@ -190,6 +193,7 @@ class LatteAggrement{
190
193
}
191
194
// NACK
192
195
if (m.m_type ==2 &&m.proposal_num ==active_proposal_num&&m.iter ==current_iter){
196
+ // Add the modification above m.iter==current_iter
193
197
nack_count++;
194
198
for (long unsigned k=0 ;k<m.value_set_num ;k++){
195
199
proposed_value.insert (m.value_set [k]);
@@ -198,41 +202,41 @@ class LatteAggrement{
198
202
for (long unsigned i=0 ;i<m.value_set_num ;i++){
199
203
cout<<m.value_set [i]<<" " ;
200
204
}
201
- cout<<" activeround:" <<m.proposal_num <<" myround:" <<active_proposal_num <<endl;
205
+ cout<<" activeround:" <<m.proposal_num <<" myround:" <<active_proposal_num <<endl;
202
206
upon_change_ack_nack (m);
203
207
204
208
}
205
209
// PROPOSAL
210
+ // if(m.iter>=accepted_value_vec.size()){
211
+ // accepted_value_vec.push
212
+ // }
213
+ bool tag=mergeset (accepted_value_vec[m.iter -1 ],m);
214
+ if (m.m_type ==0 && tag){
215
+ // ACK
216
+ mut_send.lock ();
217
+ Tosend[m.original_id -1 ].push_back (Message (1 ,
218
+ m.iter ,myid,m.proposal_num ));
219
+ mut_send.unlock ();
220
+
221
+ cout<<" Send Ack Oid:" <<myid<<" To " <<m.original_id <<" Iter:" <<m.iter <<" Type:" <<m.m_type ;
222
+ cout<<" activeround:" <<m.proposal_num <<" myround:" <<active_proposal_num <<endl;
206
223
207
- // Modify
208
- if (m.m_type ==0 && m.iter <=current_iter){
209
- bool tag=mergeset (accepted_value_vec[m.iter -1 ],m);
210
- if (m.m_type ==0 && tag){
211
- // ACK
212
- mut_send.lock ();
213
- Tosend[m.original_id -1 ].push_back (Message (1 ,
214
- m.iter ,myid,m.proposal_num )); // Modify the current_iter to m.tier
215
- mut_send.unlock ();
216
-
217
- cout<<" Send Ack Oid:" <<myid<<" Iter " <<m.iter <<" To " <<m.original_id <<" Type:" <<m.m_type ;
224
+ }
225
+ else if (m.m_type ==0 && !tag){
226
+ // NACK
227
+ mut_send.lock ();
228
+ // m.iter not current iter
229
+ Tosend[m.original_id -1 ].push_back (Message (2 ,
230
+ m.iter ,myid,m.proposal_num ,accepted_value_vec[m.iter -1 ]));
231
+ mut_send.unlock ();
232
+
233
+ cout<<" Send NACK Oid:" <<myid<<" To " <<m.original_id <<" Type:" <<m.m_type <<" Value:" ;
234
+ for (auto it= accepted_value_vec[m.iter -1 ].begin ();it!=accepted_value_vec[m.iter -1 ].end ();it++){
235
+ cout<<*it<<" " ;
236
+ }
218
237
cout<<" activeround:" <<m.proposal_num <<" myround:" <<active_proposal_num <<endl;
219
-
220
- }
221
- else if (m.m_type ==0 && !tag){
222
- // NACK
223
- mut_send.lock ();
224
- Tosend[m.original_id -1 ].push_back (Message (2 ,
225
- m.iter ,myid,m.proposal_num ,accepted_value_vec[m.iter -1 ]));
226
- mut_send.unlock ();
227
-
228
- cout<<" Send NACK Oid:" <<myid<<" To " <<m.original_id <<" Type:" <<m.m_type <<" Value:" ;
229
- for (auto it= accepted_value_vec[m.iter -1 ].begin ();
230
- it!=accepted_value_vec[m.iter -1 ].end ();it++){
231
- cout<<*it<<" " ;
232
- }
233
- cout<<" activeround:" <<m.proposal_num <<" myround:" <<active_proposal_num <<endl;
234
- }
235
238
}
239
+
236
240
237
241
}
238
242
0 commit comments