use max backoff time if no relay games

This commit is contained in:
Eric House 2016-11-11 06:31:54 -08:00
parent edcafe1c45
commit f394bcef64
2 changed files with 45 additions and 13 deletions

View file

@ -414,6 +414,34 @@ public class DBUtils {
return result;
}
public static int countOpenGamesUsingRelay( Context context )
{
int result = 0;
String[] columns = { DBHelper.CONTYPE };
String selection = String.format( "%s = 0", DBHelper.GAME_OVER );
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
selection, null, null, null, null );
int indx = cursor.getColumnIndex( DBHelper.CONTYPE );
while ( cursor.moveToNext() ) {
CommsConnTypeSet typs = new CommsConnTypeSet( cursor.getInt(indx) );
if ( typs.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
++result;
}
}
cursor.close();
db.close();
}
// DbgUtils.logd( DBUtils.class, "countOpenGamesUsingRelay() => %d", result );
return result;
}
public static class SentInvitesInfo {
public long m_rowid;
private ArrayList<InviteMeans> m_means;

View file

@ -1392,22 +1392,26 @@ public class RelayService extends XWService
private int figureBackoffSeconds() {
// DbgUtils.printStack();
long diff;
synchronized ( RelayService.class ) {
long now = Utils.getCurSeconds();
if ( s_curNextTimer <= now ) {
if ( 0 == s_curBackoff ) {
s_curBackoff = 15;
int result = 60 * 60; // default if no games
if ( 0 < DBUtils.countOpenGamesUsingRelay( this ) ) {
long diff;
synchronized ( RelayService.class ) {
long now = Utils.getCurSeconds();
if ( s_curNextTimer <= now ) {
if ( 0 == s_curBackoff ) {
s_curBackoff = 15;
}
s_curBackoff = Math.min( 2 * s_curBackoff, result );
s_curNextTimer += s_curBackoff;
}
s_curBackoff = Math.min( 2 * s_curBackoff, 60*60 );
s_curNextTimer += s_curBackoff;
}
diff = s_curNextTimer - now;
diff = s_curNextTimer - now;
}
Assert.assertTrue( diff < Integer.MAX_VALUE );
DbgUtils.logd( getClass(), "figureBackoffSeconds() => %d", diff );
result = (int)diff;
}
Assert.assertTrue( diff < Integer.MAX_VALUE );
DbgUtils.logd( getClass(), "figureBackoffSeconds() => %d", diff );
return (int)diff;
return result;
}
private class PacketHeader {