From 13550865ad29550ff969ebe4c7deff05b6e0185f Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 22 Jul 2013 06:05:24 -0700 Subject: [PATCH 1/4] drop packets in queue if they've been there longer than 30 seconds -- which should be a configurable value. --- xwords4/relay/udpqueue.cpp | 16 +++++++++++----- xwords4/relay/udpqueue.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/xwords4/relay/udpqueue.cpp b/xwords4/relay/udpqueue.cpp index 3e9b5d911..7b6ad6b64 100644 --- a/xwords4/relay/udpqueue.cpp +++ b/xwords4/relay/udpqueue.cpp @@ -199,11 +199,17 @@ UdpQueue::thread_main() pthread_mutex_unlock( &m_queueMutex ); utc->noteDequeued(); - logf( XW_LOGINFO, "%s: dispatching packet %d (socket %d); " - "%d seconds old", __func__, - utc->getID(), utc->addr()->socket() ); - (*utc->cb())( utc ); - utc->logStats(); + + time_t age = utc->ageInSeconds(); + if ( 30 > age ) { + logf( XW_LOGINFO, "%s: dispatching packet %d (socket %d); " + "%d seconds old", __func__, utc->getID(), utc->addr()->socket(), + age ); + (*utc->cb())( utc ); + utc->logStats(); + } else { + logf( XW_LOGINFO, "%s: dropping packet %d; it's %d seconds old!", age ); + } delete utc; } return NULL; diff --git a/xwords4/relay/udpqueue.h b/xwords4/relay/udpqueue.h index 16060feda..7e68fb3f8 100644 --- a/xwords4/relay/udpqueue.h +++ b/xwords4/relay/udpqueue.h @@ -55,6 +55,7 @@ public: const AddrInfo* addr() const { return &m_addr; } void noteDequeued() { m_dequed = time( NULL ); } void logStats(); + time_t ageInSeconds() { return time( NULL ) - m_created; } const QueueCallback cb() const { return m_cb; } void setID( int id ) { m_id = id; } int getID( void ) { return m_id; } From 48a2567edfeee0bc51c579670d6f9a4bbc594271 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 22 Jul 2013 06:06:39 -0700 Subject: [PATCH 2/4] log contents of incoming udp packets --- xwords4/relay/xwrelay.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index b879d4cef..b07f3b05e 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -1366,7 +1366,7 @@ ackPacketIf( const UDPHeader* header, const AddrInfo* addr ) { if ( UDPAckTrack::shouldAck( header->cmd ) ) { uint32_t packetID = header->packetID; - logf( XW_LOGINFO, "acking packet %d", packetID ); + logf( XW_LOGINFO, "%s: acking packet %d", __func__, packetID ); packetID = htonl( packetID ); send_via_udp( addr, XWPDEV_ACK, &packetID, sizeof(packetID), NULL ); @@ -1489,8 +1489,15 @@ read_udp_packet( int udpsock ) ssize_t nRead = recvfrom( udpsock, buf, sizeof(buf), 0 /*flags*/, &saddr.u.addr, &fromlen ); - logf( XW_LOGINFO, "%s: recvfrom=>%d", __func__, nRead ); if ( 0 < nRead ) { +#ifdef LOG_UDP_PACKETS + gchar* b64 = g_base64_encode( (unsigned char*)&saddr, sizeof(saddr) ); + logf( XW_LOGINFO, "%s: recvfrom=>%d (saddr='%s')", __func__, nRead, b64 ); + g_free( b64 ); +#else + logf( XW_LOGINFO, "%s: recvfrom=>%d", __func__, nRead ); +#endif + AddrInfo addr( udpsock, &saddr, false ); UdpQueue::get()->handle( &addr, buf, nRead, handle_udp_packet ); } @@ -1989,8 +1996,7 @@ main( int argc, char** argv ) logf( XW_LOGINFO, "%s: accepting connection from %s on socket %d", - __func__, inet_ntoa(saddr.u.addr_in.sin_addr), - newSock ); + __func__, inet_ntoa(saddr.u.addr_in.sin_addr), newSock ); AddrInfo addr( newSock, &saddr, true ); tPool->AddSocket( perGame ? XWThreadPool::STYPE_GAME From 7b18da70dbb99af4687d0f7788c21064e9e14ceb Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 22 Jul 2013 06:11:10 -0700 Subject: [PATCH 3/4] logging tweak --- xwords4/relay/cref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/relay/cref.h b/xwords4/relay/cref.h index c12a5d752..773a2fdeb 100644 --- a/xwords4/relay/cref.h +++ b/xwords4/relay/cref.h @@ -52,7 +52,7 @@ HostRec(HostID hostID, const AddrInfo* addr, int nPlayersH, int seed, bool ackPe , m_lastHeartbeat(uptime()) , m_ackPending(ackPending) { - ::logf( XW_LOGINFO, "created HostRec with id %d", m_hostID); + logf( XW_LOGINFO, "%s created HostRec with id %d", __func__, m_hostID); } HostID m_hostID; AddrInfo m_addr; From a191c6fc2a0e749cf6637e1657ae17093236a76e Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 22 Jul 2013 06:12:06 -0700 Subject: [PATCH 4/4] don't add chats to queue at len 64 rather than 128 --- xwords4/common/comms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index d60ed8419..754068de7 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -1969,7 +1969,7 @@ comms_canChat( const CommsCtxt* const comms ) { XP_Bool canChat = comms_isConnected( comms ) && comms->connID != 0 - && 128 > comms->queueLen; + && 64 > comms->queueLen; LOG_RETURNF( "%d", canChat ); return canChat; }