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 GamePtr m_jniGamePtr;
|
||||||
private CurGameInfo m_gi;
|
private CurGameInfo m_gi;
|
||||||
private GameSummary m_summary;
|
private GameSummary m_summary;
|
||||||
private boolean m_relayMissing;
|
|
||||||
private Handler m_handler = null;
|
private Handler m_handler = null;
|
||||||
private TimerRunnable[] m_timers;
|
private TimerRunnable[] m_timers;
|
||||||
private Runnable m_screenTimer;
|
private Runnable m_screenTimer;
|
||||||
|
@ -1305,9 +1304,6 @@ public class BoardDelegate extends DelegateBase
|
||||||
NetLaunchInfo nli = new NetLaunchInfo( m_activity, m_summary, m_gi,
|
NetLaunchInfo nli = new NetLaunchInfo( m_activity, m_summary, m_gi,
|
||||||
1, // nPlayers
|
1, // nPlayers
|
||||||
1 + m_mySIS.nGuestDevs ); // fc
|
1 + m_mySIS.nGuestDevs ); // fc
|
||||||
if ( m_relayMissing ) {
|
|
||||||
nli.removeAddress( CommsConnType.COMMS_CONN_RELAY );
|
|
||||||
}
|
|
||||||
switch ( means ) {
|
switch ( means ) {
|
||||||
case EMAIL:
|
case EMAIL:
|
||||||
GameUtils.launchEmailInviteActivity( m_activity, nli );
|
GameUtils.launchEmailInviteActivity( m_activity, nli );
|
||||||
|
@ -2693,10 +2689,6 @@ public class BoardDelegate extends DelegateBase
|
||||||
nPlayers, forceChannel )
|
nPlayers, forceChannel )
|
||||||
.setRemotesAreRobots( m_remotesAreRobots );
|
.setRemotesAreRobots( m_remotesAreRobots );
|
||||||
|
|
||||||
if ( m_relayMissing ) {
|
|
||||||
nli.removeAddress( CommsConnType.COMMS_CONN_RELAY );
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( m_missingMeans ) {
|
switch ( m_missingMeans ) {
|
||||||
case BLUETOOTH:
|
case BLUETOOTH:
|
||||||
if ( ! m_progressShown ) {
|
if ( ! m_progressShown ) {
|
||||||
|
@ -2994,15 +2986,11 @@ public class BoardDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( doIt ) {
|
if ( doIt ) {
|
||||||
CommsConnTypeSet connTypes = summary.conTypes;
|
|
||||||
if ( BuildConfig.NO_NEW_RELAY ) {
|
|
||||||
connTypes.remove(CommsConnType.COMMS_CONN_RELAY);
|
|
||||||
relayID = null;
|
|
||||||
}
|
|
||||||
String newName = summary.getRematchName( activity );
|
String newName = summary.getRematchName( activity );
|
||||||
Intent intent = GamesListDelegate
|
Intent intent = GamesListDelegate
|
||||||
.makeRematchIntent( activity, rowid, groupID, gi, connTypes,
|
.makeRematchIntent( activity, rowid, groupID, gi,
|
||||||
btAddr, phone, relayID, p2pMacAddress,
|
summary.conTypes, btAddr, phone,
|
||||||
|
relayID, p2pMacAddress,
|
||||||
mqttDevID, newName );
|
mqttDevID, newName );
|
||||||
if ( null != intent ) {
|
if ( null != intent ) {
|
||||||
activity.startActivity( intent );
|
activity.startActivity( intent );
|
||||||
|
|
|
@ -373,10 +373,6 @@ public class DBUtils {
|
||||||
public static void addRematchInfo( Context context, long rowid,
|
public static void addRematchInfo( Context context, long rowid,
|
||||||
CommsAddrRec addr )
|
CommsAddrRec addr )
|
||||||
{
|
{
|
||||||
if ( BuildConfig.NO_NEW_RELAY ) {
|
|
||||||
addr.remove(CommsConnType.COMMS_CONN_RELAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
try ( GameLock lock = GameLock.tryLock(rowid) ) {
|
try ( GameLock lock = GameLock.tryLock(rowid) ) {
|
||||||
if ( null != lock ) {
|
if ( null != lock ) {
|
||||||
String as64 = Utils.serializableToString64( addr );
|
String as64 = Utils.serializableToString64( addr );
|
||||||
|
@ -478,8 +474,10 @@ public class DBUtils {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d( TAG, "countOpenGamesUsing(with: %s, without: %s) => %d",
|
if ( 0 < result ) {
|
||||||
connTypWith, connTypWithout, result );
|
Log.d( TAG, "countOpenGamesUsing(with: %s, without: %s) => %d",
|
||||||
|
connTypWith, connTypWithout, result );
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -626,9 +626,6 @@ public class GameUtils {
|
||||||
String[] dictArray = {dict};
|
String[] dictArray = {dict};
|
||||||
if ( null == addrSet ) {
|
if ( null == addrSet ) {
|
||||||
addrSet = XWPrefs.getAddrTypes( context );
|
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
|
// 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 )
|
private void doOpenGame( Object[] params )
|
||||||
{
|
{
|
||||||
final long rowid = (Long)params[0];
|
final long rowid = (Long)params[0];
|
||||||
GameSummary summary = (GameSummary)params[1];
|
try {
|
||||||
|
if ( checkWarnNoDict( rowid ) ) {
|
||||||
if ( null != summary
|
launchGame( rowid );
|
||||||
&& 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();
|
|
||||||
}
|
}
|
||||||
|
} catch ( GameLock.GameLockedException gle ) {
|
||||||
|
Log.ex( TAG, gle );
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3152,9 +3144,6 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
.putExtra( REMATCH_NEWNAME_EXTRA, newName );
|
.putExtra( REMATCH_NEWNAME_EXTRA, newName );
|
||||||
|
|
||||||
if ( null != addrTypes ) {
|
if ( null != addrTypes ) {
|
||||||
if ( BuildConfig.NO_NEW_RELAY ) {
|
|
||||||
Assert.assertTrueNR( !addrTypes.contains(CommsConnType.COMMS_CONN_RELAY) );
|
|
||||||
}
|
|
||||||
intent.putExtra( REMATCH_ADDRS_EXTRA, addrTypes.toInt() );
|
intent.putExtra( REMATCH_ADDRS_EXTRA, addrTypes.toInt() );
|
||||||
if ( null != btAddr ) {
|
if ( null != btAddr ) {
|
||||||
Assert.assertTrue( addrTypes.contains( CommsConnType.COMMS_CONN_BT ) );
|
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.DlgDelegate.Action;
|
||||||
import org.eehouse.android.xw4.ExpandImageButton.ExpandChangeListener;
|
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.CommsConnTypeSet;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||||
import org.eehouse.android.xw4.jni.XwJNI;
|
import org.eehouse.android.xw4.jni.XwJNI;
|
||||||
|
@ -220,22 +221,19 @@ public class KnownPlayersDelegate extends DelegateBase {
|
||||||
addListing( list, R.string.knowns_ts_fmt, str );
|
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 );
|
addListing( list, R.string.knowns_bt_fmt, addr.bt_hostName );
|
||||||
if ( BuildConfig.NON_RELEASE ) {
|
if ( BuildConfig.NON_RELEASE ) {
|
||||||
addListing( list, R.string.knowns_bta_fmt, addr.bt_btAddr );
|
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 );
|
addListing( list, R.string.knowns_smsphone_fmt, addr.sms_phone );
|
||||||
}
|
}
|
||||||
if ( BuildConfig.NON_RELEASE ) {
|
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 );
|
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 )
|
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 INITIAL_BACKOFF = 5;
|
||||||
private static final int UDP_FAIL_LIMIT = 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
|
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
|
// 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 ) {
|
if ( backoff < MIN_BACKOFF ) {
|
||||||
backoff = MIN_BACKOFF;
|
backoff = MIN_BACKOFF;
|
||||||
} else {
|
} else {
|
||||||
backoff *= 2;
|
backoff = backoff * 12 / 10;
|
||||||
}
|
}
|
||||||
if ( MAX_BACKOFF <= backoff ) {
|
if ( MAX_BACKOFF <= backoff ) {
|
||||||
backoff = MAX_BACKOFF;
|
backoff = MAX_BACKOFF;
|
||||||
|
@ -278,6 +278,10 @@ public class RelayService extends XWJIService
|
||||||
{
|
{
|
||||||
Intent intent = getIntentTo( context, MsgCmds.TIMER_FIRED );
|
Intent intent = getIntentTo( context, MsgCmds.TIMER_FIRED );
|
||||||
enqueueWork( context, intent );
|
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,
|
public static int sendPacket( Context context, long rowid, byte[] msg,
|
||||||
|
@ -390,8 +394,6 @@ public class RelayService extends XWJIService
|
||||||
NetStateCache.unregister( RelayService.this,
|
NetStateCache.unregister( RelayService.this,
|
||||||
RelayService.this );
|
RelayService.this );
|
||||||
stopSelf();
|
stopSelf();
|
||||||
} else {
|
|
||||||
timerFired( RelayService.this );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1086,10 +1088,12 @@ public class RelayService extends XWJIService
|
||||||
|
|
||||||
private boolean registerWithRelayIfNot( long timestamp )
|
private boolean registerWithRelayIfNot( long timestamp )
|
||||||
{
|
{
|
||||||
if ( !s_registered && shouldRegister() ) {
|
boolean haveGames = haveLiveRelayGames();
|
||||||
|
if ( !s_registered && shouldRegister() && haveGames ) {
|
||||||
registerWithRelay( timestamp );
|
registerWithRelay( timestamp );
|
||||||
}
|
}
|
||||||
return s_registered;
|
Log.d( TAG, "registerWithRelayIfNot()=>%b", s_registered );
|
||||||
|
return s_registered && haveGames;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestMessages( long timestamp )
|
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() {
|
private int figureBackoffSeconds() {
|
||||||
// DbgUtils.printStack();
|
// DbgUtils.printStack();
|
||||||
int result = 60 * 60; // default if no games
|
int result = 60 * 60; // default if no games
|
||||||
if ( 0 < DBUtils.countOpenGamesUsingRelay( this ) ) {
|
if ( haveLiveRelayGames() ) {
|
||||||
long diff;
|
long diff;
|
||||||
synchronized ( RelayService.class ) {
|
synchronized ( RelayService.class ) {
|
||||||
long now = Utils.getCurSeconds();
|
long now = Utils.getCurSeconds();
|
||||||
|
|
|
@ -512,10 +512,8 @@ public class XWPrefs {
|
||||||
if ( -1 == flags ) {
|
if ( -1 == flags ) {
|
||||||
result = new CommsConnTypeSet();
|
result = new CommsConnTypeSet();
|
||||||
if ( getRelayEnabled( context ) ) {
|
if ( getRelayEnabled( context ) ) {
|
||||||
CommsConnType typ = BuildConfig.NO_NEW_RELAY
|
result.add( CommsConnType.COMMS_CONN_MQTT );
|
||||||
? CommsConnType.COMMS_CONN_MQTT
|
result.add( CommsConnType.COMMS_CONN_RELAY );
|
||||||
: CommsConnType.COMMS_CONN_RELAY;
|
|
||||||
result.add( typ );
|
|
||||||
}
|
}
|
||||||
if ( BTUtils.BTEnabled() ) {
|
if ( BTUtils.BTEnabled() ) {
|
||||||
result.add( CommsConnType.COMMS_CONN_BT );
|
result.add( CommsConnType.COMMS_CONN_BT );
|
||||||
|
|
|
@ -169,12 +169,8 @@ public class CommsAddrRec implements Serializable {
|
||||||
public static List<CommsConnType> getSupported( Context context )
|
public static List<CommsConnType> getSupported( Context context )
|
||||||
{
|
{
|
||||||
List<CommsConnType> supported = new ArrayList<>();
|
List<CommsConnType> supported = new ArrayList<>();
|
||||||
if ( !BuildConfig.NO_NEW_RELAY ) {
|
supported.add( CommsConnType.COMMS_CONN_RELAY );
|
||||||
supported.add( CommsConnType.COMMS_CONN_RELAY );
|
supported.add( CommsConnType.COMMS_CONN_MQTT );
|
||||||
}
|
|
||||||
if ( BuildConfig.OFFER_MQTT ) {
|
|
||||||
supported.add( CommsConnType.COMMS_CONN_MQTT );
|
|
||||||
}
|
|
||||||
if ( BTUtils.BTAvailable() ) {
|
if ( BTUtils.BTAvailable() ) {
|
||||||
supported.add( CommsConnType.COMMS_CONN_BT );
|
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*
|
CommsCtxt*
|
||||||
comms_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
|
comms_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
|
||||||
XW_UtilCtxt* util, XP_Bool isServer,
|
XW_UtilCtxt* util, XP_Bool isServer,
|
||||||
|
@ -796,6 +817,12 @@ comms_makeFromStream( MPFORMAL XWEnv xwe, XWStreamCtxt* stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyQueueChanged( comms, xwe );
|
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;
|
return comms;
|
||||||
} /* comms_makeFromStream */
|
} /* comms_makeFromStream */
|
||||||
|
|
Loading…
Add table
Reference in a new issue