From c77021231c32119f2262465df069df10e50c6f55 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 30 Jun 2013 08:33:29 -0700 Subject: [PATCH] print checksums of sent and received messages --- xwords4/common/comms.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index b0578dbda..729cabe31 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -1204,6 +1204,11 @@ sendMsg( CommsCtxt* comms, MsgQueueElem* elem ) channelNo = elem->channelNo; +#ifdef COMMS_CHECKSUM + XP_LOGF( "%s: sending message of len %d with sum %s", __func__, elem->len, + elem->checksum ); +#endif + if ( 0 ) { #ifdef XWFEATURE_RELAY } else if ( conType == COMMS_CONN_RELAY ) { @@ -1809,6 +1814,9 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream, XP_Bool usingRelay = XP_FALSE; XP_ASSERT( retAddr == NULL || comms->addr.conType == retAddr->conType ); +#ifdef COMMS_CHECKSUM + XP_U16 initialLen = stream_getSize( stream ); +#endif if ( !preProcess( comms, stream, &usingRelay, &senderID ) ) { XP_U32 connID; @@ -1816,6 +1824,17 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream, MsgID msgID; MsgID lastMsgRcd; +#ifdef COMMS_CHECKSUM + { + XP_U16 len = stream_getSize( stream ); + // stream_getPtr pts at base, but sum excludes relay header + const XP_U8* ptr = initialLen - len + stream_getPtr( stream ); + gchar* sum = g_compute_checksum_for_data( G_CHECKSUM_MD5, ptr, len ); + XP_LOGF( "%s: got message of len %d with sum %s", __func__, len, sum ); + g_free( sum ); + } +#endif + /* reject too-small message */ if ( stream_getSize( stream ) >= (sizeof(connID) + sizeof(channelNo)