add addrType to comms' main addr when added to channel

I'm fixing android client not showing stats for or allowing to disable
mqtt after it's added automatically to a game that connects
otherwise. Problem was that only the channel got the mqtt address
flag. So now add the flag for any type that's added.
This commit is contained in:
Eric House 2020-09-10 15:11:22 -07:00
parent 88dbc40180
commit 81799d3903
9 changed files with 64 additions and 27 deletions

View file

@ -558,7 +558,8 @@ public class BTService extends XWJIService {
// listenUsingRfcommWithServiceRecord() in background (on
// Android 9)
m_serverSocket = null;
Log.ex( TAG, ex );
// I'm seeing too much of this on two-user systems.
// Log.ex( TAG, ex );
}
int nBadCount = 0;

View file

@ -38,6 +38,7 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.loc.LocUtils;
public class ConnViaViewLayout extends LinearLayout {
private static final String TAG = ConnViaViewLayout.class.getSimpleName();
private CommsConnTypeSet m_curSet;
private DlgDelegate.HasDlgDelegate m_dlgDlgt;
private Activity m_activity;

View file

@ -213,6 +213,20 @@ public class CommsAddrRec {
}
}
@Override
public String toString()
{
if ( BuildConfig.NON_RELEASE ) {
List<String> tmp = new ArrayList<>();
for ( CommsConnType typ : getTypes() ) {
tmp.add( typ.toString() );
}
return TextUtils.join(",", tmp );
} else {
return super.toString();
}
}
public String toString( Context context, boolean longVersion )
{
String result;

View file

@ -603,7 +603,6 @@ addrTypesToJ( JNIEnv* env, const CommsAddrRec* addr )
"(Ljava/lang/Object;)Z" );
XP_ASSERT( !!mid2 );
CommsConnType typ;
/* far as it gets */
for ( XP_U32 st = 0; addr_iter( addr, &typ, &st ); ) {
jobject jtyp = intToJEnum( env, typ,
PKG_PATH("jni/CommsAddrRec$CommsConnType") );

View file

@ -2183,15 +2183,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
server_getDupTimerExpires(server) );
if ( !!state->game.comms ) {
CommsAddrRec addr;
CommsCtxt* comms = state->game.comms;
comms_getAddr( comms, &addr );
setInt( env, jsummary, "seed", comms_getChannelSeed( comms ) );
setInt( env, jsummary, "missingPlayers",
server_getMissingPlayers( server ) );
setInt( env, jsummary, "nPacketsPending",
comms_countPendingPackets( state->game.comms ) );
CommsAddrRec addr;
comms_getAddr( comms, &addr );
setTypeSetFieldIn( env, &addr, jsummary, "conTypes" );
CommsConnType typ;
@ -2226,7 +2226,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
case COMMS_CONN_SMS: addrps[ii] = (XP_UCHAR*)&addrs[ii].u.sms.phone; break;
default: XP_ASSERT(0); break;
}
XP_LOGF( "%s: adding btaddr/phone/mac %s", __func__, addrps[ii] );
XP_LOGFF( "adding btaddr/phone/mac %s", addrps[ii] );
}
setStringArray( env, jsummary, "remoteDevs", count, addrps );
}

View file

@ -194,9 +194,10 @@ static AddressRecord* rememberChannelAddress( CommsCtxt* comms, XWEnv xwe,
XP_PlayerAddr channelNo,
XWHostID id,
const CommsAddrRec* addr );
static void augmentChannelAddr( AddressRecord* rec, const CommsAddrRec* addr,
XWHostID hostID );
static void augmentAddr( CommsAddrRec* dest, const CommsAddrRec* src );
static void augmentChannelAddr( CommsCtxt* comms, AddressRecord* rec,
const CommsAddrRec* addr, XWHostID hostID );
static void augmentAddr( CommsCtxt* comms, CommsAddrRec* dest,
const CommsAddrRec* src );
static XP_Bool channelToAddress( CommsCtxt* comms, XWEnv xwe, XP_PlayerAddr channelNo,
const CommsAddrRec** addr );
static AddressRecord* getRecordFor( CommsCtxt* comms, XWEnv xwe,
@ -1031,7 +1032,7 @@ comms_augmentHostAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr )
&& ! addr_hasType( &comms->addr, COMMS_CONN_RELAY );
CommsAddrRec tmp = comms->addr;
augmentAddr( &tmp, addr );
augmentAddr( comms, &tmp, addr );
util_addrChange( comms->util, xwe, &comms->addr, &tmp );
comms->addr = tmp;
@ -1061,7 +1062,7 @@ comms_addMQTTDevID( CommsCtxt* comms, XP_PlayerAddr channelNo,
CommsAddrRec addr = {0};
addr_setType( &addr, COMMS_CONN_MQTT );
addr.u.mqtt.devID = *devID;
augmentAddr( &rec->addr, &addr );
augmentAddr( comms, &rec->addr, &addr );
}
}
if ( !found ) {
@ -2266,7 +2267,7 @@ validateInitialMessage( CommsCtxt* comms, XWEnv xwe,
XP_LOGF( TAGFMT() "looking at %s", TAGPRMS, cbuf );
rec = getRecordFor( comms, xwe, addr, *channelNo, XP_TRUE );
if ( !!rec ) {
augmentChannelAddr( rec, addr, senderID );
augmentChannelAddr( comms, rec, addr, senderID );
/* reject: we've already seen init message on channel */
XP_LOGF( TAGFMT() "rejecting duplicate INIT message", TAGPRMS );
rec = NULL;
@ -2341,7 +2342,7 @@ validateChannelMessage( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr,
if ( !!rec ) {
removeFromQueue( comms, xwe, channelNo, lastMsgRcd );
augmentChannelAddr( rec, addr, senderID );
augmentChannelAddr( comms, rec, addr, senderID );
if ( msgID == rec->lastMsgRcd + 1 ) {
XP_LOGF( TAGFMT() "expected %d AND got %d", TAGPRMS,
@ -2924,20 +2925,31 @@ logAddrs( const CommsCtxt* comms, XWEnv xwe, const char* caller )
#endif
static void
augmentChannelAddr( AddressRecord* const rec, const CommsAddrRec* addr,
XWHostID hostID )
augmentChannelAddr( CommsCtxt* comms, AddressRecord* const rec,
const CommsAddrRec* addr, XWHostID hostID )
{
augmentAddr( &rec->addr, addr );
augmentAddr( comms, &rec->addr, addr );
if ( addr_hasType( &rec->addr, COMMS_CONN_RELAY ) ) {
if ( 0 != hostID ) {
rec->rr.hostID = hostID;
XP_LOGF( "%s: set hostID for rec %p to %d", __func__, rec, hostID );
}
}
#ifdef DEBUG
CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( addr, &typ, &st ); ) {
if ( !addr_hasType( &comms->addr, typ ) ) {
XP_LOGFF( "main addr missing type %s", ConnType2Str(typ) );
XP_ASSERT(0); /* firing */
}
}
#endif
}
static void
augmentAddr( CommsAddrRec* destAddr, const CommsAddrRec* srcAddr )
augmentAddr( CommsCtxt* comms, CommsAddrRec* destAddr,
const CommsAddrRec* srcAddr )
{
if ( !!srcAddr ) {
CommsConnType typ;
@ -2945,6 +2957,15 @@ augmentAddr( CommsAddrRec* destAddr, const CommsAddrRec* srcAddr )
if ( ! addr_hasType( destAddr, typ ) ) {
XP_LOGFF( "adding new type %s to rec", ConnType2Str(typ) );
addr_addType( destAddr, typ );
/* If an address is getting added to a channel, the top-level
address should also include the type. The specifics of the
address don't make sense to copy, however. */
if ( ! addr_hasType( &comms->addr, typ ) ) {
XP_ASSERT( destAddr != &comms->addr ); /* we just added it, so can't be comms->addr */
XP_LOGFF( "adding %s to comms->addr", ConnType2Str(typ) );
addr_addType( &comms->addr, typ );
}
}
const void* src = NULL;

View file

@ -37,14 +37,14 @@ typedef XP_U8 XWHostID;
typedef enum {
COMMS_CONN_NONE /* I want errors on uninited case */
,COMMS_CONN_IR
,COMMS_CONN_IP_DIRECT
,COMMS_CONN_RELAY
,COMMS_CONN_BT
,COMMS_CONN_SMS
,COMMS_CONN_IR /* 1 */
,COMMS_CONN_IP_DIRECT /* 2 */
,COMMS_CONN_RELAY /* 3 */
,COMMS_CONN_BT /* 4 */
,COMMS_CONN_SMS /* 5 */
,COMMS_CONN_P2P /* a.k.a. Wifi direct */
,COMMS_CONN_NFC
,COMMS_CONN_MQTT
,COMMS_CONN_NFC /* 7 */
,COMMS_CONN_MQTT /* 8 */
,COMMS_CONN_NTYPES
} CommsConnType;

View file

@ -2947,11 +2947,9 @@ main( int argc, char** argv )
addr_addType( &mainParams.addr, COMMS_CONN_MQTT );
break;
case CMD_MQTTHOST:
addr_addType( &mainParams.addr, COMMS_CONN_MQTT );
mainParams.connInfo.mqtt.hostName = optarg;
break;
case CMD_MQTTPORT:
addr_addType( &mainParams.addr, COMMS_CONN_MQTT );
mainParams.connInfo.mqtt.port = atoi(optarg);
break;
case CMD_INVITEE_MQTTDEVID:

View file

@ -472,8 +472,10 @@ def build_cmds(args):
PARAMS += [ '--invitee-sms-number', makeSMSPhoneNo(GAME, dev) ]
PARAMS += [ '--mqtt-port', args.MQTT_PORT, '--mqtt-host', args.MQTT_HOST ]
if args.ADD_MQTT and DEV == 1:
PARAMS += [ '--force-invite' ]
if args.ADD_MQTT:
PARAMS += [ '--with-mqtt' ]
if DEV == 1:
PARAMS += [ '--force-invite' ]
if args.UNDO_PCT > 0:
PARAMS += ['--undo-pct', args.UNDO_PCT]
@ -648,6 +650,7 @@ def run_cmds(args, devs):
devs.remove(dev)
else:
time.sleep(1.0)
print('.', end='', flush=True)
# if we get here via a break, kill any remaining games
if devs: