Skip to content

Commit 84dcdff

Browse files
committed
bug fix - era change are not completely made persistent while running aasp.
Fully delivered chunks are no longer dropped per default.
1 parent 504150d commit 84dcdff

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

src/net/sharksystem/aasp/AASPEngine.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See ASPChunkStorage for details.
1515
*
1616
* @see AASPStorage
17-
* @see AASPReader
1817
* @author thsc
1918
*/
2019
public abstract class AASPEngine implements AASPStorage, AASPProtocolEngine {
@@ -37,6 +36,7 @@ public abstract class AASPEngine implements AASPStorage, AASPProtocolEngine {
3736
protected AASPMemento memento = null;
3837

3938
/* private */ final private AASPChunkStorage chunkStorage;
39+
private boolean dropDeliveredChunks = false;
4040

4141
protected AASPEngine(AASPChunkStorage chunkStorage)
4242
throws AASPException, IOException {
@@ -87,7 +87,7 @@ public void add(CharSequence urlTarget, CharSequence message) throws IOException
8787

8888
private String getLogStart() {
8989
StringBuilder b = new StringBuilder();
90-
b.append("ASP3Engine (");
90+
b.append("AASPEngine (");
9191
b.append(this.owner);
9292
b.append(") ");
9393

@@ -208,10 +208,10 @@ public void handleConnection(InputStream is, OutputStream os,
208208
//>>>>>>>>>>>>>>>>>>>debug
209209

210210
// is not a public chunk
211-
if(!this.isPublic(chunk)) {
211+
if (!this.isPublic(chunk)) {
212212
List<CharSequence> recipients = chunk.getRecipients();
213213

214-
if(!recipients.contains(peer)) {
214+
if (!recipients.contains(peer)) {
215215
continue;
216216
}
217217
}
@@ -234,13 +234,20 @@ public void handleConnection(InputStream is, OutputStream os,
234234
System.out.println(b.toString());
235235
//>>>>>>>>>>>>>>>>>>>debug
236236
// empty?
237-
if(chunk.getRecipients().isEmpty()) {
238-
chunk.drop();
239-
//<<<<<<<<<<<<<<<<<<debug
240-
b = new StringBuilder();
241-
b.append(this.getLogStart());
242-
b.append("chunk dropped");
243-
System.out.println(b.toString());
237+
if (chunk.getRecipients().isEmpty()) {
238+
if (this.isDropDeliveredChunks()) {
239+
chunk.drop();
240+
//<<<<<<<<<<<<<<<<<<debug
241+
b = new StringBuilder();
242+
b.append(this.getLogStart());
243+
b.append("chunk dropped");
244+
System.out.println(b.toString());
245+
} else {
246+
b = new StringBuilder();
247+
b.append(this.getLogStart());
248+
b.append("drop flag set false - engine does not remove delivered chunks");
249+
System.out.println(b.toString());
250+
}
244251
}
245252
}
246253

@@ -297,6 +304,14 @@ public void handleConnection(InputStream is, OutputStream os,
297304
// }
298305
}
299306

307+
private boolean isDropDeliveredChunks() {
308+
return this.dropDeliveredChunks;
309+
}
310+
311+
public void setDropDeliveredChunks(boolean drop) {
312+
this.dropDeliveredChunks = drop;
313+
}
314+
300315
static int nextEra(int workingEra) {
301316
if(workingEra == Integer.MAX_VALUE) {
302317
return 0;
@@ -375,7 +390,10 @@ private synchronized void incrementEra() throws IOException {
375390
this.era = this.getNextEra(this.era);
376391

377392
// drop very very old chunks - if available
378-
this.chunkStorage.dropChunks(this.era);
393+
this.chunkStorage.dropChunks(this.era);
394+
395+
// persistent values
396+
if(this.memento != null) this.memento.save(this);
379397
}
380398

381399
/**

src/net/sharksystem/aasp/AASPProtocolEngine.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@
1111
interface AASPProtocolEngine {
1212
public void handleConnection(InputStream is, OutputStream os,
1313
AASPReceivedChunkListener listener) throws IOException;
14+
15+
/**
16+
* Chunks are (tried to be) delivered to their recipients during each encounter
17+
* with another peer. After successful delivery, recipient is withdrawn from recipient
18+
* list to prevent mutliple delivery.
19+
*
20+
* If this flag is set, chunk are removed permanently if their are delivered
21+
* to all their recipients. If no set, they remain intact.
22+
* @param drop
23+
*/
24+
void setDropDeliveredChunks(boolean drop);
1425
}

test/net/sharksystem/aasp/BasicTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public void androidUsage() throws IOException, AASPException, InterruptedExcepti
2929

3030
// alice writes a message into chunkStorage
3131
AASPStorage aliceStorage =
32-
AASPEngineFS.getAASPChunkStorage(ALICE_FOLDER);
32+
AASPEngineFS.getAASPChunkStorage(ALICE, ALICE_FOLDER);
3333

3434
aliceStorage.add(ALICE_BOB_CHAT_URL, ALICE2BOB_MESSAGE);
3535

3636
// bob does the same
3737
AASPStorage bobStorage =
38-
AASPEngineFS.getAASPChunkStorage(BOB_FOLDER);
38+
AASPEngineFS.getAASPChunkStorage(BOB, BOB_FOLDER);
3939

4040
bobStorage.add(ALICE_BOB_CHAT_URL, BOB2ALICE_MESSAGE);
4141

@@ -71,7 +71,7 @@ public void androidUsage() throws IOException, AASPException, InterruptedExcepti
7171
bobChannel.getOutputStream(), bobListener);
7272

7373
// wait until communication probably ends
74-
Thread.sleep(10000);
74+
Thread.sleep(5000);
7575

7676
// close connections: note AASPEngine does NOT close any connection!!
7777
aliceChannel.close();
@@ -114,5 +114,10 @@ public void androidUsage() throws IOException, AASPException, InterruptedExcepti
114114
// expect bob
115115
Assert.assertEquals(1, senderList.size());
116116
Assert.assertTrue(BOB.equalsIgnoreCase(senderList.get(0).toString()));
117+
118+
// simulate a sync
119+
bobStorage = AASPEngineFS.getAASPChunkStorage(BOB, BOB_FOLDER);
120+
Assert.assertEquals(1, bobStorage.getEra());
121+
Assert.assertEquals(bobEngine.getEra(), bobStorage.getEra());
117122
}
118123
}

0 commit comments

Comments
 (0)