Skip to content

Commit 975f9a6

Browse files
committed
routing works. Era change stable.
1 parent c02d26c commit 975f9a6

7 files changed

Lines changed: 34 additions & 13 deletions

File tree

src/net/sharksystem/asap/ASAPPeerFS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public void chunkReceived(String format, String senderE2E, String uri, int era,
3030
EncounterConnectionType connectionType) throws IOException {
3131

3232
StringBuilder sb = new StringBuilder();
33-
sb.append("\n++++++++++++++++++++++++++++++++++++++++++ chunkReceived ++++++++++++++++++++++++++++++++++++++++\n");
34-
sb.append("E2E|P2P: " + senderE2E + " | " + senderPoint2Point + " | uri: " + uri + " | era: " + era + " | appFormat: " + format + " | ");
35-
sb.append("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
33+
sb.append("\n++++++++++++++++++++++++++++++++++++++++++ chunkReceived +++++++++++++++++++++++++++++++++++++++++++\n");
34+
sb.append("E2E|P2P: " + senderE2E + " | " + senderPoint2Point + " | uri: " + uri + " | era: " + era + " | appFormat: " + format);
35+
sb.append("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
3636
this.log(sb.toString());
3737

3838
if(this.chunkReceivedListener != null) {

src/net/sharksystem/asap/engine/ASAPEngine.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,18 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
402402

403403
// debug break
404404
//Log.writeLog(this, "!!!!!!!!!!!!!!!!!!!!!!!! ASSIMILATE PDU senderE2E: " + senderE2E);
405+
/*
405406
if(PeerIDHelper.sameID(senderE2E, "Alice_42")) {
406407
int i = 42;
407408
}
409+
*/
410+
411+
if(PeerIDHelper.sameID(senderE2E, this.owner)) {
412+
Log.writeLogErr(this, "I was offered messages from myself ("
413+
+ this.owner + ") by " + encounteredPeer + " - refused: ");
414+
asapAssimilationPDU.takeDataFromStream();
415+
return;
416+
}
408417

409418
//<<<<<<<<<<<<<<<<<<debug
410419
StringBuilder b = new StringBuilder();
@@ -559,7 +568,8 @@ private boolean hasSufficientCrypto(ASAP_PDU_1_0 pdu) {
559568
return proceed;
560569
}
561570

562-
public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 protocol, OutputStream os)
571+
public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 protocol,
572+
String encounteredPeer, OutputStream os, EncounterConnectionType connectionType)
563573
throws ASAPException, IOException {
564574

565575
// before we start - lets crypto: TODO can be removed - do it on communication not engine level
@@ -583,9 +593,11 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
583593
/* We have got an interest from another peer.
584594
First: Let's find what chunks from our peer are be be sent to get in sync. */
585595
Map<String, Integer> encounterMap = null;
586-
Integer lastSeenEra = null;
596+
// Integer lastSeenEra = null;
597+
Integer lastSeenEra = this.lastSeen.get(senderID);
587598

588599
// has it even provided an encounter list?
600+
/* Cannot do this - sent era is their era not ours.
589601
if(asapInterest.encounterList()) {
590602
encounterMap = asapInterest.getEncounterMap();
591603
lastSeenEra = encounterMap.get(this.getOwner());
@@ -598,6 +610,7 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
598610
// no entry in encounter list - local history?
599611
lastSeenEra = this.lastSeen.get(senderID);
600612
}
613+
*/
601614

602615
if(lastSeenEra == null) {
603616
// still nothing
@@ -654,6 +667,10 @@ public void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 prot
654667
// iterate: what sender do we know in our side?
655668
for(CharSequence receivedFromID : this.getSender()) {
656669
Log.writeLog(this, "we have messages from " + receivedFromID);
670+
if(PeerIDHelper.sameID(encounteredPeer, receivedFromID)) {
671+
// do not send messages back
672+
continue;
673+
}
657674
try {
658675
ASAPStorage receivedMessagesStorage = this.getExistingIncomingStorage(receivedFromID);
659676

src/net/sharksystem/asap/engine/ASAPProtocolEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* @author thsc
1515
*/
1616
public interface ASAPProtocolEngine {
17-
void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 protocol, OutputStream os)
17+
void handleASAPInterest(ASAP_Interest_PDU_1_0 asapInterest, ASAP_1_0 protocol,
18+
String encounteredPeer, OutputStream os, EncounterConnectionType connectionType)
1819
throws ASAPException, IOException;
1920

2021
void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, ASAP_1_0 protocolModem,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,11 @@ public void run() {
387387
// TODO add encrypt / sign as parameter..
388388
case ASAP_1_0.INTEREST_CMD:
389389
Log.writeLog(this, getLogStart() + "ASAPPDUExecutor call handleASAPInterest");
390-
engineSetting.engine.handleASAPInterest((ASAP_Interest_PDU_1_0) asapPDU, protocol, os);
390+
engineSetting.engine.handleASAPInterest(
391+
(ASAP_Interest_PDU_1_0) asapPDU, this.protocol,
392+
this.encounteredPeer,
393+
this.os,
394+
this.connectionType);
391395
break;
392396
case ASAP_1_0.ASSIMILATE_CMD:
393397
Log.writeLog(this, getLogStart() + "ASAPPDUExecutor call handleASAPAssimilate");

test/net/sharksystem/TodoTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
@RunWith(Suite.class)
1515
@Suite.SuiteClasses({
16-
Point2PointTests.class,
17-
MultihopTests.class
16+
Point2PointTests.class
1817
})
1918
public class TodoTests {
2019
}

test/net/sharksystem/V1TestSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
@Suite.SuiteClasses({
1515
SerializationTests.class,
1616
BasisMethodsTests.class,
17-
//Point2PointTests.class,
1817
UsageExamples.class,
1918
CreateNewChannelFromOutsideTest.class,
2019
PDUTests.class,
@@ -23,6 +22,7 @@
2322
LongerMessages.class,
2423
CryptoUsage.class,
2524
HelperTester.class,
25+
MultihopTests.class,
2626
SharkComponentTests.class
2727
})
2828
public class V1TestSuite {

test/net/sharksystem/asap/engine/MultihopTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class MultihopTests {
2424
* @throws ASAPException
2525
* @throws InterruptedException
2626
*/
27-
@Test
27+
//@Test // keep it as an example of batch processor based test case
2828
public void twoHops() throws IOException, ASAPException, InterruptedException {
2929
CmdLineUI ui = new CmdLineUI(System.out);
3030

@@ -141,7 +141,7 @@ public void connectionWithNoDataExchange() throws IOException, ASAPException, In
141141
ui.doKill("all");
142142
}
143143

144-
@Test
144+
// @Test
145145
public void closedChannelTest() throws IOException, ASAPException, InterruptedException {
146146
CmdLineUI ui = new CmdLineUI(System.out);
147147
ui.doResetASAPStorages();
@@ -411,7 +411,7 @@ public void asapRoutingIsFiniteAndCheckEra() throws IOException, ASAPException,
411411
// reset counter on clara side
412412
claraListener.numberOfMessages = 0;
413413
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
414-
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>> Alice meets Clara <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
414+
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> Alice meets Clara again <<<<<<<<<<<<<<<<<<<<<<<<<<<<");
415415
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
416416
alicePeer.startEncounter(TestHelper.getPortNumber(), claraPeer);
417417
// give your app a moment to process

0 commit comments

Comments
 (0)