@@ -149,10 +149,13 @@ public void handleConnection(InputStream is, OutputStream os) {
149149 System .out .println (b .toString ());
150150 //>>>>>>>>>>>>>>>>>>>debug
151151
152+ // era we are about to transmit
152153 int workingEra = this .getEraStartSync (peer );
154+
155+ // newest era (which is not necessarily highest number!!)
153156 int currentEra = this .era ;
154157
155- // we start a conversation - increase era
158+ // we start a conversation - increase era for newly produced messages
156159 this .incrementEra ();
157160
158161 //<<<<<<<<<<<<<<<<<<debug
@@ -175,9 +178,22 @@ public void handleConnection(InputStream is, OutputStream os) {
175178 b .append ("memento saved" );
176179 System .out .println (b .toString ());
177180 //>>>>>>>>>>>>>>>>>>>debug
178-
181+
182+ /*
183+ There is a little challenge: era uses a circle of numbers
184+ We cannot say: higher number, later era. That rule does *not*
185+ apply. We can calculate next era, though.
186+
187+ That loop has to be re-entered as long as working era has not
188+ yet reached currentEra. In other words: lastRound is reached whenever
189+ workingEra == currentEra. Processing currentEra is the last round
190+ We at at least one round!
191+ */
192+
193+ boolean lastRound = false ; // assume more than one round
179194 do {
180-
195+ lastRound = workingEra == currentEra ;
196+
181197 List <ASP3Chunk > chunks = this .chunkStorage .getChunks (workingEra );
182198 //<<<<<<<<<<<<<<<<<<debug
183199 b = new StringBuilder ();
@@ -211,6 +227,7 @@ public void handleConnection(InputStream is, OutputStream os) {
211227 b = new StringBuilder ();
212228 b .append (this .getLogStart ());
213229 b .append ("send chunk" );
230+ System .out .println (b .toString ());
214231 //>>>>>>>>>>>>>>>>>>>debug
215232 this .sendChunk (chunk , dos );
216233
@@ -219,15 +236,18 @@ public void handleConnection(InputStream is, OutputStream os) {
219236 //<<<<<<<<<<<<<<<<<<debug
220237 b = new StringBuilder ();
221238 b .append (this .getLogStart ());
222- b .append ("removed recipient" );
239+ b .append ("removed recipient " );
223240 b .append (peer );
241+ System .out .println (b .toString ());
224242 //>>>>>>>>>>>>>>>>>>>debug
225243 // empty?
226244 if (chunk .getRecipients ().isEmpty ()) {
227245 chunk .drop ();
228246 //<<<<<<<<<<<<<<<<<<debug
247+ b = new StringBuilder ();
229248 b .append (this .getLogStart ());
230249 b .append ("chunk dropped" );
250+ System .out .println (b .toString ());
231251 }
232252 }
233253
@@ -240,8 +260,8 @@ public void handleConnection(InputStream is, OutputStream os) {
240260 // next era which isn't necessarilly workingEra++
241261 workingEra = this .getNextEra (workingEra );
242262
243- // until served era we came in in the first place
244- } while (workingEra != currentEra );
263+ // as long as not already performed last round
264+ } while (! lastRound );
245265
246266 //<<<<<<<<<<<<<<<<<<debug
247267 b = new StringBuilder ();
@@ -379,6 +399,7 @@ private void sendChunk(ASP3Chunk chunk, DataOutputStream dos)
379399 b .append (")" );
380400 b .append ("read message: " );
381401 b .append (message );
402+ System .out .println (b .toString ());
382403 //>>>>>>>>>>>>>>>>>>>debug
383404
384405 dos .writeUTF ((String ) message );
@@ -390,6 +411,7 @@ private void sendChunk(ASP3Chunk chunk, DataOutputStream dos)
390411 b .append (")" );
391412 b .append ("wrote message: " );
392413 b .append (message );
414+ System .out .println (b .toString ());
393415 //>>>>>>>>>>>>>>>>>>>debug
394416
395417 }
@@ -399,7 +421,7 @@ private void sendChunk(ASP3Chunk chunk, DataOutputStream dos)
399421 b .append (this .owner );
400422 b .append (")" );
401423 b .append ("stop iterating messages " );
402-
424+ System . out . println ( b . toString ());
403425 }
404426
405427 /**
0 commit comments