Skip to content

Commit 3ee4621

Browse files
committed
closed channel is created but message exchange still fails.
1 parent 6d435df commit 3ee4621

File tree

4 files changed

+54
-44
lines changed

4 files changed

+54
-44
lines changed

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
403403
b.append(recipients.size());
404404
System.out.println(b.toString());
405405

406-
// find storage
406+
// find storage / app - can throw an exception - that's ok
407407
ASAPStorage asapStorage = this.getEngineByFormat(format);
408408

409409
if(asapStorage.channelExists(channelUri)) {
@@ -433,8 +433,9 @@ public boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
433433
}
434434

435435
// else - channel does not exist - create by setting recipients
436+
System.out.println(this.getLogStart() + "create channel");
436437
asapStorage.createChannel(channelUri, recipients);
437-
return false;
438+
return true;
438439
}
439440

440441
private String getLogStart() {

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,23 +174,7 @@ private synchronized void checkRunningOnlineMessageSender() {
174174

175175
public void run() {
176176
ASAP_1_0 protocol = new ASAP_Modem_Impl();
177-
/*
178-
// introduce yourself
179-
CharSequence owner = this.multiASAPEngineFS.getOwner();
180-
if(owner != null && owner.length() > 0) {
181-
try {
182-
System.out.println(this.getLogStart() + "send introduction ASAP Offer; owner: " + owner);
183-
this.sendIntroductionOffer(owner, false);
184-
} catch (IOException e) {
185-
this.terminate("io error when sending introduction offering: ", e);
186-
return;
187-
} catch (ASAPException e) {
188-
System.out.println(this.getLogStart()
189-
+ "could not send introduction offer: " + e.getLocalizedMessage());
190-
// go ahead - no io problem
191-
}
192-
}
193-
*/
177+
194178
try {
195179
// let engine write their interest - at least management interest is sent which als introduces
196180
// this peer to the other one
@@ -237,7 +221,7 @@ public void run() {
237221
// if return true - message was handled. No further actions required
238222
pduExecuted = this.multiASAPEngineFS.handleASAPManagementPDU(asappdu, protocol, is);
239223
} catch (ASAPException e) {
240-
System.err.println("asap management pdu processing failed - go ahead in read/process loop"
224+
System.err.println("asap management pdu processing failed - go ahead in read/process loop: "
241225
+ e.getLocalizedMessage());
242226
pduExecuted = false; // failed to execute - forget and go ahead
243227
} catch (IOException e) {

src/net/sharksystem/cmdline/CmdLineUI.java

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CmdLineUI {
1818
public static final String KILL = "kill";
1919
public static final String SETWAITING = "setwaiting";
2020
public static final String CREATE_ASAP_ENGINE = "newengine";
21-
public static final String CREATE_ASAP_STORAGE = "newstorage";
21+
public static final String CREATE_ASAP_APP = "newapp";
2222
public static final String CREATE_ASAP_CHANNEL = "newchannel";
2323
public static final String CREATE_ASAP_MESSAGE = "newmessage";
2424
public static final String RESET_ASAP_STORAGES = "resetstorage";
@@ -80,8 +80,8 @@ public void printUsage() {
8080
b.append(CREATE_ASAP_ENGINE);
8181
b.append(".. create new asap engine");
8282
b.append("\n");
83-
b.append(CREATE_ASAP_STORAGE);
84-
b.append(".. create new asap storage");
83+
b.append(CREATE_ASAP_APP);
84+
b.append(".. create new asap app (==storage)");
8585
b.append("\n");
8686
b.append(CREATE_ASAP_CHANNEL);
8787
b.append(".. create new closed asap channel");
@@ -143,9 +143,9 @@ public void printUsage(String cmdString, String comment) {
143143
out.println("example: " + CREATE_ASAP_ENGINE + " Alice");
144144
out.println("create engine called Alice - data kept under a folder called tests/Alice");
145145
break;
146-
case CREATE_ASAP_STORAGE:
147-
out.println(CREATE_ASAP_STORAGE + " owner appName");
148-
out.println("example: " + CREATE_ASAP_STORAGE + " Alice chat");
146+
case CREATE_ASAP_APP:
147+
out.println(CREATE_ASAP_APP + " owner appName");
148+
out.println("example: " + CREATE_ASAP_APP + " Alice chat");
149149
break;
150150
case CREATE_ASAP_CHANNEL:
151151
out.println(CREATE_ASAP_CHANNEL + " owner appName uri (recipient)+");
@@ -216,7 +216,8 @@ public void runCommandLoop() {
216216
this.doSetWaiting(parameterString); break;
217217
case CREATE_ASAP_ENGINE:
218218
this.doCreateASAPMultiEngine(parameterString); break;
219-
case CREATE_ASAP_STORAGE: // same
219+
case CREATE_ASAP_APP: // same
220+
this.doCreateASAPApp(parameterString); break;
220221
case CREATE_ASAP_CHANNEL:
221222
this.doCreateASAPChannel(parameterString); break;
222223
case CREATE_ASAP_MESSAGE:
@@ -396,39 +397,57 @@ public void doCreateASAPMultiEngine(String parameterString) {
396397
}
397398
}
398399

399-
public void doCreateASAPChannel(String parameterString) {
400+
public void doCreateASAPApp(String parameterString) {
400401
StringTokenizer st = new StringTokenizer(parameterString);
401402

402403
try {
403404
String owner = st.nextToken();
404405
String appName = st.nextToken();
405-
String uri = st.nextToken();
406406

407407
String appFolderName = TESTS_ROOT_FOLDER + "/" + owner + "/" + appName;
408-
String format = "sn2://" + appName;
409-
410-
List<CharSequence> recipients = new ArrayList<>();
411-
while(st.hasMoreTokens()) {
412-
recipients.add(st.nextToken());
413-
}
414408

415-
ASAPStorage storage = ASAPEngineFS.getASAPStorage(owner, appFolderName, format);
409+
ASAPStorage storage = ASAPEngineFS.getASAPStorage(owner, appFolderName, appName);
416410
if(!storage.isASAPManagementStorageSet()) {
417411
storage.setASAPManagementStorage(ASAPEngineFS.getASAPStorage(owner,
418412
TESTS_ROOT_FOLDER + "/" + owner + "/ASAPManagement",
419413
ASAP_1_0.ASAP_MANAGEMENT_FORMAT));
420414
}
421415

422-
if(recipients.size() > 0) {
423-
storage.createChannel(uri, recipients);
416+
this.storages.put(this.getStorageKey(owner, appName), storage);
417+
}
418+
catch(RuntimeException e) {
419+
this.printUsage(CREATE_ASAP_APP, e.getLocalizedMessage());
420+
} catch (IOException | ASAPException e) {
421+
this.printUsage(CREATE_ASAP_APP, e.getLocalizedMessage());
422+
}
423+
}
424+
425+
public void doCreateASAPChannel(String parameterString) {
426+
StringTokenizer st = new StringTokenizer(parameterString);
427+
428+
try {
429+
String owner = st.nextToken();
430+
String appName = st.nextToken();
431+
String uri = st.nextToken();
432+
433+
ASAPStorage storage = this.storages.get(this.getStorageKey(owner, appName));
434+
435+
List<CharSequence> recipients = new ArrayList<>();
436+
437+
// one recipient is mandatory - provoke an exception otherwise
438+
recipients.add(st.nextToken());
439+
440+
// optional recipients
441+
while(st.hasMoreTokens()) {
442+
recipients.add(st.nextToken());
424443
}
425444

426-
this.storages.put(this.getStorageKey(owner, appName), storage);
445+
storage.createChannel(uri, recipients);
427446
}
428447
catch(RuntimeException e) {
429-
this.printUsage(CREATE_ASAP_STORAGE, e.getLocalizedMessage());
448+
this.printUsage(CREATE_ASAP_APP, e.getLocalizedMessage());
430449
} catch (IOException | ASAPException e) {
431-
this.printUsage(CREATE_ASAP_STORAGE, e.getLocalizedMessage());
450+
this.printUsage(CREATE_ASAP_APP, e.getLocalizedMessage());
432451
}
433452
}
434453

test/net/sharksystem/asap/MultihopTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public void twoHops() throws IOException, ASAPException, InterruptedException {
2121
ui.doResetASAPStorages();
2222

2323
// create storages
24-
ui.doCreateASAPChannel("Alice twoHops sn2://abc");
25-
ui.doCreateASAPChannel("Bob twoHops sn2://abc");
26-
ui.doCreateASAPChannel("Clara twoHops sn2://abc");
24+
ui.doCreateASAPApp("Alice twoHops");
25+
ui.doCreateASAPApp("Bob twoHops");
26+
ui.doCreateASAPApp("Clara twoHops");
2727

2828
ui.doSetSendReceivedMessage("Alice:twoHops on");
2929
ui.doSetSendReceivedMessage("Bob:twoHops on");
@@ -98,6 +98,12 @@ public void createNonOpenStorage() throws IOException, ASAPException, Interrupte
9898
CmdLineUI ui = new CmdLineUI(System.out);
9999
ui.doResetASAPStorages();
100100

101+
// create app on each peer
102+
ui.doCreateASAPApp("Alice chat");
103+
ui.doCreateASAPApp("Bob chat");
104+
ui.doCreateASAPApp("Clara chat");
105+
106+
// create closed channel with Alice
101107
ui.doCreateASAPChannel(" Alice chat sn2://closedChannel Bob Clara");
102108
ui.doPrintChannelInformation("Alice chat sn2://closedChannel");
103109

0 commit comments

Comments
 (0)