@@ -580,6 +580,8 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
580580
581581 this .sendChunks (sender , peer , incomingChunkStorage , protocol , workingEra , lastEra , os );
582582 }
583+ } else {
584+ System .out .println (this .getLogStart () + "engine does not send received chunks" );
583585 }
584586 }
585587
@@ -608,6 +610,7 @@ private void sendChunks(CharSequence sender, String recipient, ASAPChunkStorage
608610
609611 boolean lastRound = false ; // assume more than one round
610612 do {
613+ boolean goAhead = true ; // to avoid deep if-if-if-if structures
611614 lastRound = workingEra == lastEra ;
612615
613616 List <ASAPChunk > chunks = chunkStorage .getChunks (workingEra );
@@ -625,68 +628,69 @@ private void sendChunks(CharSequence sender, String recipient, ASAPChunkStorage
625628 b .append (this .getLogStart ());
626629 b .append ("chunkUrl: " );
627630 b .append (chunk .getUri ());
628- b .append (" / isPublic: " );
631+ b .append (" | isPublic: " );
629632 b .append (this .isPublic (chunk ));
633+ b .append (" | len: " );
634+ b .append (chunk .getLength ());
630635 System .out .println (b .toString ());
631636 //>>>>>>>>>>>>>>>>>>>debug
632637
638+ if (chunk .getLength () < 1 ) {
639+ goAhead = false ;
640+ }
641+
633642 // is not a public chunk
634- if (!this .isPublic (chunk )) {
643+ if (goAhead && !this .isPublic (chunk )) {
635644 Set <CharSequence > recipients = chunk .getRecipients ();
636-
637- if (!recipients .contains (recipient )) {
638- continue ;
645+ if (recipients == null || !recipients .contains (recipient )) {
646+ goAhead = false ;
639647 }
640648 }
641649
642- //<<<<<<<<<<<<<<<<<<debug
643- b = new StringBuilder ();
644- b .append (this .getLogStart ());
645- b .append ("send chunk" );
646- System .out .println (b .toString ());
647- //>>>>>>>>>>>>>>>>>>>debug
648-
649- /*
650- void assimilate(CharSequence recipient, CharSequence recipientPeer, CharSequence format, CharSequence channel, int era,
651- int length, List<Integer> offsets, InputStream dataIS, OutputStream os, boolean signed)
652- throws IOException, ASAPException;
653- */
654-
655- protocol .assimilate (sender , // recipient
656- recipient , // recipient
657- this .format ,
658- chunk .getUri (), // channel ok
659- workingEra , // era ok
660- chunk .getLength (), // data length
661- chunk .getOffsetList (),
662- chunk .getMessageInputStream (),
663- os ,
664- false );
665-
666- // remember sent
667- chunk .deliveredTo (recipient );
668- //<<<<<<<<<<<<<<<<<<debug
669- b = new StringBuilder ();
670- b .append (this .getLogStart ());
671- b .append ("remembered delivered to " );
672- b .append (recipient );
673- System .out .println (b .toString ());
674- //>>>>>>>>>>>>>>>>>>>debug
675- // sent to all recipients
676- if (chunk .getRecipients ().size () == chunk .getDeliveredTo ().size ()) {
677- b = Log .startLog (this );
678- b .append ("#recipients == #deliveredTo chunk delivered to any potential recipient - could drop it" );
650+ if (goAhead ) {
651+ //<<<<<<<<<<<<<<<<<<debug
652+ b = new StringBuilder ();
653+ b .append (this .getLogStart ());
654+ b .append ("send chunk" );
679655 System .out .println (b .toString ());
680- if (this .isDropDeliveredChunks ()) {
681- chunk .drop ();
682- //<<<<<<<<<<<<<<<<<<debug
683- b = Log .startLog (this );
684- b .append ("chunk dropped" );
685- System .out .println (b .toString ());
686- } else {
656+ //>>>>>>>>>>>>>>>>>>>debug
657+
658+ protocol .assimilate (sender , // recipient
659+ recipient , // recipient
660+ this .format ,
661+ chunk .getUri (), // channel ok
662+ workingEra , // era ok
663+ chunk .getLength (), // data length
664+ chunk .getOffsetList (),
665+ chunk .getMessageInputStream (),
666+ os ,
667+ false );
668+
669+ // remember sent
670+ chunk .deliveredTo (recipient );
671+ //<<<<<<<<<<<<<<<<<<debug
672+ b = new StringBuilder ();
673+ b .append (this .getLogStart ());
674+ b .append ("remembered delivered to " );
675+ b .append (recipient );
676+ System .out .println (b .toString ());
677+ //>>>>>>>>>>>>>>>>>>>debug
678+ // sent to all recipients
679+ if (chunk .getRecipients ().size () == chunk .getDeliveredTo ().size ()) {
687680 b = Log .startLog (this );
688- b .append ("drop flag set false - engine does not remove delivered chunks " );
681+ b .append ("#recipients == #deliveredTo chunk delivered to any potential recipient - could drop it " );
689682 System .out .println (b .toString ());
683+ if (this .isDropDeliveredChunks ()) {
684+ chunk .drop ();
685+ //<<<<<<<<<<<<<<<<<<debug
686+ b = Log .startLog (this );
687+ b .append ("chunk dropped" );
688+ System .out .println (b .toString ());
689+ } else {
690+ b = Log .startLog (this );
691+ b .append ("drop flag set false - engine does not remove delivered chunks" );
692+ System .out .println (b .toString ());
693+ }
690694 }
691695 }
692696 }
0 commit comments