@@ -105,17 +105,22 @@ private boolean isPublic(ASAPInternalChunk chunk) {
105105
106106 @ Override
107107 public void newEra () {
108+ this .newEra (false , -1 );
109+ }
110+
111+ private void newEra (boolean force , int nextEra ) {
108112 try {
109113 this .syncMemento ();
110114 } catch (IOException e ) {
111115 Log .writeLogErr (this , this .toString (),"cannot read memento: " + e .getLocalizedMessage ());
112116 }
113117
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" );
116121 try {
117122 int oldEra = this .era ;
118- int nextEra = this .getNextEra (this .era );
123+ nextEra = nextEra < 0 ? this .getNextEra (this .era ) : nextEra ;
119124
120125 // set as fast as possible to make race conditions less likely
121126 this .contentChanged = false ;
@@ -268,6 +273,15 @@ public ASAPChunkStorage getChunkStorage() {
268273 return this .chunkStorage ;
269274 }
270275
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+
271285 ASAPChunkStorage getStorage () {
272286 return this .chunkStorage ;
273287 }
@@ -394,7 +408,7 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
394408 //>>>>>>>>>>>>>>>>>>>debug
395409
396410 // get received storage
397- ASAPStorage incomingStorage = this .getIncomingStorage (senderE2E , true );
411+ ASAPInternalStorage incomingStorage = ( ASAPInternalStorage ) this .getIncomingStorage (senderE2E , true );
398412 ASAPChunkStorage incomingChunkStorage = incomingStorage .getChunkStorage ();
399413 //ASAPChunkStorage incomingChunkStorage = this.getReceivedChunksStorage(senderE2E);
400414 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
436450 return ;
437451 }
438452
439- ASAPInternalChunk incomingChunk = incomingChunkStorage .getChunk (uri , eraSender );
453+ ASAPInternalChunk incomingChunk = incomingStorage .createNewChunk (uri , eraSender );
454+ //ASAPInternalChunk incomingChunk = incomingChunkStorage.getChunk(uri, eraSender);
440455
441456 if (localChunk != null ) {
442457 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
555570 Log .writeLog (this , this .toString (), b .toString ());
556571 //>>>>>>>>>>>>>>>>>>>debug
557572
558- Integer lastSeenEra = this .lastSeen .get (senderID );
573+ // init
574+ int workingEra = this .getOldestEra ();
559575
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 ;
563580 }
564581
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 );
567598
568599 if (workingEra == this .era ) {
569600 // nothing todo
@@ -591,9 +622,6 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
591622 /////////////////////////////////// asap routing
592623
593624 if (this .routingAllowed ()) {
594- Map <String , Integer > encounterMap = asapInterest .getEncounterMap ();
595- Log .writeLog (this , this .toString (), "routing allowed: encounterMap: " + encounterMap );
596-
597625 // iterate: what sender do we know in our side?
598626 for (CharSequence receivedFromID : this .getSender ()) {
599627 if (PeerIDHelper .sameID (encounteredPeer , receivedFromID )) {
0 commit comments