mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
deal better with old relay games
Attempting to stop calling the relay, but to let relay-only games finish and issue invitations. Big changes are that relay is removed from games if they have viable mqtt connections, and relay timers fire less often, then eventually stop getting set if there are no active games. Result is that a relay-only invitation won't likely be received, but there should be few or none of those now.
This commit is contained in:
parent
0cd3be2668
commit
4bfcf2afb4
9 changed files with 64 additions and 64 deletions
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -169,12 +169,8 @@ public class CommsAddrRec implements Serializable {
|
|||
public static List<CommsConnType> getSupported( Context context )
|
||||
{
|
||||
List<CommsConnType> 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 );
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue