From 81799d3903724c1ccb265891fd7101c05ffc71a9 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 10 Sep 2020 15:11:22 -0700 Subject: [PATCH] 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. --- .../org/eehouse/android/xw4/BTService.java | 3 +- .../android/xw4/ConnViaViewLayout.java | 1 + .../eehouse/android/xw4/jni/CommsAddrRec.java | 14 ++++++ xwords4/android/jni/andutils.c | 1 - xwords4/android/jni/xwjni.c | 6 +-- xwords4/common/comms.c | 43 ++++++++++++++----- xwords4/common/comms.h | 14 +++--- xwords4/linux/linuxmain.c | 2 - xwords4/linux/scripts/discon_ok2.py | 7 ++- 9 files changed, 64 insertions(+), 27 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 068f04999..302dc96a1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -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; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java index 60f037ec9..e528ffb46 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java @@ -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; 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 4afd8b889..50f4cc45a 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 @@ -213,6 +213,20 @@ public class CommsAddrRec { } } + @Override + public String toString() + { + if ( BuildConfig.NON_RELEASE ) { + List 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; diff --git a/xwords4/android/jni/andutils.c b/xwords4/android/jni/andutils.c index 31bddfc0b..87d9fc4f2 100644 --- a/xwords4/android/jni/andutils.c +++ b/xwords4/android/jni/andutils.c @@ -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") ); diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index 51a9f01ca..a07454ecc 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -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 ); } diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index f410a689f..5b6f0a253 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -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; diff --git a/xwords4/common/comms.h b/xwords4/common/comms.h index b36e991f1..e389600df 100644 --- a/xwords4/common/comms.h +++ b/xwords4/common/comms.h @@ -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; diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index b2e8ff13a..eaa629b9c 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -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: diff --git a/xwords4/linux/scripts/discon_ok2.py b/xwords4/linux/scripts/discon_ok2.py index f7d4c94cc..55e392c64 100755 --- a/xwords4/linux/scripts/discon_ok2.py +++ b/xwords4/linux/scripts/discon_ok2.py @@ -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: