1313import java .io .*;
1414import java .util .*;
1515
16- public class ASAPEncounterManagerImpl implements ASAPEncounterManager , ASAPEncounterManagerAdmin ,
17- ASAPConnectionListener {
16+ public class ASAPEncounterManagerImpl implements
17+ ASAPEncounterManager , ASAPEncounterManagerAdmin , ASAPConnectionListener {
1818 public static final long DEFAULT_WAIT_BEFORE_RECONNECT_TIME = 60000 ; // 60 seconds == 1 minute
1919 public static final long DEFAULT_WAIT_TO_AVOID_RACE_CONDITION = 500 ; // milliseconds - worked fine with BT.
2020 public static final String DATASTORAGE_FILE_EXTENSION = "em" ;
@@ -221,9 +221,6 @@ private void handleEncounter(StreamPair streamPair, ASAPEncounterConnectionType
221221 this .openStreamPairs .put (connectionID , streamPair );
222222 Log .writeLog (this , this .toString (), "remember encounter: " + streamPair .getEndpointID ());
223223 this .encounterDate .put (streamPair .getEndpointID (), new Date ());
224-
225- Log .writeLog (this , this .toString (), "going to launch a new asap connection" );
226-
227224 try {
228225 Log .writeLog (this , this .toString (), "call asap peer to handle connection" );
229226 ASAPConnection asapConnection =
@@ -232,6 +229,8 @@ private void handleEncounter(StreamPair streamPair, ASAPEncounterConnectionType
232229
233230 asapConnection .addASAPConnectionListener (this );
234231
232+ Log .writeLog (this , this .toString (),
233+ "asap peers is handling session: " + asapConnection .toString ());
235234 this .openASAPConnections .put (asapConnection , connectionID );
236235
237236 } catch (IOException | ASAPException e ) {
@@ -315,7 +314,7 @@ private boolean solveRaceCondition(StreamPair streamPair, boolean connectionInit
315314 @ Override
316315 public synchronized void asapConnectionStarted (String remotePeerName , ASAPConnection connection ) {
317316 CharSequence peerID = connection .getEncounteredPeer ();
318- Log .writeLog (this , this .toString (), "new ASAP session started with peerID " + peerID );
317+ Log .writeLog (this , this .toString (), "new ASAP session: " + connection );
319318
320319 CharSequence streamPairID = this .openASAPConnections .get (connection );
321320 if (PeerIDHelper .sameID (streamPairID , peerID )) {
@@ -336,6 +335,7 @@ public synchronized void asapConnectionStarted(String remotePeerName, ASAPConnec
336335
337336 @ Override
338337 public synchronized void asapConnectionTerminated (Exception terminatingException , ASAPConnection connection ) {
338+ Log .writeLog (this , this .toString (), "terminated: " + connection );
339339 CharSequence peerID = connection .getEncounteredPeer ();
340340
341341 CharSequence peerIDOrAddress = this .openASAPConnections .get (connection );
@@ -434,6 +434,17 @@ public Set<CharSequence> getDenyList() {
434434 public Set <CharSequence > getConnectedPeerIDs () {
435435 return this .openStreamPairs .keySet ();
436436 }
437+
438+ public ASAPEncounterConnectionType getConnectionType (CharSequence peerID ) throws ASAPException {
439+ for (ASAPConnection connection : this .openASAPConnections .keySet ()) {
440+ if (PeerIDHelper .sameID (connection .getEncounteredPeer (), peerID )) {
441+ // found our connection
442+ return connection .getASAPEncounterConnectionType ();
443+ }
444+ }
445+ throw new ASAPException ("there is no connection to peer " + peerID );
446+ }
447+
437448 @ Override
438449 public void cancelConnection (CharSequence peerID ) {
439450 StreamPair stream2Close = this .openStreamPairs .get (peerID );
0 commit comments