augment addresses even when message received is a duplicate. Now games

using (fake) SMS and relay work whichever of the address modes is
disabled during the game, on either side.  At least for two-device
games.
This commit is contained in:
Eric House 2014-11-11 07:46:01 -08:00
parent 552ab8fa48
commit 0e2bbfc1ad

View file

@ -1216,8 +1216,7 @@ removeFromQueue( CommsCtxt* comms, XP_PlayerAddr channelNo, MsgID msgID )
XP_LOGF( "%s: remove msgs <= " XP_LD " for %s (queueLen: %d)", XP_LOGF( "%s: remove msgs <= " XP_LD " for %s (queueLen: %d)",
__func__, msgID, cbuf, comms->queueLen ); __func__, msgID, cbuf, comms->queueLen );
if ( (channelNo == 0) || !!getRecordFor( comms, NULL, channelNo, if ((channelNo == 0) || !!getRecordFor( comms, NULL, channelNo, XP_FALSE)) {
XP_FALSE ) ) {
MsgQueueElem* elem = comms->msgQueueHead; MsgQueueElem* elem = comms->msgQueueHead;
MsgQueueElem* next; MsgQueueElem* next;
@ -1284,16 +1283,12 @@ static XP_S16
sendMsg( CommsCtxt* comms, MsgQueueElem* elem ) sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
{ {
XP_S16 result = -1; XP_S16 result = -1;
XP_PlayerAddr channelNo; XP_PlayerAddr channelNo = elem->channelNo;
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH CNO_FMT( cbuf, channelNo );
// CommsConnType conType = comms_getConType( comms );
#endif
channelNo = elem->channelNo;
#ifdef COMMS_CHECKSUM #ifdef COMMS_CHECKSUM
XP_LOGF( "%s: sending message of len %d with sum %s", __func__, elem->len, XP_LOGF( "%s: sending message of len %d on %s with sum %s", __func__, elem->len,
elem->checksum ); cbuf, elem->checksum );
#endif #endif
CommsConnType typ; CommsConnType typ;
@ -1370,9 +1365,9 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
XP_LOGF( "%s: elem's sendCount since load: %d", __func__, XP_LOGF( "%s: elem's sendCount since load: %d", __func__,
elem->sendCount ); elem->sendCount );
} }
CNO_FMT( cbuf, elem->channelNo ); CNO_FMT( cbuf1, elem->channelNo );
XP_LOGF( "%s(%s; msgID=" XP_LD ")=>%d", __func__, XP_LOGF( "%s(%s; msgID=" XP_LD ")=>%d", __func__,
cbuf, elem->msgID, result ); cbuf1, elem->msgID, result );
return result; return result;
} /* sendMsg */ } /* sendMsg */
@ -1739,38 +1734,35 @@ preProcess( CommsCtxt* comms, const CommsAddrRec* useAddr,
XWHostID* XP_UNUSED_RELAY(senderID) ) XWHostID* XP_UNUSED_RELAY(senderID) )
{ {
XP_Bool consumed = XP_FALSE; XP_Bool consumed = XP_FALSE;
// XWStreamPos pos = stream_getPos( stream, POS_READ);
CommsConnType typ; /* There should be exactly one type associated with an incoming message */
for ( XP_U32 st = 0; !consumed && addr_iter( useAddr, &typ, &st ); ) { CommsConnType typ = addr_getType( useAddr );
XP_LOGF( "%s(typ=%s)", __func__, ConnType2Str(typ) ); XP_LOGF( "%s(typ=%s)", __func__, ConnType2Str(typ) );
// stream_setPos( stream, POS_READ, pos ); switch ( typ ) {
switch ( typ ) {
#ifdef XWFEATURE_RELAY #ifdef XWFEATURE_RELAY
/* relayPreProcess returns true if consumes the message. May just eat the /* relayPreProcess returns true if consumes the message. May just eat the
header and leave a regular message to be processed below. */ header and leave a regular message to be processed below. */
case COMMS_CONN_RELAY: case COMMS_CONN_RELAY:
consumed = relayPreProcess( comms, stream, senderID ); consumed = relayPreProcess( comms, stream, senderID );
if ( !consumed ) { if ( !consumed ) {
*usingRelay = XP_TRUE; *usingRelay = XP_TRUE;
} }
break; break;
#endif #endif
#if defined XWFEATURE_IP_DIRECT #if defined XWFEATURE_IP_DIRECT
case COMMS_CONN_BT: case COMMS_CONN_BT:
case COMMS_CONN_IP_DIRECT: case COMMS_CONN_IP_DIRECT:
consumed = btIpPreProcess( comms, stream ); consumed = btIpPreProcess( comms, stream );
break; break;
#endif #endif
#if defined XWFEATURE_SMS #if defined XWFEATURE_SMS
case COMMS_CONN_SMS: case COMMS_CONN_SMS:
break; /* nothing to grab */ break; /* nothing to grab */
#endif #endif
default: default:
XP_ASSERT(0); XP_ASSERT(0);
break; break;
}
} }
LOG_RETURNF( "%d", consumed ); LOG_RETURNF( "%d", consumed );
return consumed; return consumed;
@ -1788,6 +1780,10 @@ getRecordFor( CommsCtxt* comms, const CommsAddrRec* addr,
/* Use addr if we have it. Otherwise use channelNo if non-0 */ /* Use addr if we have it. Otherwise use channelNo if non-0 */
CNO_FMT( cbuf, channelNo ); CNO_FMT( cbuf, channelNo );
for ( rec = comms->recs; !!rec; rec = rec->next ) { for ( rec = comms->recs; !!rec; rec = rec->next ) {
/* server should have only one rec max -- but relay has bugs right now
that send to the wrong device randomly. */
// XP_ASSERT( comms->isServer || !rec->next );
CNO_FMT( cbuf1, rec->channelNo ); CNO_FMT( cbuf1, rec->channelNo );
XP_LOGF( "%s: comparing rec channel %s with addr channel %s", __func__, XP_LOGF( "%s: comparing rec channel %s with addr channel %s", __func__,
cbuf1, cbuf ); cbuf1, cbuf );
@ -1796,15 +1792,14 @@ getRecordFor( CommsCtxt* comms, const CommsAddrRec* addr,
XP_LOGF( "%s: match based on channels!!!", __func__ ); XP_LOGF( "%s: match based on channels!!!", __func__ );
matched = XP_TRUE; matched = XP_TRUE;
} else { } else {
if ( (rec->channelNo & ~CHANNEL_MASK) == (channelNo & ~CHANNEL_MASK) ) { /* if ( (rec->channelNo & ~CHANNEL_MASK) == (channelNo & ~CHANNEL_MASK) ) { */
// XP_ASSERT(0); /* figure out why this would make sense */ /* XP_ASSERT(0); /\* figure out why this would make sense *\/ */
XP_LOGF( "%s: figure out why this would make sense ", __func__ ); /* XP_LOGF( "%s: figure out why this would make sense ", __func__ ); */
} /* } */
CommsConnType conType = !!addr ? CommsConnType conType = !!addr ?
addr_getType( addr ) : COMMS_CONN_NONE; addr_getType( addr ) : COMMS_CONN_NONE;
switch( conType ) { switch( conType ) {
case COMMS_CONN_RELAY: case COMMS_CONN_RELAY:
XP_ASSERT(0); /* is this being used? */
if ( (addr->u.ip_relay.ipAddr == rec->addr.u.ip_relay.ipAddr) if ( (addr->u.ip_relay.ipAddr == rec->addr.u.ip_relay.ipAddr)
&& (addr->u.ip_relay.port == rec->addr.u.ip_relay.port ) ) { && (addr->u.ip_relay.port == rec->addr.u.ip_relay.port ) ) {
matched = XP_TRUE; matched = XP_TRUE;
@ -1960,7 +1955,8 @@ validateInitialMessage( CommsCtxt* comms,
*/ */
static AddressRecord* static AddressRecord*
validateChannelMessage( CommsCtxt* comms, const CommsAddrRec* addr, validateChannelMessage( CommsCtxt* comms, const CommsAddrRec* addr,
XP_PlayerAddr channelNo, MsgID msgID, MsgID lastMsgRcd ) XP_PlayerAddr channelNo, XWHostID senderID,
MsgID msgID, MsgID lastMsgRcd )
{ {
AddressRecord* rec; AddressRecord* rec;
@ -1969,9 +1965,10 @@ validateChannelMessage( CommsCtxt* comms, const CommsAddrRec* addr,
rec = getRecordFor( comms, NULL, channelNo, XP_FALSE ); rec = getRecordFor( comms, NULL, channelNo, XP_FALSE );
if ( !!rec ) { if ( !!rec ) {
removeFromQueue( comms, channelNo, lastMsgRcd ); removeFromQueue( comms, channelNo, lastMsgRcd );
if ( msgID == rec->lastMsgRcd + 1 ) {
augmentChannelAddr( comms, rec, addr, 0 ); augmentChannelAddr( comms, rec, addr, senderID );
} else {
if ( msgID != rec->lastMsgRcd + 1 ) {
XP_LOGF( "%s: expected %d, got %d", __func__, XP_LOGF( "%s: expected %d, got %d", __func__,
rec->lastMsgRcd + 1, msgID ); rec->lastMsgRcd + 1, msgID );
rec = NULL; rec = NULL;
@ -1989,8 +1986,10 @@ XP_Bool
comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream, comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
const CommsAddrRec* retAddr ) const CommsAddrRec* retAddr )
{ {
XP_ASSERT( !!retAddr ); /* for now */
XP_Bool messageValid = XP_FALSE; XP_Bool messageValid = XP_FALSE;
LOG_FUNC(); XP_LOGF( "%s(retAddr.typ = %s)", __func__,
ConnType2Str(addr_getType( retAddr ) ) );
if ( comms_getAddrDisabled( comms, addr_getType(retAddr), XP_FALSE ) ) { if ( comms_getAddrDisabled( comms, addr_getType(retAddr), XP_FALSE ) ) {
XP_LOGF( "%s: dropping message because %s disabled", __func__, XP_LOGF( "%s: dropping message because %s disabled", __func__,
ConnType2Str( addr_getType( retAddr ) ) ); ConnType2Str( addr_getType( retAddr ) ) );
@ -2044,8 +2043,8 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
rec = validateInitialMessage( comms, payloadSize > 0, retAddr, rec = validateInitialMessage( comms, payloadSize > 0, retAddr,
senderID, &channelNo ); senderID, &channelNo );
} else if ( comms->connID == connID ) { } else if ( comms->connID == connID ) {
rec = validateChannelMessage( comms, retAddr, channelNo, msgID, rec = validateChannelMessage( comms, retAddr, channelNo, senderID,
lastMsgRcd ); msgID, lastMsgRcd );
} else { } else {
XP_LOGF( "%s: unexpected connID; dropping message", __func__ ); XP_LOGF( "%s: unexpected connID; dropping message", __func__ );
} }
@ -2418,6 +2417,12 @@ augmentChannelAddr( CommsCtxt* comms, AddressRecord* rec, const CommsAddrRec* ad
if ( !!addr ) { if ( !!addr ) {
CommsConnType typ; CommsConnType typ;
for ( XP_U32 st = 0; addr_iter( addr, &typ, &st ); ) { for ( XP_U32 st = 0; addr_iter( addr, &typ, &st ); ) {
if ( ! addr_hasType( &rec->addr, typ ) ) {
CNO_FMT( cbuf, rec->channelNo );
XP_LOGF( "%s: adding type %s to rec %p with %s", __func__,
ConnType2Str(typ), rec, cbuf );
}
addr_addType( &rec->addr, typ ); addr_addType( &rec->addr, typ );
const void* src = NULL; const void* src = NULL;
@ -2450,7 +2455,11 @@ augmentChannelAddr( CommsCtxt* comms, AddressRecord* rec, const CommsAddrRec* ad
break; break;
} }
if ( !!dest ) { if ( !!dest ) {
XP_MEMCPY( dest, src, siz ); if ( 0 != XP_MEMCMP( dest, src, siz ) ) {
XP_LOGF( "%s: actually changing addr info for typ %s",
__func__, ConnType2Str(typ) );
XP_MEMCPY( dest, src, siz );
}
} }
} }
} }
@ -2563,15 +2572,17 @@ getDestID( CommsCtxt* comms, XP_PlayerAddr channelNo )
if ( (channelNo & CHANNEL_MASK) == CHANNEL_NONE ) { if ( (channelNo & CHANNEL_MASK) == CHANNEL_NONE ) {
id = HOST_ID_SERVER; id = HOST_ID_SERVER;
} else { } else {
channelNo = channelNo & ~CHANNEL_MASK;
for ( AddressRecord* recs = comms->recs; !!recs; recs = recs->next ) { for ( AddressRecord* recs = comms->recs; !!recs; recs = recs->next ) {
CNO_FMT( cbuf, recs->channelNo ); CNO_FMT( cbuf, recs->channelNo );
XP_LOGF( "%s: rec %p has %s, hostID %d", __func__, recs, XP_LOGF( "%s: rec %p has %s, hostID %d", __func__, recs,
cbuf, recs->rr.hostID ); cbuf, recs->rr.hostID );
if ( recs->channelNo == channelNo if ( (recs->channelNo & ~CHANNEL_MASK) == channelNo
&& addr_hasType( &recs->addr, COMMS_CONN_RELAY ) ) { && addr_hasType( &recs->addr, COMMS_CONN_RELAY ) ) {
id = recs->rr.hostID; id = recs->rr.hostID;
} else { } else {
XP_LOGF( "%s: rejected record %p", __func__, recs ); XP_LOGF( "%s: rejected record %p", __func__, recs );
logAddr( comms, &recs->addr, __func__ );
} }
} }
} }