Skip to content

Commit 6260638

Browse files
committed
multihop with closed channels works with one hop now.
1 parent 99ae321 commit 6260638

File tree

4 files changed

+43
-54
lines changed

4 files changed

+43
-54
lines changed

src/net/sharksystem/asap/MultiASAPEngineFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* That interface hides those different engines.
2121
*/
22-
public interface MultiASAPEngineFS extends ASAPManagementProtocolEngine {
22+
public interface MultiASAPEngineFS {
2323
public static final long DEFAULT_MAX_PROCESSING_TIME = Long.MAX_VALUE;
2424

2525
public ASAPEngine getEngineByFormat(CharSequence format) throws ASAPException, IOException;

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.*;
1111

1212
public class MultiASAPEngineFS_Impl implements
13-
MultiASAPEngineFS, ASAPManagementProtocolEngine, ASAPConnectionListener, ThreadFinishedListener {
13+
MultiASAPEngineFS, ASAPConnectionListener, ThreadFinishedListener, ASAPChunkReceivedListener {
1414
private final CharSequence rootFolderName;
1515
private final ASAPChunkReceivedListener listener;
1616
private CharSequence owner;
@@ -74,6 +74,12 @@ private void setupFolderMap() throws IOException, ASAPException {
7474
this.folderMap.put(engine.format, setting);
7575
}
7676
}
77+
78+
// set yourself as listener to asap management app
79+
EngineSetting folderAndListener = folderMap.get(ASAP_1_0.ASAP_MANAGEMENT_FORMAT);
80+
if(folderAndListener != null) {
81+
folderAndListener.listener = this;
82+
}
7783
}
7884

7985
/**
@@ -360,30 +366,40 @@ public void pushInterests(OutputStream os) throws IOException, ASAPException {
360366
}
361367
}
362368

363-
public boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
364-
InputStream is) throws ASAPException, IOException {
369+
private String getLogStart() {
370+
return this.getClass().getSimpleName() + "(" + this.getOwner() + "): ";
371+
}
372+
373+
///////////////////////////////////////////////////////////////////////////////////////////////////////
374+
// chunk received listener for asap management engine //
375+
///////////////////////////////////////////////////////////////////////////////////////////////////////
376+
377+
@Override
378+
public void chunkReceived(String sender, String uri, int era) {
379+
System.out.println(this.getLogStart()
380+
+ "handle received chunk (sender/uri/era)" + sender + "/" + uri + "/" + era);
381+
try {
382+
ASAPEngine asapManagementEngine = this.getEngineByFormat(ASAP_1_0.ASAP_MANAGEMENT_FORMAT);
383+
ASAPChunkStorage incomingChunkStorage = asapManagementEngine.getIncomingChunkStorage(sender);
384+
ASAPChunk chunk = incomingChunkStorage.getChunk(uri, era);
385+
Iterator<byte[]> messageIter = chunk.getMessagesAsBytes();
386+
System.out.println(this.getLogStart() + "iterate management messages");
387+
while(messageIter.hasNext()) {
388+
byte[] message = messageIter.next();
389+
this.handleASAPManagementMessage(sender, message);
390+
}
391+
System.out.println(this.getLogStart() + "done iterating management messages");
392+
} catch (ASAPException | IOException e) {
393+
System.out.println("could get asap management engine but received chunk - looks like a bug");
394+
}
395+
}
365396

397+
private void handleASAPManagementMessage(CharSequence owner, byte[] message) throws ASAPException, IOException {
366398
StringBuilder b = new StringBuilder();
367399
b.append(this.getLogStart());
368400
b.append("start processing asap management pdu");
369401
System.out.println(b.toString());
370402

371-
System.out.println(this.getLogStart() + asapPDU);
372-
373-
ASAP_AssimilationPDU_1_0 asap_assimilationPDU_1_0 = null;
374-
if(asapPDU instanceof ASAP_AssimilationPDU_1_0) {
375-
asap_assimilationPDU_1_0 = (ASAP_AssimilationPDU_1_0) asapPDU;
376-
} else {
377-
b = new StringBuilder();
378-
b.append(this.getLogStart());
379-
b.append("asap management pdu not an assimilate message - let ordinary engine to the job");
380-
System.out.println(b.toString());
381-
return false;
382-
}
383-
384-
CharSequence owner = asapPDU.getPeer();
385-
byte[] message = asap_assimilationPDU_1_0.getData();
386-
387403
ASAPManagementCreateASAPStorageMessage asapManagementCreateASAPStorageMessage =
388404
ASAPManagementMessage.parseASAPManagementMessage(owner, message);
389405

@@ -395,7 +411,7 @@ public boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
395411
List<CharSequence> recipients = new ArrayList<>();
396412

397413
// add owner
398-
recipients.add(asapPDU.getPeer());
414+
recipients.add(owner);
399415

400416
// add rest
401417
for(CharSequence r : receivedRecipients) {
@@ -412,7 +428,6 @@ public boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
412428
b.append(channelUri);
413429
b.append(" | #recipients: ");
414430
b.append(recipients.size());
415-
System.out.println(b.toString());
416431

417432
// find storage / app - can throw an exception - that's ok
418433
ASAPStorage asapStorage = this.getEngineByFormat(format);
@@ -433,25 +448,18 @@ public boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
433448
}
434449
}
435450
if(!found) {
436-
throw new ASAPException("channel already exists but with different recipients");
451+
throw new ASAPException("channel already exists but with different recipients: " + b.toString());
437452
}
438453
}
439454
// ok it the same
440-
return false;
455+
return;
441456
} else {
442-
throw new ASAPException("channel already exists but with different settings");
457+
throw new ASAPException("channel already exists but with different settings: " + b.toString());
443458
}
444459
}
445460

446461
// else - channel does not exist - create by setting recipients
447-
System.out.println(this.getLogStart() + "create channel");
462+
System.out.println(this.getLogStart() + "create channel: " + b.toString());
448463
asapStorage.createChannel(channelUri, recipients);
449-
System.err.println(this.getLogStart() + ".handleASAPManagementPDU(): TODO: return true - works / false not - but must be false...");
450-
// return true;
451-
return false;
452-
}
453-
454-
private String getLogStart() {
455-
return this.getClass().getSimpleName() + "(" + this.getOwner() + "): ";
456464
}
457465
}

src/net/sharksystem/asap/protocol/ASAPManagementProtocolEngine.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/net/sharksystem/asap/protocol/ASAPPersistentConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public void run() {
213213

214214
// process received pdu
215215
boolean pduExecuted = false;
216+
/*
216217
if(asappdu.getFormat().equalsIgnoreCase(ASAP_1_0.ASAP_MANAGEMENT_FORMAT)) {
217218
System.out.println(this.getLogStart()
218219
+ "got asap management message - let multi-engine handle this one");
@@ -229,7 +230,7 @@ public void run() {
229230
break;
230231
}
231232
}
232-
233+
*/
233234
if(!pduExecuted) { // not (completely executed by multi engine
234235
try {
235236
this.executor = new ASAPPDUExecutor(asappdu,

0 commit comments

Comments
 (0)