Skip to content

Commit ed6131b

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

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import java.io.*;
1010
import java.util.*;
1111

12-
public class ASAPEncounterManagerImpl implements ASAPEncounterManager, ASAPConnectionListener {
12+
public class ASAPEncounterManagerImpl implements ASAPEncounterManager,
13+
EncounterManagerAdmin,
14+
ASAPConnectionListener {
1315
public static final long DEFAULT_WAIT_BEFORE_RECONNECT_TIME = 1000; // a second - debugging
1416
public static final long DEFAULT_WAIT_TO_AVOID_RACE_CONDITION = 500; // milliseconds - worked fine with BT.
1517

@@ -47,6 +49,7 @@ public ASAPEncounterManagerImpl(ASAPConnectionHandler asapConnectionHandler, lon
4749
this.asapConnectionHandler = asapConnectionHandler;
4850
this.randomValue = new Random(System.currentTimeMillis()).nextInt();
4951
this.waitBeforeReconnect = waitingPeriod;
52+
this.restoreDenyList();
5053
}
5154

5255
private boolean coolDownOver(CharSequence id, EncounterConnectionType connectionType) {
@@ -293,6 +296,54 @@ public synchronized void asapConnectionTerminated(Exception terminatingException
293296
}
294297
}
295298

299+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
300+
// EncounterManagerAdmin //
301+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
302+
303+
private Set<CharSequence> denyList;
304+
305+
//// housekeeping
306+
private void restoreDenyList() {
307+
// TODO
308+
this.denyList = new HashSet<>();
309+
Log.writeLog(this, "need to implement restoreDenyList");
310+
}
311+
312+
private void saveDenyList() {
313+
// TODO
314+
Log.writeLog(this, "need to implement saveDenyList");
315+
}
316+
317+
///// manage deny list
318+
@Override
319+
public void addToDenyList(CharSequence peerID) {
320+
this.denyList.add(peerID);
321+
this.saveDenyList();
322+
}
323+
324+
@Override
325+
public void removeFromDenyList(CharSequence peerID) {
326+
this.denyList.remove(peerID);
327+
this.saveDenyList();
328+
}
329+
330+
@Override
331+
public Set<CharSequence> getDenyList() {
332+
return this.denyList;
333+
}
334+
335+
@Override
336+
public Set<CharSequence> getConnectedPeerIDs() {
337+
return this.openStreamPairs.keySet();
338+
}
339+
@Override
340+
public void cancelConnection(CharSequence peerID) {
341+
StreamPair stream2Close = this.openStreamPairs.get(peerID);
342+
if(stream2Close != null) {
343+
stream2Close.close();
344+
}
345+
}
346+
296347
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
297348
// utils //
298349
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -301,5 +352,4 @@ public String toString() {
301352
return this.asapConnectionHandler.toString();
302353
}
303354

304-
305355
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.sharksystem.asap;
2+
3+
import java.util.Set;
4+
5+
/**
6+
* That's the admin interface of an encounter manager. It allows <b>deny list management</b>.
7+
* A deny list contains peerIDs. The encounter manager must not establish new connections to
8+
* those peers. There can be several reasons (security (peer is not considered trustworthy),
9+
* network topology (see considerations of a large scale ad-hoc network with limited
10+
* connections on each peer).
11+
*
12+
* Future enhancements:
13+
* <ul><li>define a point to point encryption policy.</li>
14+
* <li>define what connections types are acceptable (Internet, Hub, Ad-hoc, Onion)</li></ul>
15+
*/
16+
public interface EncounterManagerAdmin {
17+
/**
18+
* @return set of ID to which an open connection exists right now.
19+
*/
20+
public abstract Set<CharSequence> getConnectedPeerIDs();
21+
22+
/**
23+
* Add a peerID to what no connection should be established.
24+
* Note: Adding a peer to the deny list does not necessarily terminate an
25+
* existing connection to that peer.
26+
* @param peerID
27+
*/
28+
public abstract void addToDenyList(CharSequence peerID);
29+
30+
/**
31+
* Remove a peerID from deny list
32+
* @param peerID
33+
*/
34+
public abstract void removeFromDenyList(CharSequence peerID);
35+
36+
/**
37+
* Get PeerID set to which no connection should be established
38+
* @return
39+
*/
40+
public abstract Set<CharSequence> getDenyList();
41+
42+
/**
43+
* Cancel a connection to a peer. This method call does not change the deny list.
44+
* @param peerID
45+
*/
46+
public abstract void cancelConnection(CharSequence peerID);
47+
48+
}

0 commit comments

Comments
 (0)