wire disabling checkboxes into comms. They work -- and show that

multi-addressing needs debugging still.
This commit is contained in:
Eric House 2014-11-06 06:35:28 -08:00
parent b1de8663d6
commit 540d3e9622
4 changed files with 159 additions and 104 deletions

View file

@ -150,6 +150,10 @@ struct CommsCtxt {
} rr; } rr;
XP_Bool isServer; XP_Bool isServer;
#ifdef DEBUG
XP_Bool disableds[COMMS_CONN_NTYPES][2];
#endif
MPSLOT MPSLOT
}; };
@ -1283,55 +1287,61 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem )
XP_S16 nSent = -1; XP_S16 nSent = -1;
XP_LOGF( "%s: sending msg with sum %s using typ %s", __func__, elem->checksum, XP_LOGF( "%s: sending msg with sum %s using typ %s", __func__, elem->checksum,
ConnType2Str(typ) ); ConnType2Str(typ) );
switch ( typ ) {
if ( comms_getAddrDisabled( comms, typ, XP_TRUE ) ) {
XP_LOGF( "%s: dropping message because %s disabled", __func__,
ConnType2Str( typ ) );
} else {
switch ( typ ) {
#ifdef XWFEATURE_RELAY #ifdef XWFEATURE_RELAY
case COMMS_CONN_RELAY: { case COMMS_CONN_RELAY: {
XWHostID destID = getDestID( comms, channelNo ); XWHostID destID = getDestID( comms, channelNo );
if ( HOST_ID_NONE == destID ) { if ( HOST_ID_NONE == destID ) {
XP_LOGF( "%s: skipping message via relay: no destID yet", __func__ ); XP_LOGF( "%s: skipping message via relay: no destID yet", __func__ );
} else if ( haveRelayID( comms ) && sendNoConn( comms, elem, destID ) ) { } else if ( haveRelayID( comms ) && sendNoConn( comms, elem, destID ) ) {
/* do nothing */ /* do nothing */
nSent = elem->len;
} else if ( comms->rr.relayState >= COMMS_RELAYSTATE_CONNECTED ) {
if ( send_via_relay( comms, XWRELAY_MSG_TORELAY, destID,
elem->msg, elem->len ) ){
nSent = elem->len; nSent = elem->len;
} else if ( comms->rr.relayState >= COMMS_RELAYSTATE_CONNECTED ) {
if ( send_via_relay( comms, XWRELAY_MSG_TORELAY, destID,
elem->msg, elem->len ) ){
nSent = elem->len;
}
} else {
XP_LOGF( "%s: skipping message: not connected", __func__ );
} }
} else { break;
XP_LOGF( "%s: skipping message: not connected", __func__ );
} }
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:
nSent = send_via_ip( comms, BTIPMSG_DATA, channelNo, nSent = send_via_ip( comms, BTIPMSG_DATA, channelNo,
elem->msg, elem->len ); elem->msg, elem->len );
#ifdef COMMS_HEARTBEAT #ifdef COMMS_HEARTBEAT
setHeartbeatTimer( comms ); setHeartbeatTimer( comms );
#endif #endif
break; break;
#endif #endif
default: { default: {
CommsAddrRec addr; CommsAddrRec addr;
const CommsAddrRec* addrP; const CommsAddrRec* addrP;
(void)channelToAddress( comms, channelNo, &addrP ); (void)channelToAddress( comms, channelNo, &addrP );
if ( NULL == addrP ) { if ( NULL == addrP ) {
XP_LOGF( "%s: no addr for channel so using comms'", __func__ ); XP_LOGF( "%s: no addr for channel so using comms'", __func__ );
comms_getAddr( comms, &addr ); comms_getAddr( comms, &addr );
} else { } else {
addr = *addrP; addr = *addrP;
}
XP_U32 gameid = gameID( comms );
XP_ASSERT( !!comms->procs.send );
nSent = (*comms->procs.send)( elem->msg, elem->len, &addr, typ,
gameid, comms->procs.closure );
break;
} }
} /* switch */
XP_U32 gameid = gameID( comms );
XP_ASSERT( !!comms->procs.send );
nSent = (*comms->procs.send)( elem->msg, elem->len, &addr, typ,
gameid, comms->procs.closure );
break;
} }
} /* switch */
XP_LOGF( "%s: sent %d bytes using typ %s", __func__, nSent, XP_LOGF( "%s: sent %d bytes using typ %s", __func__, nSent,
ConnType2Str(typ) ); ConnType2Str(typ) );
if ( nSent > result ) { if ( nSent > result ) {
@ -1951,83 +1961,88 @@ XP_Bool
comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream, comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
const CommsAddrRec* retAddr ) const CommsAddrRec* retAddr )
{ {
LOG_FUNC();
XP_Bool messageValid = XP_FALSE; XP_Bool messageValid = XP_FALSE;
XWHostID senderID = 0; /* unset; default for non-relay cases */ LOG_FUNC();
XP_Bool usingRelay = XP_FALSE; if ( comms_getAddrDisabled( comms, addr_getType(retAddr), XP_FALSE ) ) {
XP_LOGF( "%s: dropping message because %s disabled", __func__,
ConnType2Str( addr_getType( retAddr ) ) );
} else {
XWHostID senderID = 0; /* unset; default for non-relay cases */
XP_Bool usingRelay = XP_FALSE;
XP_ASSERT( retAddr == NULL || XP_ASSERT( retAddr == NULL ||
(0 != (comms->addr._conTypes & retAddr->_conTypes)) ); (0 != (comms->addr._conTypes & retAddr->_conTypes)) );
#ifdef COMMS_CHECKSUM #ifdef COMMS_CHECKSUM
XP_U16 initialLen = stream_getSize( stream ); XP_U16 initialLen = stream_getSize( stream );
#endif #endif
const CommsAddrRec* useAddr = !!retAddr ? retAddr : &comms->addr; const CommsAddrRec* useAddr = !!retAddr ? retAddr : &comms->addr;
if ( !preProcess( comms, useAddr, stream, &usingRelay, &senderID ) ) { if ( !preProcess( comms, useAddr, stream, &usingRelay, &senderID ) ) {
XP_U32 connID; XP_U32 connID;
XP_PlayerAddr channelNo; XP_PlayerAddr channelNo;
MsgID msgID; MsgID msgID;
MsgID lastMsgRcd; MsgID lastMsgRcd;
#ifdef COMMS_CHECKSUM #ifdef COMMS_CHECKSUM
{ {
XP_U16 len = stream_getSize( stream ); XP_U16 len = stream_getSize( stream );
// stream_getPtr pts at base, but sum excludes relay header // stream_getPtr pts at base, but sum excludes relay header
const XP_U8* ptr = initialLen - len + stream_getPtr( stream ); const XP_U8* ptr = initialLen - len + stream_getPtr( stream );
XP_UCHAR* sum = util_md5sum( comms->util, ptr, len ); XP_UCHAR* sum = util_md5sum( comms->util, ptr, len );
XP_LOGF( "%s: got message of len %d with sum %s", __func__, len, sum ); XP_LOGF( "%s: got message of len %d with sum %s", __func__, len, sum );
XP_FREE( comms->mpool, sum ); XP_FREE( comms->mpool, sum );
} }
#endif #endif
/* reject too-small message */ /* reject too-small message */
if ( stream_getSize( stream ) >= if ( stream_getSize( stream ) >=
(sizeof(connID) + sizeof(channelNo) (sizeof(connID) + sizeof(channelNo)
+ sizeof(msgID) + sizeof(lastMsgRcd)) ) { + sizeof(msgID) + sizeof(lastMsgRcd)) ) {
XP_U16 payloadSize; XP_U16 payloadSize;
AddressRecord* rec = NULL; AddressRecord* rec = NULL;
connID = stream_getU32( stream ); connID = stream_getU32( stream );
XP_LOGF( "%s: read connID (gameID) of %x", __func__, connID ); XP_LOGF( "%s: read connID (gameID) of %x", __func__, connID );
channelNo = stream_getU16( stream ); channelNo = stream_getU16( stream );
msgID = stream_getU32( stream ); msgID = stream_getU32( stream );
lastMsgRcd = stream_getU32( stream ); lastMsgRcd = stream_getU32( stream );
XP_LOGF( "%s: rcd on channelNo %d(%X): msgID=%d,lastMsgRcd=%d ", XP_LOGF( "%s: rcd on channelNo %d(%X): msgID=%d,lastMsgRcd=%d ",
__func__, channelNo & CHANNEL_MASK, channelNo, __func__, channelNo & CHANNEL_MASK, channelNo,
msgID, lastMsgRcd ); msgID, lastMsgRcd );
payloadSize = stream_getSize( stream ); /* anything left? */ payloadSize = stream_getSize( stream ); /* anything left? */
if ( connID == CONN_ID_NONE ) { if ( connID == CONN_ID_NONE ) {
/* special case: initial message from client or server */ /* special case: initial message from client or server */
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, msgID,
lastMsgRcd ); lastMsgRcd );
} else {
XP_LOGF( "%s: unexpected connID; dropping message", __func__ );
}
messageValid = (NULL != rec)
&& (0 == rec->lastMsgRcd || rec->lastMsgRcd <= msgID);
if ( messageValid ) {
XP_LOGF( "%s: got channelNo=%d;msgID=%d;len=%d", __func__,
channelNo & CHANNEL_MASK, msgID, payloadSize );
rec->lastMsgRcd = msgID;
comms->lastSaveToken = 0; /* lastMsgRcd no longer valid */
stream_setAddress( stream, channelNo );
messageValid = payloadSize > 0;
resetBackoff( comms );
}
} else { } else {
XP_LOGF( "%s: unexpected connID; dropping message", __func__ ); XP_LOGF( "%s: message too small", __func__ );
} }
messageValid = (NULL != rec)
&& (0 == rec->lastMsgRcd || rec->lastMsgRcd <= msgID);
if ( messageValid ) {
XP_LOGF( "%s: got channelNo=%d;msgID=%d;len=%d", __func__,
channelNo & CHANNEL_MASK, msgID, payloadSize );
rec->lastMsgRcd = msgID;
comms->lastSaveToken = 0; /* lastMsgRcd no longer valid */
stream_setAddress( stream, channelNo );
messageValid = payloadSize > 0;
resetBackoff( comms );
}
} else {
XP_LOGF( "%s: message too small", __func__ );
} }
/* Call after we've had a chance to create rec for addr */
noteHBReceived( comms/* , addr */ );
} }
/* Call after we've had a chance to create rec for addr */
noteHBReceived( comms/* , addr */ );
LOG_RETURNF( "%s", messageValid?"valid":"invalid" ); LOG_RETURNF( "%s", messageValid?"valid":"invalid" );
return messageValid; return messageValid;
} /* comms_checkIncomingStream */ } /* comms_checkIncomingStream */
@ -2253,6 +2268,25 @@ comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream )
stream_catString( stream, buf ); stream_catString( stream, buf );
} }
} /* comms_getStats */ } /* comms_getStats */
void
comms_setAddrDisabled( CommsCtxt* comms, CommsConnType typ,
XP_Bool send, XP_Bool disabled )
{
XP_ASSERT( !!comms );
XP_LOGF( "%s(typ=%s, send=%d, disabled=%d)", __func__,
ConnType2Str(typ), send, disabled );
comms->disableds[typ][send?0:1] = disabled;
}
XP_Bool
comms_getAddrDisabled( const CommsCtxt* comms, CommsConnType typ,
XP_Bool send )
{
XP_ASSERT( !!comms );
return comms->disableds[typ][send?0:1];
}
#endif #endif
static AddressRecord* static AddressRecord*

View file

@ -241,6 +241,13 @@ void comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream );
const char* ConnType2Str( CommsConnType typ ); const char* ConnType2Str( CommsConnType typ );
const char* CommsRelayState2Str( CommsRelayState state ); const char* CommsRelayState2Str( CommsRelayState state );
const char* XWREASON2Str( XWREASON reason ); const char* XWREASON2Str( XWREASON reason );
void comms_setAddrDisabled( CommsCtxt* comms, CommsConnType typ,
XP_Bool send, XP_Bool enabled );
XP_Bool comms_getAddrDisabled( const CommsCtxt* comms, CommsConnType typ,
XP_Bool send );
# else
# define comms_getAddrDisabled( comms, typ, send ) XP_FALSE
# endif # endif
EXTERN_C_END EXTERN_C_END

View file

@ -450,8 +450,12 @@ setTransportProcs( TransportProcs* procs, GtkGameGlobals* globals )
static void static void
drop_msg_toggle( GtkWidget* toggle, void* data ) drop_msg_toggle( GtkWidget* toggle, void* data )
{ {
XP_Bool* bp = (XP_Bool*)data; XP_Bool disabled = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(toggle) );
*bp = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(toggle) ); long asInt = (long)data;
XP_Bool send = 0 != (asInt & 1);
asInt &= ~1;
DropTypeData* datum = (DropTypeData*)asInt;
comms_setAddrDisabled( datum->comms, datum->typ, send, disabled );
} /* drop_msg_toggle */ } /* drop_msg_toggle */
static void static void
@ -463,6 +467,10 @@ addDropChecks( GtkGameGlobals* globals )
comms_getAddr( comms, &addr ); comms_getAddr( comms, &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 ); ) {
DropTypeData* datum = &globals->dropData[typ];
datum->typ = typ;
datum->comms = comms;
GtkWidget* hbox = gtk_hbox_new( FALSE, 0 ); GtkWidget* hbox = gtk_hbox_new( FALSE, 0 );
gchar buf[32]; gchar buf[32];
snprintf( buf, sizeof(buf), "Drop %s messages", snprintf( buf, sizeof(buf), "Drop %s messages",
@ -473,13 +481,13 @@ addDropChecks( GtkGameGlobals* globals )
widget = gtk_check_button_new_with_label( "Incoming" ); widget = gtk_check_button_new_with_label( "Incoming" );
g_signal_connect( GTK_OBJECT(widget), "toggled", G_CALLBACK(drop_msg_toggle), g_signal_connect( GTK_OBJECT(widget), "toggled", G_CALLBACK(drop_msg_toggle),
&globals->dropMsgs[typ][0] ); datum );
gtk_box_pack_start( GTK_BOX(hbox), widget, FALSE, TRUE, 0); gtk_box_pack_start( GTK_BOX(hbox), widget, FALSE, TRUE, 0);
gtk_widget_show( widget ); gtk_widget_show( widget );
widget = gtk_check_button_new_with_label( "Outgoing" ); widget = gtk_check_button_new_with_label( "Outgoing" );
g_signal_connect( GTK_OBJECT(widget), "toggled", G_CALLBACK(drop_msg_toggle), g_signal_connect( GTK_OBJECT(widget), "toggled", G_CALLBACK(drop_msg_toggle),
&globals->dropMsgs[typ][1] ); (void*)(((long)datum) | 1) );
gtk_box_pack_start( GTK_BOX(hbox), widget, FALSE, TRUE, 0); gtk_box_pack_start( GTK_BOX(hbox), widget, FALSE, TRUE, 0);
gtk_widget_show( widget ); gtk_widget_show( widget );
@ -492,7 +500,7 @@ addDropChecks( GtkGameGlobals* globals )
} }
# else # else
# define addDropChecks( globals ) # define addDropChecks( globals )
# endif # endif /* DEBUG */
#endif #endif
static void static void

View file

@ -84,6 +84,11 @@ typedef struct ClientStreamRec {
int sock; int sock;
} ClientStreamRec; } ClientStreamRec;
typedef struct _DropTypeData {
CommsCtxt* comms;
CommsConnType typ;
} DropTypeData;
typedef struct GtkGameGlobals { typedef struct GtkGameGlobals {
CommonGlobals cGlobals; CommonGlobals cGlobals;
CurGameInfo gi; CurGameInfo gi;
@ -127,8 +132,9 @@ typedef struct GtkGameGlobals {
XP_UCHAR stateChar; XP_UCHAR stateChar;
#endif #endif
DropTypeData dropData[COMMS_CONN_NTYPES];
XP_Bool gridOn; XP_Bool gridOn;
XP_Bool dropMsgs[COMMS_CONN_NTYPES][2];
XP_Bool mouseDown; XP_Bool mouseDown;
XP_Bool altKeyDown; XP_Bool altKeyDown;
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV