diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index 561539881..3fed33c81 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -100,7 +100,6 @@ public class BoardDelegate extends DelegateBase private GamePtr m_jniGamePtr; private CurGameInfo m_gi; private GameSummary m_summary; - private boolean m_relayMissing; private Handler m_handler = null; private TimerRunnable[] m_timers; private Runnable m_screenTimer; @@ -1305,9 +1304,6 @@ public class BoardDelegate extends DelegateBase NetLaunchInfo nli = new NetLaunchInfo( m_activity, m_summary, m_gi, 1, // nPlayers 1 + m_mySIS.nGuestDevs ); // fc - if ( m_relayMissing ) { - nli.removeAddress( CommsConnType.COMMS_CONN_RELAY ); - } switch ( means ) { case EMAIL: GameUtils.launchEmailInviteActivity( m_activity, nli ); @@ -2693,10 +2689,6 @@ public class BoardDelegate extends DelegateBase nPlayers, forceChannel ) .setRemotesAreRobots( m_remotesAreRobots ); - if ( m_relayMissing ) { - nli.removeAddress( CommsConnType.COMMS_CONN_RELAY ); - } - switch ( m_missingMeans ) { case BLUETOOTH: if ( ! m_progressShown ) { @@ -2994,15 +2986,11 @@ public class BoardDelegate extends DelegateBase } if ( doIt ) { - CommsConnTypeSet connTypes = summary.conTypes; - if ( BuildConfig.NO_NEW_RELAY ) { - connTypes.remove(CommsConnType.COMMS_CONN_RELAY); - relayID = null; - } String newName = summary.getRematchName( activity ); Intent intent = GamesListDelegate - .makeRematchIntent( activity, rowid, groupID, gi, connTypes, - btAddr, phone, relayID, p2pMacAddress, + .makeRematchIntent( activity, rowid, groupID, gi, + summary.conTypes, btAddr, phone, + relayID, p2pMacAddress, mqttDevID, newName ); if ( null != intent ) { activity.startActivity( intent ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java index 537298497..c793fb131 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java @@ -373,10 +373,6 @@ public class DBUtils { public static void addRematchInfo( Context context, long rowid, CommsAddrRec addr ) { - if ( BuildConfig.NO_NEW_RELAY ) { - addr.remove(CommsConnType.COMMS_CONN_RELAY); - } - try ( GameLock lock = GameLock.tryLock(rowid) ) { if ( null != lock ) { String as64 = Utils.serializableToString64( addr ); @@ -478,8 +474,10 @@ public class DBUtils { cursor.close(); } - Log.d( TAG, "countOpenGamesUsing(with: %s, without: %s) => %d", - connTypWith, connTypWithout, result ); + if ( 0 < result ) { + Log.d( TAG, "countOpenGamesUsing(with: %s, without: %s) => %d", + connTypWith, connTypWithout, result ); + } return result; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java index a127b7774..135a0e1fc 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java @@ -626,9 +626,6 @@ public class GameUtils { String[] dictArray = {dict}; if ( null == addrSet ) { addrSet = XWPrefs.getAddrTypes( context ); - if ( BuildConfig.NO_NEW_RELAY ) { - addrSet.remove( CommsConnType.COMMS_CONN_RELAY ); - } } // Silently add this to any networked game if our device supports diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index bd2b690ab..2f9a8455c 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -2914,21 +2914,13 @@ public class GamesListDelegate extends ListDelegateBase private void doOpenGame( Object[] params ) { final long rowid = (Long)params[0]; - GameSummary summary = (GameSummary)params[1]; - - if ( null != summary - && summary.conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) - && summary.roomName.length() == 0 ) { - Assert.failDbg(); - } else { - try { - if ( checkWarnNoDict( rowid ) ) { - launchGame( rowid ); - } - } catch ( GameLock.GameLockedException gle ) { - Log.ex( TAG, gle ); - finish(); + try { + if ( checkWarnNoDict( rowid ) ) { + launchGame( rowid ); } + } catch ( GameLock.GameLockedException gle ) { + Log.ex( TAG, gle ); + finish(); } } @@ -3152,9 +3144,6 @@ public class GamesListDelegate extends ListDelegateBase .putExtra( REMATCH_NEWNAME_EXTRA, newName ); if ( null != addrTypes ) { - if ( BuildConfig.NO_NEW_RELAY ) { - Assert.assertTrueNR( !addrTypes.contains(CommsConnType.COMMS_CONN_RELAY) ); - } intent.putExtra( REMATCH_ADDRS_EXTRA, addrTypes.toInt() ); if ( null != btAddr ) { Assert.assertTrue( addrTypes.contains( CommsConnType.COMMS_CONN_BT ) ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java index f4f717b94..7440a5d81 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java @@ -43,6 +43,7 @@ import java.util.Set; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.ExpandImageButton.ExpandChangeListener; +import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.XwJNI; @@ -220,22 +221,19 @@ public class KnownPlayersDelegate extends DelegateBase { addListing( list, R.string.knowns_ts_fmt, str ); } - if ( conTypes.contains( CommsAddrRec.CommsConnType.COMMS_CONN_BT ) ) { + if ( conTypes.contains( CommsConnType.COMMS_CONN_BT ) ) { addListing( list, R.string.knowns_bt_fmt, addr.bt_hostName ); if ( BuildConfig.NON_RELEASE ) { addListing( list, R.string.knowns_bta_fmt, addr.bt_btAddr ); } } - if ( conTypes.contains( CommsAddrRec.CommsConnType.COMMS_CONN_SMS ) ) { + if ( conTypes.contains( CommsConnType.COMMS_CONN_SMS ) ) { addListing( list, R.string.knowns_smsphone_fmt, addr.sms_phone ); } if ( BuildConfig.NON_RELEASE ) { - if ( conTypes.contains( CommsAddrRec.CommsConnType.COMMS_CONN_MQTT ) ) { + if ( conTypes.contains( CommsConnType.COMMS_CONN_MQTT ) ) { addListing( list, R.string.knowns_mqtt_fmt, addr.mqtt_devID ); } - // if ( conTypes.contains( CommsAddrRec.CommsConnType.COMMS_CONN_RELAY ) ) { - // addListing( item, R.string.knowns_relay_fmt, addr.relay_devID ); - // } } item.findViewById( R.id.player_edit_name ) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java index 4a47a3963..503bb9ef6 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayService.java @@ -72,7 +72,7 @@ public class RelayService extends XWJIService private static final int INITIAL_BACKOFF = 5; private static final int UDP_FAIL_LIMIT = 5; - private static final long MIN_BACKOFF = 1000 * 60 * 2; // 2 minutes + private static final long MIN_BACKOFF = 1000 * 15; // 15 seconds private static final long MAX_BACKOFF = 1000 * 60 * 60 * 23; // 23 hours // Must use the same jobID for all work enqueued for the same class. I @@ -165,7 +165,7 @@ public class RelayService extends XWJIService if ( backoff < MIN_BACKOFF ) { backoff = MIN_BACKOFF; } else { - backoff *= 2; + backoff = backoff * 12 / 10; } if ( MAX_BACKOFF <= backoff ) { backoff = MAX_BACKOFF; @@ -278,6 +278,10 @@ public class RelayService extends XWJIService { Intent intent = getIntentTo( context, MsgCmds.TIMER_FIRED ); enqueueWork( context, intent ); + + // Kinda a hail Mary, but a no-op unless there are RELAY games + GameUtils.resendAllIf( context, CommsConnType.COMMS_CONN_RELAY, + true, false ); } public static int sendPacket( Context context, long rowid, byte[] msg, @@ -390,8 +394,6 @@ public class RelayService extends XWJIService NetStateCache.unregister( RelayService.this, RelayService.this ); stopSelf(); - } else { - timerFired( RelayService.this ); } } }; @@ -1086,10 +1088,12 @@ public class RelayService extends XWJIService private boolean registerWithRelayIfNot( long timestamp ) { - if ( !s_registered && shouldRegister() ) { + boolean haveGames = haveLiveRelayGames(); + if ( !s_registered && shouldRegister() && haveGames ) { registerWithRelay( timestamp ); } - return s_registered; + Log.d( TAG, "registerWithRelayIfNot()=>%b", s_registered ); + return s_registered && haveGames; } private void requestMessages( long timestamp ) @@ -1761,10 +1765,15 @@ public class RelayService extends XWJIService } } + private boolean haveLiveRelayGames() + { + return 0 < DBUtils.countOpenGamesUsingRelay( this ); + } + private int figureBackoffSeconds() { // DbgUtils.printStack(); int result = 60 * 60; // default if no games - if ( 0 < DBUtils.countOpenGamesUsingRelay( this ) ) { + if ( haveLiveRelayGames() ) { long diff; synchronized ( RelayService.class ) { long now = Utils.getCurSeconds(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java index a6d7da8f5..144f27dc1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java @@ -512,10 +512,8 @@ public class XWPrefs { if ( -1 == flags ) { result = new CommsConnTypeSet(); if ( getRelayEnabled( context ) ) { - CommsConnType typ = BuildConfig.NO_NEW_RELAY - ? CommsConnType.COMMS_CONN_MQTT - : CommsConnType.COMMS_CONN_RELAY; - result.add( typ ); + result.add( CommsConnType.COMMS_CONN_MQTT ); + result.add( CommsConnType.COMMS_CONN_RELAY ); } if ( BTUtils.BTEnabled() ) { result.add( CommsConnType.COMMS_CONN_BT ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java index 2d171f6c4..a0054e77a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java @@ -169,12 +169,8 @@ public class CommsAddrRec implements Serializable { public static List getSupported( Context context ) { List supported = new ArrayList<>(); - if ( !BuildConfig.NO_NEW_RELAY ) { - supported.add( CommsConnType.COMMS_CONN_RELAY ); - } - if ( BuildConfig.OFFER_MQTT ) { - supported.add( CommsConnType.COMMS_CONN_MQTT ); - } + supported.add( CommsConnType.COMMS_CONN_RELAY ); + supported.add( CommsConnType.COMMS_CONN_MQTT ); if ( BTUtils.BTAvailable() ) { supported.add( CommsConnType.COMMS_CONN_BT ); } diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index 078538aa4..4b0e75c7a 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -670,6 +670,27 @@ addrFromStream( CommsAddrRec* addrP, XWStreamCtxt* stream ) } } +/* Return TRUE if there are no addresses left that include relay */ +static XP_Bool +removeRelayIf( CommsCtxt* comms ) +{ + XP_Bool allRemoved = XP_TRUE; + for ( AddressRecord* rec = comms->recs; !!rec; rec = rec->next ) { + CommsAddrRec* addr = &rec->addr; + if ( addr_hasType( addr, COMMS_CONN_RELAY ) ) { + if ( addr_hasType( addr, COMMS_CONN_MQTT ) + && 0 != addr->u.mqtt.devID ) { + addr_rmType( addr, COMMS_CONN_RELAY ); + XP_LOGFF( "we DID remove RELAY" ); + } else { + allRemoved = XP_FALSE; + } + } + } + LOG_RETURNF( "%s", boolToStr(allRemoved) ); + return allRemoved; +} + CommsCtxt* comms_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, XW_UtilCtxt* util, XP_Bool isServer, @@ -796,6 +817,12 @@ comms_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream, } notifyQueueChanged( comms, xwe ); + if ( addr_hasType( &comms->addr, COMMS_CONN_RELAY ) + && addr_hasType( &comms->addr, COMMS_CONN_MQTT ) + && 0 != &comms->addr.u.mqtt.devID + && removeRelayIf( comms ) ) { + addr_rmType( &comms->addr, COMMS_CONN_RELAY ); + } return comms; } /* comms_makeFromStream */