mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
Make cooperation in a heartbeat scheme a compile-time option. This is
meant to allow comms to take over heartbeats.
This commit is contained in:
parent
f752eace94
commit
a91056bed2
8 changed files with 40 additions and 11 deletions
|
@ -262,6 +262,7 @@ CookieRef::HasSocket( int socket )
|
||||||
return found;
|
return found;
|
||||||
} /* HasSocket */
|
} /* HasSocket */
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
void
|
void
|
||||||
CookieRef::_HandleHeartbeat( HostID id, int socket )
|
CookieRef::_HandleHeartbeat( HostID id, int socket )
|
||||||
{
|
{
|
||||||
|
@ -286,6 +287,7 @@ CookieRef::_CheckHeartbeats( time_t now )
|
||||||
|
|
||||||
handleEvents();
|
handleEvents();
|
||||||
} /* CheckHeartbeats */
|
} /* CheckHeartbeats */
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::_Forward( HostID src, HostID dest, unsigned char* buf, int buflen )
|
CookieRef::_Forward( HostID src, HostID dest, unsigned char* buf, int buflen )
|
||||||
|
@ -327,6 +329,7 @@ CookieRef::pushReconnectEvent( int socket, HostID srcID,
|
||||||
m_eventQueue.push_back( evt );
|
m_eventQueue.push_back( evt );
|
||||||
} /* pushReconnectEvent */
|
} /* pushReconnectEvent */
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
void
|
void
|
||||||
CookieRef::pushHeartbeatEvent( HostID id, int socket )
|
CookieRef::pushHeartbeatEvent( HostID id, int socket )
|
||||||
{
|
{
|
||||||
|
@ -345,6 +348,7 @@ CookieRef::pushHeartFailedEvent( int socket )
|
||||||
evt.u.heart.socket = socket;
|
evt.u.heart.socket = socket;
|
||||||
m_eventQueue.push_back( evt );
|
m_eventQueue.push_back( evt );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::pushForwardEvent( HostID src, HostID dest,
|
CookieRef::pushForwardEvent( HostID src, HostID dest,
|
||||||
|
@ -649,7 +653,6 @@ CookieRef::forward( const CRefEvent* evt )
|
||||||
{
|
{
|
||||||
unsigned char* buf = evt->u.fwd.buf;
|
unsigned char* buf = evt->u.fwd.buf;
|
||||||
int buflen = evt->u.fwd.buflen;
|
int buflen = evt->u.fwd.buflen;
|
||||||
HostID src = evt->u.fwd.src;
|
|
||||||
HostID dest = evt->u.fwd.dest;
|
HostID dest = evt->u.fwd.dest;
|
||||||
|
|
||||||
int destSocket = SocketForHost( dest );
|
int destSocket = SocketForHost( dest );
|
||||||
|
@ -660,7 +663,10 @@ CookieRef::forward( const CRefEvent* evt )
|
||||||
send_with_length( destSocket, buf, buflen );
|
send_with_length( destSocket, buf, buflen );
|
||||||
|
|
||||||
/* also note that we've heard from src recently */
|
/* also note that we've heard from src recently */
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
|
HostID src = evt->u.fwd.src;
|
||||||
pushHeartbeatEvent( src, SocketForHost(src) );
|
pushHeartbeatEvent( src, SocketForHost(src) );
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* We're not really connected yet! */
|
/* We're not really connected yet! */
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,12 +392,14 @@ CRefMgr::UnlockCref( CookieRef* cref )
|
||||||
pthread_mutex_unlock( cref_mutex );
|
pthread_mutex_unlock( cref_mutex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
/* static */ void
|
/* static */ void
|
||||||
CRefMgr::heartbeatProc( void* closure )
|
CRefMgr::heartbeatProc( void* closure )
|
||||||
{
|
{
|
||||||
CRefMgr* self = (CRefMgr*)closure;
|
CRefMgr* self = (CRefMgr*)closure;
|
||||||
self->checkHeartbeats( now() );
|
self->checkHeartbeats( now() );
|
||||||
} /* heartbeatProc */
|
} /* heartbeatProc */
|
||||||
|
#endif
|
||||||
|
|
||||||
CookieRef*
|
CookieRef*
|
||||||
CRefMgr::AddNew( const char* cookie, const char* connName, CookieID id )
|
CRefMgr::AddNew( const char* cookie, const char* connName, CookieID id )
|
||||||
|
@ -412,12 +414,14 @@ CRefMgr::AddNew( const char* cookie, const char* connName, CookieID id )
|
||||||
logf( XW_LOGINFO, "paired cookie %s/connName %s with id %d",
|
logf( XW_LOGINFO, "paired cookie %s/connName %s with id %d",
|
||||||
(cookie?cookie:"NULL"), connName, ref->GetCookieID() );
|
(cookie?cookie:"NULL"), connName, ref->GetCookieID() );
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
if ( m_cookieMap.size() == 1 ) {
|
if ( m_cookieMap.size() == 1 ) {
|
||||||
RelayConfigs* cfg = RelayConfigs::GetConfigs();
|
RelayConfigs* cfg = RelayConfigs::GetConfigs();
|
||||||
short heartbeat = cfg->GetHeartbeatInterval();
|
short heartbeat = cfg->GetHeartbeatInterval();
|
||||||
TimerMgr::GetTimerMgr()->SetTimer( heartbeat, heartbeatProc, this,
|
TimerMgr::GetTimerMgr()->SetTimer( heartbeat, heartbeatProc, this,
|
||||||
heartbeat );
|
heartbeat );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ref;
|
return ref;
|
||||||
} /* AddNew */
|
} /* AddNew */
|
||||||
|
@ -452,9 +456,11 @@ CRefMgr::Delete( CookieRef* cref )
|
||||||
|
|
||||||
delete cref;
|
delete cref;
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
if ( m_cookieMap.size() == 0 ) {
|
if ( m_cookieMap.size() == 0 ) {
|
||||||
TimerMgr::GetTimerMgr()->ClearTimer( heartbeatProc, this );
|
TimerMgr::GetTimerMgr()->ClearTimer( heartbeatProc, this );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
logf( XW_LOGINFO, "CRefMgr::Delete done" );
|
logf( XW_LOGINFO, "CRefMgr::Delete done" );
|
||||||
}
|
}
|
||||||
|
@ -493,6 +499,7 @@ CRefMgr::getCookieRef_impl( CookieID cookieID )
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
void
|
void
|
||||||
CRefMgr::checkHeartbeats( time_t now )
|
CRefMgr::checkHeartbeats( time_t now )
|
||||||
{
|
{
|
||||||
|
@ -513,6 +520,7 @@ CRefMgr::checkHeartbeats( time_t now )
|
||||||
scr.CheckHeartbeats( now );
|
scr.CheckHeartbeats( now );
|
||||||
}
|
}
|
||||||
} /* checkHeartbeats */
|
} /* checkHeartbeats */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* static */ CookieMapIterator
|
/* static */ CookieMapIterator
|
||||||
CRefMgr::GetCookieIterator()
|
CRefMgr::GetCookieIterator()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2005 by Eric House (xwords@eehouse.org). All rights reserved.
|
* Copyright 2005-2007 by Eric House (xwords@eehouse.org). All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -165,6 +165,8 @@ class SafeCref {
|
||||||
m_cref->_Remove( socket );
|
m_cref->_Remove( socket );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
int HandleHeartbeat( HostID id, int socket ) {
|
int HandleHeartbeat( HostID id, int socket ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_HandleHeartbeat( id, socket );
|
m_cref->_HandleHeartbeat( id, socket );
|
||||||
|
@ -178,6 +180,8 @@ class SafeCref {
|
||||||
m_cref->_CheckHeartbeats( now );
|
m_cref->_CheckHeartbeats( now );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void PrintCookieInfo( string& out ) {
|
void PrintCookieInfo( string& out ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_PrintCookieInfo( out );
|
m_cref->_PrintCookieInfo( out );
|
||||||
|
|
|
@ -97,6 +97,7 @@ StateTable g_stateTable[] = {
|
||||||
{ XWS_ALLCONNECTED, XWE_REMOVESOCKET, XWA_REMOVESOCKET, XWS_MISSING },
|
{ XWS_ALLCONNECTED, XWE_REMOVESOCKET, XWA_REMOVESOCKET, XWS_MISSING },
|
||||||
{ XWS_MISSING, XWE_REMOVESOCKET, XWA_REMOVESOCKET, XWS_MISSING },
|
{ XWS_MISSING, XWE_REMOVESOCKET, XWA_REMOVESOCKET, XWS_MISSING },
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
{ XWS_ALLCONNECTED, XWE_HEARTFAILED, XWA_HEARTDISCONN, XWS_MISSING },
|
{ XWS_ALLCONNECTED, XWE_HEARTFAILED, XWA_HEARTDISCONN, XWS_MISSING },
|
||||||
{ XWS_CONNECTING, XWE_HEARTFAILED, XWA_HEARTDISCONN, XWS_CONNECTING },
|
{ XWS_CONNECTING, XWE_HEARTFAILED, XWA_HEARTDISCONN, XWS_CONNECTING },
|
||||||
{ XWS_MISSING, XWE_HEARTFAILED, XWA_HEARTDISCONN, XWS_MISSING },
|
{ XWS_MISSING, XWE_HEARTFAILED, XWA_HEARTDISCONN, XWS_MISSING },
|
||||||
|
@ -105,6 +106,7 @@ StateTable g_stateTable[] = {
|
||||||
{ XWS_CONNECTING, XWE_HEARTRCVD, XWA_NOTEHEART, XWS_CONNECTING },
|
{ XWS_CONNECTING, XWE_HEARTRCVD, XWA_NOTEHEART, XWS_CONNECTING },
|
||||||
{ XWS_ALLCONNECTED, XWE_HEARTRCVD, XWA_NOTEHEART, XWS_ALLCONNECTED },
|
{ XWS_ALLCONNECTED, XWE_HEARTRCVD, XWA_NOTEHEART, XWS_ALLCONNECTED },
|
||||||
{ XWS_MISSING, XWE_HEARTRCVD, XWA_NOTEHEART, XWS_MISSING },
|
{ XWS_MISSING, XWE_HEARTRCVD, XWA_NOTEHEART, XWS_MISSING },
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Connect timer */
|
/* Connect timer */
|
||||||
{ XWS_CONNECTING, XWE_CONNTIMER, XWA_TIMERDISCONN, XWS_DEAD },
|
{ XWS_CONNECTING, XWE_CONNTIMER, XWA_TIMERDISCONN, XWS_DEAD },
|
||||||
|
@ -187,9 +189,11 @@ eventString( XW_RELAY_EVENT evt )
|
||||||
CASESTR(XWE_RECONNECTMSG);
|
CASESTR(XWE_RECONNECTMSG);
|
||||||
CASESTR(XWE_DISCONNMSG);
|
CASESTR(XWE_DISCONNMSG);
|
||||||
CASESTR(XWE_FORWARDMSG);
|
CASESTR(XWE_FORWARDMSG);
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
CASESTR(XWE_HEARTRCVD);
|
CASESTR(XWE_HEARTRCVD);
|
||||||
CASESTR(XWE_CONNTIMER);
|
|
||||||
CASESTR(XWE_HEARTFAILED);
|
CASESTR(XWE_HEARTFAILED);
|
||||||
|
#endif
|
||||||
|
CASESTR(XWE_CONNTIMER);
|
||||||
CASESTR(XWE_ANY);
|
CASESTR(XWE_ANY);
|
||||||
CASESTR(XWE_REMOVESOCKET);
|
CASESTR(XWE_REMOVESOCKET);
|
||||||
CASESTR(XWE_NOMORESOCKETS);
|
CASESTR(XWE_NOMORESOCKETS);
|
||||||
|
|
|
@ -96,12 +96,12 @@ typedef enum {
|
||||||
|
|
||||||
,XWE_FORWARDMSG /* A message needs forwarding */
|
,XWE_FORWARDMSG /* A message needs forwarding */
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
,XWE_HEARTRCVD /* A heartbeat message arrived */
|
,XWE_HEARTRCVD /* A heartbeat message arrived */
|
||||||
|
,XWE_HEARTFAILED
|
||||||
|
#endif
|
||||||
,XWE_CONNTIMER /* timer for did we get all players hooked
|
,XWE_CONNTIMER /* timer for did we get all players hooked
|
||||||
up */
|
up */
|
||||||
,XWE_HEARTFAILED
|
|
||||||
|
|
||||||
,XWE_REMOVESOCKET /* Need to remove socket from this cref */
|
,XWE_REMOVESOCKET /* Need to remove socket from this cref */
|
||||||
|
|
||||||
,XWE_NOTIFYDISCON /* Send a discon */
|
,XWE_NOTIFYDISCON /* Send a discon */
|
||||||
|
|
|
@ -30,4 +30,4 @@ IDFILE=/home/eehouse/xwrelay_id.txt
|
||||||
|
|
||||||
# Initial level of logging. See xwrelay_priv.h for values. Currently
|
# Initial level of logging. See xwrelay_priv.h for values. Currently
|
||||||
# 0 means errors only, 1 info, 2 verbose and 3 very verbose.
|
# 0 means errors only, 1 info, 2 verbose and 3 very verbose.
|
||||||
LOGLEVEL=0
|
LOGLEVEL=2
|
||||||
|
|
|
@ -137,6 +137,7 @@ getNetByte( unsigned char** bufpp, unsigned char* end, unsigned char* out )
|
||||||
return ok;
|
return ok;
|
||||||
} /* getNetByte */
|
} /* getNetByte */
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
static int
|
static int
|
||||||
processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
|
@ -158,6 +159,7 @@ processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
} /* processHeartbeat */
|
} /* processHeartbeat */
|
||||||
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
readStr( unsigned char** bufp, const unsigned char* end,
|
readStr( unsigned char** bufp, const unsigned char* end,
|
||||||
|
@ -370,10 +372,12 @@ processMessage( unsigned char* buf, int bufLen, int socket )
|
||||||
case XWRELAY_GAME_DISCONNECT:
|
case XWRELAY_GAME_DISCONNECT:
|
||||||
success = processDisconnect( buf+1, bufLen-1, socket );
|
success = processDisconnect( buf+1, bufLen-1, socket );
|
||||||
break;
|
break;
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
case XWRELAY_HEARTBEAT:
|
case XWRELAY_HEARTBEAT:
|
||||||
logf( XW_LOGINFO, "processMessage got XWRELAY_HEARTBEAT" );
|
logf( XW_LOGINFO, "processMessage got XWRELAY_HEARTBEAT" );
|
||||||
success = processHeartbeat( buf + 1, bufLen - 1, socket );
|
success = processHeartbeat( buf + 1, bufLen - 1, socket );
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case XWRELAY_MSG_TORELAY:
|
case XWRELAY_MSG_TORELAY:
|
||||||
logf( XW_LOGINFO, "processMessage got XWRELAY_MSG_TORELAY" );
|
logf( XW_LOGINFO, "processMessage got XWRELAY_MSG_TORELAY" );
|
||||||
success = forwardMessage( buf, bufLen, socket );
|
success = forwardMessage( buf, bufLen, socket );
|
||||||
|
|
|
@ -74,9 +74,12 @@ enum { XWRELAY_NONE /* 0 is an illegal value */
|
||||||
, XWRELAY_CONNECTDENIED
|
, XWRELAY_CONNECTDENIED
|
||||||
/* The relay says go away. Format: reason code: 1 */
|
/* The relay says go away. Format: reason code: 1 */
|
||||||
|
|
||||||
|
#ifdef RELAY_HEARTBEAT
|
||||||
, XWRELAY_HEARTBEAT
|
, XWRELAY_HEARTBEAT
|
||||||
/* Sent in either direction. Format: cookieID: 2; srcID: 1 */
|
/* Sent in either direction. Format: cookieID: 2; srcID: 1 */
|
||||||
|
#else
|
||||||
|
, _XWRELAY_HEARTBEAT /* don't use this */
|
||||||
|
#endif
|
||||||
, XWRELAY_MSG_FROMRELAY
|
, XWRELAY_MSG_FROMRELAY
|
||||||
/* Sent from relay to device. Format: cookieID: 2; src_hostID: 1;
|
/* Sent from relay to device. Format: cookieID: 2; src_hostID: 1;
|
||||||
dest_hostID: 1; data <len-headerLen> */
|
dest_hostID: 1; data <len-headerLen> */
|
||||||
|
|
Loading…
Add table
Reference in a new issue