@@ -105,17 +105,22 @@ private boolean isPublic(ASAPInternalChunk chunk) {
105
105
106
106
@ Override
107
107
public void newEra () {
108
+ this .newEra (false , -1 );
109
+ }
110
+
111
+ private void newEra (boolean force , int nextEra ) {
108
112
try {
109
113
this .syncMemento ();
110
114
} catch (IOException e ) {
111
115
Log .writeLogErr (this , this .toString (),"cannot read memento: " + e .getLocalizedMessage ());
112
116
}
113
117
114
- if (this .contentChanged ) {
115
- Log .writeLog (this , this .toString (), "content changed - increment era..." );
118
+ if (force || this .contentChanged ) {
119
+ if (this .contentChanged ) Log .writeLog (this , this .toString (), "content changed - increment era..." );
120
+ if (force ) Log .writeLog (this , this .toString (), "increment era to add new chunks" );
116
121
try {
117
122
int oldEra = this .era ;
118
- int nextEra = this .getNextEra (this .era );
123
+ nextEra = nextEra < 0 ? this .getNextEra (this .era ) : nextEra ;
119
124
120
125
// set as fast as possible to make race conditions less likely
121
126
this .contentChanged = false ;
@@ -268,6 +273,15 @@ public ASAPChunkStorage getChunkStorage() {
268
273
return this .chunkStorage ;
269
274
}
270
275
276
+
277
+ @ Override
278
+ public ASAPInternalChunk createNewChunk (String uri , int newEra ) throws IOException {
279
+ ASAPInternalChunk chunk = this .getChunkStorage ().getChunk (uri , newEra );
280
+ // set new era
281
+ this .newEra (true , newEra );
282
+ return chunk ;
283
+ }
284
+
271
285
ASAPChunkStorage getStorage () {
272
286
return this .chunkStorage ;
273
287
}
@@ -394,7 +408,7 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
394
408
//>>>>>>>>>>>>>>>>>>>debug
395
409
396
410
// get received storage
397
- ASAPStorage incomingStorage = this .getIncomingStorage (senderE2E , true );
411
+ ASAPInternalStorage incomingStorage = ( ASAPInternalStorage ) this .getIncomingStorage (senderE2E , true );
398
412
ASAPChunkStorage incomingChunkStorage = incomingStorage .getChunkStorage ();
399
413
//ASAPChunkStorage incomingChunkStorage = this.getReceivedChunksStorage(senderE2E);
400
414
Log .writeLog (this , this .toString (), "got incoming chunk storage for senderE2E: " + senderE2E );
@@ -436,7 +450,8 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
436
450
return ;
437
451
}
438
452
439
- ASAPInternalChunk incomingChunk = incomingChunkStorage .getChunk (uri , eraSender );
453
+ ASAPInternalChunk incomingChunk = incomingStorage .createNewChunk (uri , eraSender );
454
+ //ASAPInternalChunk incomingChunk = incomingChunkStorage.getChunk(uri, eraSender);
440
455
441
456
if (localChunk != null ) {
442
457
Log .writeLog (this , this .toString (), "copy local meta data into newly created incoming chunk" );
@@ -555,15 +570,31 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
555
570
Log .writeLog (this , this .toString (), b .toString ());
556
571
//>>>>>>>>>>>>>>>>>>>debug
557
572
558
- Integer lastSeenEra = this .lastSeen .get (senderID );
573
+ // init
574
+ int workingEra = this .getOldestEra ();
559
575
560
- if (lastSeenEra == null ) {
561
- // still nothing
562
- lastSeenEra = this .getOldestEra ();
576
+ // already met?
577
+ if (this .lastSeen != null ) {
578
+ Integer lastSeenEra = this .lastSeen .get (senderID );
579
+ if (lastSeenEra != null ) workingEra = lastSeenEra ;
563
580
}
564
581
565
- int workingEra = lastSeenEra ;
566
- Log .writeLog (this , this .toString (), "last_seen: " + workingEra + " | era: " + this .era );
582
+ // got even information from other side?
583
+ Map <String , Integer > encounterMap = asapInterest .getEncounterMap ();
584
+ Log .writeLog (this , this .toString (), "received encounterMap: " + encounterMap );
585
+
586
+ /*
587
+ // am I in encounter list?
588
+ if(encounterMap != null) {
589
+ int eraEncounter = encounterMap.get(this.owner);
590
+ if(ASAP.isEraInRange(eraEncounter, this.getOldestEra(), workingEra)) {
591
+ // this seems to be a valid era - maybe got routed data
592
+ workingEra = eraEncounter;
593
+ }
594
+ }
595
+ */
596
+
597
+ Log .writeLog (this , this .toString (), "transmit chunks from " + workingEra + " to era: " + this .era );
567
598
568
599
if (workingEra == this .era ) {
569
600
// nothing todo
@@ -591,9 +622,6 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
591
622
/////////////////////////////////// asap routing
592
623
593
624
if (this .routingAllowed ()) {
594
- Map <String , Integer > encounterMap = asapInterest .getEncounterMap ();
595
- Log .writeLog (this , this .toString (), "routing allowed: encounterMap: " + encounterMap );
596
-
597
625
// iterate: what sender do we know in our side?
598
626
for (CharSequence receivedFromID : this .getSender ()) {
599
627
if (PeerIDHelper .sameID (encounteredPeer , receivedFromID )) {
0 commit comments