@@ -557,39 +557,13 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
557557 Log .writeLog (this , this .toString (), b .toString ());
558558 //>>>>>>>>>>>>>>>>>>>debug
559559
560- /* We have got an interest from another peer.
561- First: Let's find what chunks from our peer are be be sent to get in sync. */
562- Map <String , Integer > encounterMap = null ;
563- // Integer lastSeenEra = null;
564560 Integer lastSeenEra = this .lastSeen .get (senderID );
565561
566- // has it even provided an encounter list?
567- /* Cannot do this - sent era is their era not ours.
568- if(asapInterest.encounterList()) {
569- encounterMap = asapInterest.getEncounterMap();
570- lastSeenEra = encounterMap.get(this.getOwner());
571- }
572-
573- if(lastSeenEra != null) {
574- // remember this fact - will be overwritten later - but maybe when connection goes down before..
575- this.lastSeen.put(asapInterest.getSender(), lastSeenEra);
576- } else {
577- // no entry in encounter list - local history?
578- lastSeenEra = this.lastSeen.get(senderID);
579- }
580- */
581-
582562 if (lastSeenEra == null ) {
583563 // still nothing
584564 lastSeenEra = this .getOldestEra ();
585565 }
586566
587- /*
588- if(PeerIDHelper.sameID(encounteredPeer, "Clara_44")) {
589- int i = 42; // debug break;
590- }
591- */
592-
593567 int workingEra = lastSeenEra ;
594568 Log .writeLog (this , this .toString (), "last_seen: " + workingEra + " | era: " + this .era );
595569
@@ -616,33 +590,52 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
616590 Log .writeLog (this , this .toString (), "ended iterating local chunks" );
617591 }
618592
593+ /////////////////////////////////// asap routing
594+
619595 if (this .routingAllowed ()) {
596+ Map <String , Integer > encounterMap = asapInterest .getEncounterMap ();
597+ Log .writeLog (this , this .toString (), "routing allowed: encounterMap: " + encounterMap );
598+
620599 // iterate: what sender do we know in our side?
621600 for (CharSequence receivedFromID : this .getSender ()) {
622601 if (PeerIDHelper .sameID (encounteredPeer , receivedFromID )) {
623602 // do not send messages back
624603 continue ;
625604 }
626605 Log .writeLog (this , this .toString (), "going to route messages from " + receivedFromID );
627- Log .writeLog (this , this .toString (), "received encounter map: " + encounterMap );
628606 try {
629607 ASAPStorage receivedMessagesStorage = this .getExistingIncomingStorage (receivedFromID );
608+ int eraLastToSend = receivedMessagesStorage .getEra ();
609+ int eraFirstToSend = receivedMessagesStorage .getOldestEra ();
630610
631- int routeSinceEra = ASAP .INITIAL_ERA ;
632- // maybe we can do better and there is an entry in encounter map
611+ // got encounter information from other peer?
633612 if (encounterMap != null ) {
634- Integer lastMetEra = encounterMap .get (receivedFromID );
635- if (lastMetEra != null ) {
636- routeSinceEra = lastMetEra ;
637- Log .writeLog (this , this .toString (), "found sender received encounter map" );
613+ Integer eraLastMet = encounterMap .get (receivedFromID );
614+ if (eraLastMet != null ) {
615+ Log .writeLog (this , this .toString (),
616+ "found sender received encounter map; last encounter: " + eraLastMet );
617+ /*
618+ Peer told us last encounter era - from senders perspective of course.
619+ There are several options, sketch:
620+
621+ <------ our storage ------->
622+ ............ [eraFirst] +++++++++++++++ [eraLast] .........
623+ (a) (b) (c) (d)
624+ a) We send everything we have
625+ b) We send from b+1 until eraLast
626+ c) + d) We are in sync or behind - nothing to do
627+ */
628+
629+ // we would start with the next era
630+ int eraAfterLastMet = ASAP .nextEra (eraLastMet );
631+
632+ if (ASAP .isEraInRange (eraAfterLastMet , eraFirstToSend , eraLastToSend )) { // case b)
633+ eraFirstToSend = eraAfterLastMet ;
634+ }
638635 }
639636 }
640-
641- this .sendChunks (receivedFromID , senderID ,
642- receivedMessagesStorage .getChunkStorage (),
643- protocol , routeSinceEra ,
644- receivedMessagesStorage .getEra (), os ,
645- false );
637+ this .sendChunks (receivedFromID , senderID , receivedMessagesStorage .getChunkStorage (), protocol ,
638+ eraFirstToSend , eraLastToSend , os ,false );
646639 }
647640 catch (ASAPException e ) {
648641 Log .writeLogErr (this , this .toString (),
@@ -681,10 +674,13 @@ void sendInterest(CharSequence ownerID, ASAP_1_0 protocol, OutputStream os)
681674 /*
682675 There is no storage for encountered peer. Can happen - met but has not got anything from it.
683676 So, take era from last seen...
684- */
677+
678+ I can't follow, sorry 2021, Dec, 10th (thsc42)
685679 encounterMap.put(peerID, this.lastSeen.get(peerID));
680+ */
686681 }
687682 }
683+ Log .writeLog (this , this .toString (), "send encounterMap with interest: " + encounterMap );
688684
689685 protocol .interest (ownerID , null ,
690686 format , null , ASAP_1_0 .ERA_NOT_DEFINED , ASAP_1_0 .ERA_NOT_DEFINED ,
0 commit comments