@@ -37,8 +37,8 @@ public void setSecurityAdministrator(DefaultSecurityAdministrator securityAdmini
3737
3838 protected String owner = ANONYMOUS_OWNER ;
3939
40- protected int era = 0 ;
41- protected int oldestEra = 0 ;
40+ protected int era = ASAP . INITIAL_ERA ;
41+ protected int oldestEra = ASAP . INITIAL_ERA ;
4242 protected HashMap <String , Integer > lastSeen = new HashMap <>();
4343 protected ASAPMemento memento = null ;
4444 public long lastMementoWritten ;
@@ -403,135 +403,138 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
403403 b .append ("handle assimilate pdu received from " );
404404 b .append (senderE2E );
405405 b .append (" | era: " );
406- b .append (eraSender );
406+ if (eraSender == ASAP .TRANSIENT_ERA ) b .append ("transient" );
407+ else b .append (eraSender );
407408 Log .writeLog (this , this .toString (), b .toString ());
408409 //>>>>>>>>>>>>>>>>>>>debug
409410
410411 // get received storage
411412 ASAPInternalStorage incomingStorage = (ASAPInternalStorage ) this .getIncomingStorage (senderE2E , true );
412413 ASAPChunkStorage incomingChunkStorage = incomingStorage .getChunkStorage ();
413- //ASAPChunkStorage incomingChunkStorage = this.getReceivedChunksStorage(senderE2E);
414414 Log .writeLog (this , this .toString (), "got incoming chunk storage for senderE2E: " + senderE2E );
415415
416416 boolean changed = false ;
417417 boolean allowedAssimilation = true ;
418418
419- try {
420- // read URI
421- String uri = asapAssimilationPDU . getChannelUri ( );
419+ // add entry to hop list
420+ List < ASAPHop > asapHopList = asapAssimilationPDU . getASAPHopList ();
421+ Log . writeLog ( this , this . toString (), "got hop list: " + asapHopList );
422422
423- // get local target for data to come
424- ASAPInternalChunk localChunk = null ;
423+ // add this new hop
424+ ASAPHop lastHop = new ASAPHopImpl (encounteredPeer , asapAssimilationPDU .verified (),
425+ asapAssimilationPDU .encrypted (), connectionType );
425426
426- if (!incomingChunkStorage .existsChunk (uri , eraSender )) {
427- // is there a local chunk - to clone recipients from?
428- if (this .channelExists (uri )) {
429- localChunk = this .getStorage ().getChunk (uri , this .getEra ());
430- } else {
431- Log .writeLog (this , this .toString (), "asked to set up new channel: (uri/senderE2E): "
432- + uri + " | " + senderE2E );
433- // this channel is new to local peer - am I allowed to create it?
434- if (!this .securityAdministrator .allowedToCreateChannel (asapAssimilationPDU )) {
435- Log .writeLog (this , this .toString (),
436- ".. not allowed .. TODO not yet implemented .. always set up" );
427+ asapHopList .add (lastHop );
428+
429+ // get URI
430+ String uri = asapAssimilationPDU .getChannelUri ();
431+
432+ if (eraSender != ASAP .TRANSIENT_ERA ) {
433+ try {
434+ // get local target for data to come
435+ ASAPInternalChunk localChunk = null ;
437436
438- allowedAssimilation = false ; // TODO
437+ if (!incomingChunkStorage .existsChunk (uri , eraSender )) {
438+ // is there a local chunk - to clone recipients from?
439+ if (this .channelExists (uri )) {
440+ localChunk = this .getStorage ().getChunk (uri , this .getEra ());
439441 } else {
440- Log .writeLog (this , this .toString (), "allowed. Set it up." );
441- this .createChannel (uri );
442+ Log .writeLog (this , this .toString (), "asked to set up new channel: (uri/senderE2E): "
443+ + uri + " | " + senderE2E );
444+ // this channel is new to local peer - am I allowed to create it?
445+ if (!this .securityAdministrator .allowedToCreateChannel (asapAssimilationPDU )) {
446+ Log .writeLog (this , this .toString (),
447+ ".. not allowed .. TODO not yet implemented .. always set up" );
448+
449+ allowedAssimilation = false ; // TODO
450+ } else {
451+ Log .writeLog (this , this .toString (), "allowed. Set it up." );
452+ this .createChannel (uri );
453+ }
442454 }
443- }
444- } else {
445- Log .writeLog (this , this .toString (), "received chunk that already exists - did nothing: "
446- + senderE2E + " | " + eraSender + " | " + uri );
455+ } else {
456+ Log .writeLog (this , this .toString (), "received chunk that already exists - did nothing: "
457+ + senderE2E + " | " + eraSender + " | " + uri );
447458
448- // read assimilation message payload to oblivion!
449- asapAssimilationPDU .takeDataFromStream ();
450- return ;
451- }
459+ // read assimilation message payload to oblivion!
460+ asapAssimilationPDU .takeDataFromStream ();
461+ return ;
462+ }
452463
453- ASAPInternalChunk incomingChunk = incomingStorage .createNewChunk (uri , eraSender );
454- //ASAPInternalChunk incomingChunk = incomingChunkStorage.getChunk(uri, eraSender);
464+ ASAPInternalChunk incomingChunk = incomingStorage .createNewChunk (uri , eraSender );
465+ //ASAPInternalChunk incomingChunk = incomingChunkStorage.getChunk(uri, eraSender);
455466
456- if (localChunk != null ) {
457- Log .writeLog (this , this .toString (), "copy local meta data into newly created incoming chunk" );
458- incomingChunk .copyMetaData (this .getChannel (uri ));
459- }
467+ if (localChunk != null ) {
468+ Log .writeLog (this , this .toString (), "copy local meta data into newly created incoming chunk" );
469+ incomingChunk .copyMetaData (this .getChannel (uri ));
470+ }
460471
461- List <Integer > messageOffsets = asapAssimilationPDU .getMessageOffsets ();
472+ List <Integer > messageOffsets = asapAssimilationPDU .getMessageOffsets ();
473+
474+ // iterate messages and stream into chunk
475+ InputStream protocolInputStream = asapAssimilationPDU .getInputStream ();
476+ long offset = 0 ;
477+ for (long nextOffset : messageOffsets ) {
478+ //<<<<<<<<<<<<<<<<<<debug
479+ b = new StringBuilder ();
480+ b .append ("going to read message: [" );
481+ b .append (offset );
482+ b .append (", " );
483+ b .append (nextOffset );
484+ b .append (")" );
485+ Log .writeLog (this , this .toString (), b .toString ());
486+ //>>>>>>>>>>>>>>>>>>>debug
487+ incomingChunk .addMessage (protocolInputStream , nextOffset - offset );
488+ //if(!changed) { changed = true; this.contentChanged();}
489+ offset = nextOffset ;
490+ }
462491
463- // iterate messages and stream into chunk
464- InputStream protocolInputStream = asapAssimilationPDU .getInputStream ();
465- long offset = 0 ;
466- for (long nextOffset : messageOffsets ) {
492+ // last round
467493 //<<<<<<<<<<<<<<<<<<debug
468494 b = new StringBuilder ();
469- b .append ("going to read message: [ " );
495+ b .append ("going to read last message: from offset " );
470496 b .append (offset );
471- b .append (", " );
472- b .append (nextOffset );
473- b .append (")" );
497+ b .append (" to end of file - total length: " );
498+ b .append (asapAssimilationPDU .getLength ());
474499 Log .writeLog (this , this .toString (), b .toString ());
475500 //>>>>>>>>>>>>>>>>>>>debug
476- incomingChunk .addMessage (protocolInputStream , nextOffset - offset );
477- //if(!changed) { changed = true; this.contentChanged();}
478- offset = nextOffset ;
501+
502+ incomingChunk .addMessage (protocolInputStream , asapAssimilationPDU .getLength () - offset );
503+
504+ // add hop list to newly create chunk
505+ incomingChunk .setASAPHopList (asapHopList );
506+ } catch (IOException | ASAPException e ) {
507+ Log .writeLogErr (this , this .toString (),
508+ "exception (give up, keep streams untouched): " + e .getLocalizedMessage ());
509+ throw e ;
479510 }
511+ }
512+
513+ /////// notify listeners - if any
480514
481- // last round
515+ // read all messages
516+ if (listener != null ) {
482517 //<<<<<<<<<<<<<<<<<<debug
483518 b = new StringBuilder ();
484- b .append ("going to read last message: from offset " );
485- b .append (offset );
486- b .append (" to end of file - total length: " );
487- b .append (asapAssimilationPDU .getLength ());
519+ b .append ("call " );
520+ b .append (listener .getClass ().getSimpleName ());
521+ b .append (".chunkReceived(senderE2E: " );
522+ b .append (senderE2E );
523+ b .append (", uri: " );
524+ b .append (uri );
525+ b .append (", eraSender: " );
526+ if (eraSender != ASAP .TRANSIENT_ERA ) b .append (eraSender );
527+ else b .append ("transient" );
528+ b .append (")" );
488529 Log .writeLog (this , this .toString (), b .toString ());
489530 //>>>>>>>>>>>>>>>>>>>debug
490531
491- incomingChunk .addMessage (protocolInputStream , asapAssimilationPDU .getLength () - offset );
492- // receiving has no effect on era.
493- //if(!changed) { changed = true; this.contentChanged();}
494-
495- // add hop list.
496- List <ASAPHop > asapHopList = asapAssimilationPDU .getASAPHopList ();
497- Log .writeLog (this , this .toString (), "got hop list: " + asapHopList );
498-
499- // add this new hop
500- ASAPHop lastHop = new ASAPHopImpl (encounteredPeer , asapAssimilationPDU .verified (),
501- asapAssimilationPDU .encrypted (), connectionType );
502-
503- asapHopList .add (lastHop );
504-
505- incomingChunk .setASAPHopList (asapHopList );
506-
507- // read all messages
508- if (listener != null ) {
509- //<<<<<<<<<<<<<<<<<<debug
510- b = new StringBuilder ();
511- b .append ("call " );
512- b .append (listener .getClass ().getSimpleName ());
513- b .append (".chunkReceived(senderE2E: " );
514- b .append (senderE2E );
515- b .append (", uri: " );
516- b .append (uri );
517- b .append (", eraSender: " );
518- b .append (eraSender );
519- b .append (")" );
520- Log .writeLog (this , this .toString (), b .toString ());
521- //>>>>>>>>>>>>>>>>>>>debug
522-
523- listener .chunkReceived (this .format ,
524- senderE2E , uri , eraSender ,
525- asapHopList
526- );
527- } else {
528- Log .writeLog (this , this .toString (), "no chunk received listener found" );
529- }
530- }
531- catch (IOException | ASAPException e ) {
532- Log .writeLogErr (this , this .toString (),
533- "exception (give up, keep streams untouched): " + e .getLocalizedMessage ());
534- throw e ;
532+ listener .chunkReceived (this .format ,
533+ senderE2E , uri , eraSender ,
534+ asapHopList
535+ );
536+ } else {
537+ Log .writeLog (this , this .toString (), "no chunk received listener found" );
535538 }
536539 }
537540
0 commit comments