Skip to content

Commit a9c2748

Browse files
committed
introduced ASAPHop - makes SharkMessenger API easier to understand. Makes difference between E2E and Point2Point more obvious. At least I hope so.
1 parent cc0999b commit a9c2748

19 files changed

Lines changed: 129 additions & 85 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package net.sharksystem;
2+
3+
import net.sharksystem.asap.ASAPHop;
4+
import net.sharksystem.asap.EncounterConnectionType;
5+
6+
public class ASAPHopImpl implements ASAPHop {
7+
private final CharSequence sender;
8+
private final boolean verified;
9+
private final boolean encrypted;
10+
private final EncounterConnectionType connectionType;
11+
12+
public ASAPHopImpl(CharSequence sender, boolean verified, boolean encrypted, EncounterConnectionType connectionType) {
13+
this.sender = sender;
14+
this.verified = verified;
15+
this.encrypted = encrypted;
16+
this.connectionType = connectionType;
17+
}
18+
19+
@Override
20+
public CharSequence sender() {
21+
return this.sender;
22+
}
23+
24+
@Override
25+
public EncounterConnectionType getConnectionType() {
26+
return this.connectionType;
27+
}
28+
29+
@Override
30+
public boolean verified() {
31+
return this.verified;
32+
}
33+
34+
@Override
35+
public boolean encrypted() {
36+
return this.encrypted;
37+
}
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package net.sharksystem.asap;
2+
3+
/**
4+
* Describes the exchange if an ASAP message from one peer to the other
5+
*/
6+
public interface ASAPHop {
7+
/**
8+
* Sender is always a point-to-point sender. There is no get receiver method, though. Hops are kept in a chain.
9+
* Receiver of the last entry is local peer itself. For all hops in between: Sender of next hop is receiver of
10+
* the previous hop.
11+
* @return
12+
*/
13+
CharSequence sender();
14+
15+
/**
16+
* An ASAP message exchange is based on a point-to-point connection. There are different options: Ad-hoc networks,
17+
* Internet, onion networks etc. This method describes the connection type of this hop.
18+
* @return
19+
*/
20+
EncounterConnectionType getConnectionType();
21+
22+
/**
23+
* A sender could have signed the point-to-point message transfer. This message returns true if the receiver was
24+
* able to verify the signature. A false could be indicator for a forged identity or that the receiver has not got
25+
* sender's public key.
26+
* @return
27+
*/
28+
boolean verified();
29+
30+
/**
31+
* This point-to-point connection was encrypted.
32+
* @return
33+
*/
34+
boolean encrypted();
35+
36+
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package net.sharksystem.asap;
22

3-
import net.sharksystem.EncounterConnectionType;
4-
53
import java.io.IOException;
64

75
public interface ASAPMessageReceivedListener {
8-
void asapMessagesReceived(ASAPMessages messages,
9-
String senderE2E, // E2E part
10-
String senderPoint2Point, boolean verified, boolean encrypted, // Point2Point part
11-
EncounterConnectionType connectionType) throws IOException;
6+
void asapMessagesReceived(ASAPMessages messages, String senderE2E, // E2E part
7+
ASAPHop asapHop /* Point-to-point part */ ) throws IOException;
128
}

src/net/sharksystem/asap/ASAPPeerFS.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.sharksystem.asap;
22

3-
import net.sharksystem.EncounterConnectionType;
43
import net.sharksystem.asap.engine.*;
54
import net.sharksystem.asap.utils.Helper;
65
import net.sharksystem.utils.Log;
@@ -26,29 +25,25 @@ public void overwriteChuckReceivedListener(ASAPChunkReceivedListener listener) {
2625

2726
@Override
2827
public void chunkReceived(String format, String senderE2E, String uri, int era,
29-
String senderPoint2Point, boolean verified, boolean encrypted,
30-
EncounterConnectionType connectionType) throws IOException {
28+
ASAPHop asapHop) throws IOException {
3129

3230
StringBuilder sb = new StringBuilder();
3331
sb.append("\n++++++++++++++++++++++++++++++++++++++++++ chunkReceived +++++++++++++++++++++++++++++++++++++++++++\n");
34-
sb.append("E2E|P2P: " + senderE2E + " | " + senderPoint2Point + " | uri: " + uri + " | era: " + era + " | appFormat: " + format);
32+
sb.append("E2E|P2P: " + senderE2E + " | " + asapHop.sender() + " | uri: " + uri + " | era: " + era + " | appFormat: " + format);
3533
sb.append("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
3634
this.log(sb.toString());
3735

3836
if(this.chunkReceivedListener != null) {
3937
this.log("chunk received listener set - call this one");
40-
this.chunkReceivedListener.chunkReceived(format, senderE2E, uri, era, senderPoint2Point,
41-
verified, encrypted, connectionType);
38+
this.chunkReceivedListener.chunkReceived(format, senderE2E, uri, era, asapHop);
4239
} else {
4340
this.log("extract messages from chunk and notify listener");
4441
ASAPMessages receivedMessages =
4542
Helper.getMessagesByChunkReceivedInfos(format, senderE2E, uri, this.rootFolder, era);
4643

4744
this.asapMessageReceivedListenerManager.notifyReceived(
4845
format, receivedMessages, true,
49-
senderE2E,
50-
senderPoint2Point, verified, encrypted,
51-
connectionType);
46+
senderE2E, asapHop);
5247
}
5348
}
5449

src/net/sharksystem/EncounterConnectionType.java renamed to src/net/sharksystem/asap/EncounterConnectionType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.sharksystem;
1+
package net.sharksystem.asap;
22

33
public enum EncounterConnectionType {
44
UNKNOWN, AD_HOC_LAYER_2_NETWORK, ASAP_HUB, INTERNET, ONION_NETWORK

src/net/sharksystem/asap/apps/gossip/GossipUI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.sharksystem.asap.apps.gossip;
22

3-
import net.sharksystem.EncounterConnectionType;
3+
import net.sharksystem.asap.ASAPHop;
4+
import net.sharksystem.asap.EncounterConnectionType;
45
import net.sharksystem.asap.ASAPException;
56
import net.sharksystem.asap.ASAPMessages;
67
import net.sharksystem.asap.engine.*;
@@ -98,8 +99,7 @@ private void go() {
9899

99100
@Override
100101
public void chunkReceived(String format, String senderE2E, String uri, int era,
101-
String senderPoint2Point, boolean verified, boolean encrypted,
102-
EncounterConnectionType connectionType) throws IOException {
102+
ASAPHop asapHop) throws IOException {
103103

104104
ASAPMessages receivedMessages =
105105
Helper.getMessagesByChunkReceivedInfos(format, senderE2E, uri, this.rootFolderName, era);

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.sharksystem.asap.engine;
22

3-
import net.sharksystem.EncounterConnectionType;
3+
import net.sharksystem.asap.ASAPHop;
4+
import net.sharksystem.asap.EncounterConnectionType;
45

56
import java.io.IOException;
67

@@ -22,14 +23,10 @@ public interface ASAPChunkReceivedListener {
2223
* the channel.
2324
* @param uri message uri
2425
* @param era era of the original sender (the end-to-end sender). not
25-
* @param senderPoint2Point the sender on the other side of the channel.
26-
* @param verified true only if a) point-to-point connection was signed and b) signature could be verified
27-
* @param encrypted true if point-to-point connection was encrypted
28-
* @param connectionType describes the type of point-to-point connection (ad-hoc network, Internet, an
29-
* onion network, like TOR etc.)
30-
* @see EncounterConnectionType
26+
* @param asapHop describes the point-to-point message exchhange in more details
27+
* @see ASAPHop
28+
*
3129
*/
3230
void chunkReceived(String format, String senderE2E, String uri, int era, // E2E part
33-
String senderPoint2Point, boolean verified, boolean encrypted, // Point2Point part
34-
EncounterConnectionType connectionType) throws IOException;
31+
ASAPHop asapHop) throws IOException;
3532
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.sharksystem.asap.engine;
22

3-
import net.sharksystem.EncounterConnectionType;
3+
import net.sharksystem.ASAPHopImpl;
4+
import net.sharksystem.asap.EncounterConnectionType;
45
import net.sharksystem.asap.*;
56
import net.sharksystem.asap.ASAPChunkStorage;
67
import net.sharksystem.asap.ASAPMessages;
@@ -529,12 +530,14 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
529530
b.append(")");
530531
System.out.println(b.toString());
531532
//>>>>>>>>>>>>>>>>>>>debug
533+
532534
listener.chunkReceived(this.format,
533535
senderE2E, uri, eraSender,
534-
encounteredPeer,
535-
asapAssimilationPDU.verified(),
536-
asapAssimilationPDU.encrypted(),
537-
connectionType);
536+
new ASAPHopImpl(encounteredPeer,
537+
asapAssimilationPDU.verified(),
538+
asapAssimilationPDU.encrypted(),
539+
connectionType)
540+
);
538541
} else {
539542
//<<<<<<<<<<<<<<<<<<debug
540543
b = new StringBuilder();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.sharksystem.asap.engine;
22

3-
import net.sharksystem.EncounterConnectionType;
3+
import net.sharksystem.asap.EncounterConnectionType;
44
import net.sharksystem.asap.crypto.*;
55
import net.sharksystem.utils.Utils;
66
import net.sharksystem.asap.ASAP;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.sharksystem.asap.engine;
22

3-
import net.sharksystem.EncounterConnectionType;
3+
import net.sharksystem.asap.EncounterConnectionType;
44
import net.sharksystem.asap.ASAPException;
55
import net.sharksystem.asap.protocol.ASAP_1_0;
66
import net.sharksystem.asap.protocol.ASAP_AssimilationPDU_1_0;

0 commit comments

Comments
 (0)