Skip to content

Commit f2e1271

Browse files
committed
introduce EncounterManagerAdmin... a step to implement that large scale ad-hoc network.
1 parent ed6131b commit f2e1271

20 files changed

+73
-73
lines changed

src/main/java/net/sharksystem/asap/ASAPConnectionHandler.java

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

3-
import net.sharksystem.asap.ASAPException;
4-
import net.sharksystem.asap.crypto.ASAPPoint2PointCryptoSettings;
53
import net.sharksystem.asap.protocol.ASAPConnection;
64

75
import java.io.IOException;
@@ -30,7 +28,7 @@ ASAPConnection handleConnection(
3028
) throws IOException, ASAPException;
3129

3230
ASAPConnection handleConnection(
33-
InputStream is, OutputStream os, boolean encrypt, boolean sign,EncounterConnectionType connectionType,
31+
InputStream is, OutputStream os, boolean encrypt, boolean sign, ASAPEncounterConnectionType connectionType,
3432
Set<CharSequence> appsWhiteList, Set<CharSequence> appsBlackList
3533
) throws IOException, ASAPException;
3634

@@ -47,5 +45,5 @@ ASAPConnection handleConnection(
4745
ASAPConnection handleConnection(InputStream is, OutputStream os) throws IOException, ASAPException;
4846

4947
ASAPConnection handleConnection(InputStream inputStream, OutputStream outputStream,
50-
EncounterConnectionType connectionType) throws IOException, ASAPException;
48+
ASAPEncounterConnectionType connectionType) throws IOException, ASAPException;
5149
}

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

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

3-
public enum EncounterConnectionType {
3+
public enum ASAPEncounterConnectionType {
44
UNKNOWN, AD_HOC_LAYER_2_NETWORK, ASAP_HUB, INTERNET, ONION_NETWORK
55
}

src/main/java/net/sharksystem/asap/ASAPEncounterManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public interface ASAPEncounterManager {
4848
* There will be no attempts to establish a connection.
4949
* @param connectionType Describes the connection that is planned to be established.
5050
* @return true: a connection should be established or not.
51-
* @see EncounterConnectionType
51+
* @see ASAPEncounterConnectionType
5252
*/
53-
boolean shouldCreateConnectionToPeer(CharSequence addressOrPeerID, EncounterConnectionType connectionType);
53+
boolean shouldCreateConnectionToPeer(CharSequence addressOrPeerID, ASAPEncounterConnectionType connectionType);
5454

5555
/**
5656
* A connection to another device was established. This method can be called to handle this new connection.
@@ -62,7 +62,7 @@ public interface ASAPEncounterManager {
6262
* @param streamPair most likely a socket that is can be used for an ASAP session.
6363
* @throws IOException something can go wrong when sending data. This object has no obligation to deal with this.
6464
*/
65-
void handleEncounter(StreamPair streamPair, EncounterConnectionType connectionType) throws IOException;
65+
void handleEncounter(StreamPair streamPair, ASAPEncounterConnectionType connectionType) throws IOException;
6666

6767
/**
6868
* This method is a variant of the one with less parameters.
@@ -115,7 +115,7 @@ public interface ASAPEncounterManager {
115115
* @param streamPair
116116
* @param initiator
117117
* @throws IOException
118-
* @see ASAPEncounterManager#handleEncounter(StreamPair, EncounterConnectionType)
118+
* @see ASAPEncounterManager#handleEncounter(StreamPair, ASAPEncounterConnectionType)
119119
*/
120-
void handleEncounter(StreamPair streamPair, EncounterConnectionType connectionType, boolean initiator) throws IOException;
120+
void handleEncounter(StreamPair streamPair, ASAPEncounterConnectionType connectionType, boolean initiator) throws IOException;
121121
}

src/main/java/net/sharksystem/asap/EncounterManagerAdmin.java renamed to src/main/java/net/sharksystem/asap/ASAPEncounterManagerAdmin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* <ul><li>define a point to point encryption policy.</li>
1414
* <li>define what connections types are acceptable (Internet, Hub, Ad-hoc, Onion)</li></ul>
1515
*/
16-
public interface EncounterManagerAdmin {
16+
public interface ASAPEncounterManagerAdmin {
1717
/**
1818
* @return set of ID to which an open connection exists right now.
1919
*/

src/main/java/net/sharksystem/asap/ASAPEncounterManagerImpl.java

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

1212
public class ASAPEncounterManagerImpl implements ASAPEncounterManager,
13-
EncounterManagerAdmin,
13+
ASAPEncounterManagerAdmin,
1414
ASAPConnectionListener {
1515
public static final long DEFAULT_WAIT_BEFORE_RECONNECT_TIME = 1000; // a second - debugging
1616
public static final long DEFAULT_WAIT_TO_AVOID_RACE_CONDITION = 500; // milliseconds - worked fine with BT.
1717

18-
private final int randomValue;
19-
private final long waitBeforeReconnect;
18+
private int randomValue;
19+
private long waitBeforeReconnect;
2020
private ASAPConnectionHandler asapConnectionHandler; // object that will eventually run the ASAP session
2121

2222
/*
@@ -52,7 +52,7 @@ public ASAPEncounterManagerImpl(ASAPConnectionHandler asapConnectionHandler, lon
5252
this.restoreDenyList();
5353
}
5454

55-
private boolean coolDownOver(CharSequence id, EncounterConnectionType connectionType) {
55+
private boolean coolDownOver(CharSequence id, ASAPEncounterConnectionType connectionType) {
5656
Date now = new Date();
5757
Date lastEncounter = this.encounterDate.get(id);
5858

@@ -87,7 +87,7 @@ private boolean coolDownOver(CharSequence id, EncounterConnectionType connection
8787
}
8888

8989
@Override
90-
public boolean shouldCreateConnectionToPeer(CharSequence remoteAdressOrPeerID, EncounterConnectionType connectionType) {
90+
public boolean shouldCreateConnectionToPeer(CharSequence remoteAdressOrPeerID, ASAPEncounterConnectionType connectionType) {
9191
// do we have a connection under a peerID?
9292
StreamPair streamPair = this.openStreamPairs.get(remoteAdressOrPeerID);
9393
if(streamPair != null) {
@@ -118,19 +118,19 @@ public boolean shouldCreateConnectionToPeer(CharSequence remoteAdressOrPeerID, E
118118
}
119119

120120
@Override
121-
public void handleEncounter(StreamPair streamPair, EncounterConnectionType connectionType) throws IOException {
121+
public void handleEncounter(StreamPair streamPair, ASAPEncounterConnectionType connectionType) throws IOException {
122122
this.handleEncounter(streamPair, connectionType, false, false);
123123
}
124124

125125
@Override
126-
public void handleEncounter(StreamPair streamPair, EncounterConnectionType connectionType, boolean initiator)
126+
public void handleEncounter(StreamPair streamPair, ASAPEncounterConnectionType connectionType, boolean initiator)
127127
throws IOException {
128128

129129
this.handleEncounter(streamPair, connectionType, initiator, true);
130130
}
131131

132-
private void handleEncounter(StreamPair streamPair, EncounterConnectionType connectionType, boolean initiator,
133-
boolean raceCondition) throws IOException {
132+
private void handleEncounter(StreamPair streamPair, ASAPEncounterConnectionType connectionType, boolean initiator,
133+
boolean raceCondition) throws IOException {
134134

135135
CharSequence streamPairID = streamPair.getSessionID();
136136

@@ -300,12 +300,12 @@ public synchronized void asapConnectionTerminated(Exception terminatingException
300300
// EncounterManagerAdmin //
301301
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
302302

303-
private Set<CharSequence> denyList;
303+
private Set<CharSequence> denyList = new HashSet<>();
304304

305305
//// housekeeping
306306
private void restoreDenyList() {
307307
// TODO
308-
this.denyList = new HashSet<>();
308+
//this.denyList = new HashSet<>();
309309
Log.writeLog(this, "need to implement restoreDenyList");
310310
}
311311

src/main/java/net/sharksystem/asap/ASAPHop.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface ASAPHop {
1717
* Internet, onion networks etc. This method describes the connection type of this hop.
1818
* @return
1919
*/
20-
EncounterConnectionType getConnectionType();
20+
ASAPEncounterConnectionType getConnectionType();
2121

2222
/**
2323
* A sender could have signed the point-to-point message transfer. This message returns true if the receiver was

src/main/java/net/sharksystem/asap/ASAPHopImpl.java

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

3-
import net.sharksystem.asap.ASAPHop;
4-
import net.sharksystem.asap.EncounterConnectionType;
5-
63
public class ASAPHopImpl implements ASAPHop {
74
private final CharSequence sender;
85
private final boolean verified;
96
private final boolean encrypted;
10-
private final EncounterConnectionType connectionType;
7+
private final ASAPEncounterConnectionType connectionType;
118

12-
public ASAPHopImpl(CharSequence sender, boolean verified, boolean encrypted, EncounterConnectionType connectionType) {
9+
public ASAPHopImpl(CharSequence sender, boolean verified, boolean encrypted, ASAPEncounterConnectionType connectionType) {
1310
this.sender = sender;
1411
this.verified = verified;
1512
this.encrypted = encrypted;
@@ -22,7 +19,7 @@ public CharSequence sender() {
2219
}
2320

2421
@Override
25-
public EncounterConnectionType getConnectionType() {
22+
public ASAPEncounterConnectionType getConnectionType() {
2623
return this.connectionType;
2724
}
2825

src/main/java/net/sharksystem/asap/ASAPInternalPeerWrapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public ASAPConnection handleConnection(InputStream is, OutputStream os) throws I
6464
}
6565

6666
public ASAPConnection handleConnection(InputStream is, OutputStream os,
67-
EncounterConnectionType connectionType) throws IOException, ASAPException {
67+
ASAPEncounterConnectionType connectionType) throws IOException, ASAPException {
6868

6969
return this.peer.handleConnection(is, os, connectionType);
7070
}
7171

7272
public ASAPConnection handleConnection(InputStream is, OutputStream os, boolean encrypt, boolean sign,
73-
EncounterConnectionType connectionType) throws IOException, ASAPException {
73+
ASAPEncounterConnectionType connectionType) throws IOException, ASAPException {
7474

7575
return this.peer.handleConnection(is, os, encrypt, sign, connectionType,
7676
(Set<CharSequence>)null, (Set<CharSequence>)null);
@@ -86,7 +86,7 @@ public ASAPConnection handleConnection(
8686

8787

8888
public ASAPConnection handleConnection(InputStream is, OutputStream os, boolean encrypt, boolean sign,
89-
EncounterConnectionType connectionType,
89+
ASAPEncounterConnectionType connectionType,
9090
Set<CharSequence> appsWhiteList, Set<CharSequence> appsBlackList) throws IOException, ASAPException {
9191
return this.peer.handleConnection(is, os, encrypt, sign, connectionType, appsWhiteList, appsBlackList);
9292
}

src/main/java/net/sharksystem/asap/ASAPPeerFS.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public ASAPPeerFS(CharSequence owner, CharSequence rootFolder,
2121
this.rootFolder = rootFolder.toString();
2222
}
2323

24+
public ASAPPeerFS(CharSequence owner, CharSequence rootFolder) throws IOException, ASAPException {
25+
super.setInternalPeer(ASAPInternalPeerFS.createASAPPeer(owner, rootFolder, null, this));
26+
this.rootFolder = rootFolder.toString();
27+
}
28+
2429
public void overwriteChuckReceivedListener(ASAPChunkAssimilatedListener listener) {
2530
Log.writeLogErr(this, this.getPeerID(), "do not use chunk received listener - message received listener is better");
2631
this.chunkReceivedListener = listener;

src/main/java/net/sharksystem/asap/apps/TCPServerSocketAcceptor.java

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

33
import net.sharksystem.asap.ASAPEncounterManager;
4-
import net.sharksystem.asap.EncounterConnectionType;
4+
import net.sharksystem.asap.ASAPEncounterConnectionType;
55
import net.sharksystem.utils.Log;
66
import net.sharksystem.utils.streams.StreamPair;
77
import net.sharksystem.utils.tcp.SocketFactory;
@@ -24,7 +24,7 @@ public TCPServerSocketAcceptor(int portNumber, ASAPEncounterManager encounterMan
2424
public void streamPairCreated(StreamPair streamPair) {
2525
Log.writeLog(this, "new stream pair created");
2626
try {
27-
this.encounterManager.handleEncounter(streamPair, EncounterConnectionType.INTERNET);
27+
this.encounterManager.handleEncounter(streamPair, ASAPEncounterConnectionType.INTERNET);
2828
} catch (IOException e) {
2929
Log.writeLogErr(this, "exception when asking for new connection handling: "
3030
+ e.getLocalizedMessage());

0 commit comments

Comments
 (0)