Don't allow comms types that aren't in selfAddress

(Likely crashes on android)
This commit is contained in:
Eric House 2023-01-15 16:18:26 -08:00
parent efb6c2d0a6
commit c620f9bc75
2 changed files with 24 additions and 40 deletions

View file

@ -268,7 +268,6 @@ static XP_Bool channelToAddress( const CommsCtxt* comms, XWEnv xwe,
XP_PlayerAddr channelNo, const CommsAddrRec** addr ); XP_PlayerAddr channelNo, const CommsAddrRec** addr );
static AddressRecord* getRecordFor( const CommsCtxt* comms, XWEnv xwe, static AddressRecord* getRecordFor( const CommsCtxt* comms, XWEnv xwe,
const CommsAddrRec* addr, XP_PlayerAddr channelNo ); const CommsAddrRec* addr, XP_PlayerAddr channelNo );
static void augmentSelfAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr );
static XP_S16 sendMsg( const CommsCtxt* comms, XWEnv xwe, MsgQueueElem* elem, static XP_S16 sendMsg( const CommsCtxt* comms, XWEnv xwe, MsgQueueElem* elem,
CommsConnType filter ); CommsConnType filter );
static MsgQueueElem* addToQueue( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* newElem ); static MsgQueueElem* addToQueue( CommsCtxt* comms, XWEnv xwe, MsgQueueElem* newElem );
@ -492,7 +491,8 @@ comms_make( MPFORMAL XWEnv xwe, XW_UtilCtxt* util, XP_Bool isServer,
#endif #endif
if ( !!selfAddr ) { if ( !!selfAddr ) {
augmentSelfAddr( comms, xwe, selfAddr ); ASSERT_ADDR_OK(selfAddr);
comms->selfAddr = *selfAddr;
} }
if ( !!hostAddr ) { if ( !!hostAddr ) {
XP_ASSERT( !isServer ); XP_ASSERT( !isServer );
@ -504,6 +504,13 @@ comms_make( MPFORMAL XWEnv xwe, XW_UtilCtxt* util, XP_Bool isServer,
rememberChannelAddress( comms, xwe, channelNo, 0, hostAddr, rememberChannelAddress( comms, xwe, channelNo, 0, hostAddr,
COMMS_VERSION ); COMMS_VERSION );
XP_ASSERT( rec == getRecordFor( comms, xwe, hostAddr, channelNo ) ); XP_ASSERT( rec == getRecordFor( comms, xwe, hostAddr, channelNo ) );
#ifdef DEBUG
/* Anything in hostAddr should be supported -- in selfAddr */
CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( hostAddr, &typ, &st ); ) {
XP_ASSERT( addr_hasType( &comms->selfAddr, typ ) );
}
#endif
} }
return comms; return comms;
@ -1199,36 +1206,6 @@ comms_getHostAddr( const CommsCtxt* comms, CommsAddrRec* addr )
return haveAddr; return haveAddr;
} /* comms_getAddr */ } /* comms_getAddr */
static void
augmentSelfAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr )
{
logAddr( comms, xwe, addr, __func__ );
XP_ASSERT( comms != NULL );
#ifdef XWFEATURE_RELAY
XP_Bool addingRelay = addr_hasType( addr, COMMS_CONN_RELAY )
&& ! addr_hasType( &comms->selfAddr, COMMS_CONN_RELAY );
#endif
CommsAddrRec tmp = comms->selfAddr;
augmentAddrIntrnl( comms, &tmp, addr, XP_TRUE );
util_addrChange( comms->util, xwe, &comms->selfAddr, &tmp );
comms->selfAddr = tmp;
logAddr( comms, xwe, &comms->selfAddr, "after" );
#ifdef COMMS_HEARTBEAT
setDoHeartbeat( comms );
#endif
#ifdef XWFEATURE_RELAY
if ( addingRelay ) {
XP_ASSERT(0);
sendConnect( comms, xwe , XP_TRUE
);
}
#endif
} /* comms_setHostAddr */
void void
comms_addMQTTDevID( CommsCtxt* comms, XP_PlayerAddr channelNo, comms_addMQTTDevID( CommsCtxt* comms, XP_PlayerAddr channelNo,
const MQTTDevID* devID ) const MQTTDevID* devID )
@ -1246,7 +1223,9 @@ comms_addMQTTDevID( CommsCtxt* comms, XP_PlayerAddr channelNo,
for ( AddressRecord* rec = comms->recs; !!rec && !found; rec = rec->next ) { for ( AddressRecord* rec = comms->recs; !!rec && !found; rec = rec->next ) {
found = (rec->channelNo & ~CHANNEL_MASK) == (channelNo & ~CHANNEL_MASK); found = (rec->channelNo & ~CHANNEL_MASK) == (channelNo & ~CHANNEL_MASK);
if ( found ) { if ( found ) {
if ( addr_hasType( &rec->addr, COMMS_CONN_MQTT ) ) { if ( !addr_hasType( &comms->selfAddr, COMMS_CONN_MQTT ) ) {
XP_LOGFF( "not adding mqtt because game doesn't allow it" );
} else if ( addr_hasType( &rec->addr, COMMS_CONN_MQTT ) ) {
XP_ASSERT( *devID == rec->addr.u.mqtt.devID ); XP_ASSERT( *devID == rec->addr.u.mqtt.devID );
} else { } else {
CommsAddrRec tmp = {0}; CommsAddrRec tmp = {0};
@ -1927,6 +1906,7 @@ sendMsg( const CommsCtxt* comms, XWEnv xwe, MsgQueueElem* elem,
XP_LOGFF( "dropping message because not of type %s", XP_LOGFF( "dropping message because not of type %s",
ConnType2Str( filter ) ); ConnType2Str( filter ) );
} else { } else {
XP_ASSERT( addr_hasType( &comms->selfAddr, typ ) );
#ifdef COMMS_CHECKSUM #ifdef COMMS_CHECKSUM
XP_LOGFF( TAGFMT() "sending msg with sum %s using typ %s", TAGPRMS, XP_LOGFF( TAGFMT() "sending msg with sum %s using typ %s", TAGPRMS,
elem->checksum, ConnType2Str(typ) ); elem->checksum, ConnType2Str(typ) );

View file

@ -745,14 +745,18 @@ server_countTilesInPool( ServerCtxt* server )
the host. the host.
*/ */
static void static void
addMQTTDevID( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream ) addMQTTDevIDIf( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream )
{ {
MQTTDevID devID; CommsAddrRec selfAddr = {0};
dvc_getMQTTDevID( server->vol.dutil, xwe, &devID ); comms_getSelfAddr( server->vol.comms, &selfAddr );
if ( addr_hasType( &selfAddr, COMMS_CONN_MQTT ) ) {
MQTTDevID devID;
dvc_getMQTTDevID( server->vol.dutil, xwe, &devID );
XP_UCHAR buf[32]; XP_UCHAR buf[32];
formatMQTTDevID( &devID, buf, VSIZE(buf) ); formatMQTTDevID( &devID, buf, VSIZE(buf) );
stringToStream( stream, buf ); stringToStream( stream, buf );
}
} }
static void static void
@ -2133,7 +2137,7 @@ sendInitialMessage( ServerCtxt* server, XWEnv xwe )
} }
} }
addMQTTDevID( server, xwe, stream ); addMQTTDevIDIf( server, xwe, stream );
stream_destroy( stream, xwe ); stream_destroy( stream, xwe );
} }