mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-11-18 10:08:29 +01:00
Make cookieID a 32-bit value instead of 16-bit
This commit is contained in:
parent
db6f6c258d
commit
1ae6c010c9
5 changed files with 42 additions and 25 deletions
|
@ -87,7 +87,7 @@ struct CommsCtxt {
|
|||
XWHostID myHostID; /* 0 if unset, 1 if acting as server, random for
|
||||
client */
|
||||
CommsRelaystate relayState; /* not saved: starts at UNCONNECTED */
|
||||
XP_U16 cookieID; /* standin for cookie; set by relay */
|
||||
XP_U32 cookieID; /* standin for cookie; set by relay */
|
||||
|
||||
/* heartbeat: for periodic pings if relay thinks the network the device is
|
||||
on requires them. Not saved since only valid when connected, and we
|
||||
|
@ -264,7 +264,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
|
|||
comms->connID = stream_getU32( stream );
|
||||
comms->nextChannelNo = stream_getU16( stream );
|
||||
comms->myHostID = stream_getU16( stream );
|
||||
comms->cookieID = stream_getU16( stream );
|
||||
comms->cookieID = stream_getU32( stream );
|
||||
|
||||
#ifdef DEBUG
|
||||
comms->nUniqueBytes = stream_getU16( stream );
|
||||
|
@ -376,7 +376,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream )
|
|||
stream_putU32( stream, comms->connID );
|
||||
stream_putU16( stream, comms->nextChannelNo );
|
||||
stream_putU16( stream, comms->myHostID );
|
||||
stream_putU16( stream, comms->cookieID );
|
||||
stream_putU32( stream, comms->cookieID );
|
||||
|
||||
#ifdef DEBUG
|
||||
stream_putU16( stream, comms->nUniqueBytes );
|
||||
|
@ -662,7 +662,7 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
|
|||
{
|
||||
XP_Bool consumed;
|
||||
XWHostID destID, srcID;
|
||||
XP_U16 cookieID;
|
||||
XP_U32 cookieID;
|
||||
|
||||
if ( comms->addr.conType != COMMS_CONN_RELAY ) {
|
||||
consumed = XP_FALSE; /* nothing for us to do here! */
|
||||
|
@ -673,8 +673,8 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
|
|||
consumed = XP_TRUE;
|
||||
comms->relayState = COMMS_RELAYSTATE_CONNECTED;
|
||||
comms->heartbeat = stream_getU16( stream );
|
||||
comms->cookieID = stream_getU16( stream );
|
||||
XP_LOGF( "got XWRELAY_CONNECTRESP; set cookieID = %d",
|
||||
comms->cookieID = stream_getU32( stream );
|
||||
XP_LOGF( "got XWRELAY_CONNECTRESP; set cookieID = %ld",
|
||||
comms->cookieID );
|
||||
/* We're connected now. Send any pending messages. This may need
|
||||
to be done later since we're inside the platform's socket read
|
||||
|
@ -684,10 +684,10 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
|
|||
setHeartbeatTimer( comms );
|
||||
break;
|
||||
case XWRELAY_MSG_FROMRELAY:
|
||||
cookieID = stream_getU16( stream );
|
||||
cookieID = stream_getU32( stream );
|
||||
srcID = stream_getU16( stream );
|
||||
destID = stream_getU16( stream );
|
||||
XP_LOGF( "cookieID: %d; srcID: %d; destID: %d",
|
||||
XP_LOGF( "cookieID: %ld; srcID: %d; destID: %d",
|
||||
cookieID, srcID, destID );
|
||||
/* If these values don't check out, drop it */
|
||||
consumed = cookieID != comms->cookieID
|
||||
|
@ -970,7 +970,7 @@ send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd, XWHostID destID,
|
|||
stream_putU8( tmpStream, cmd );
|
||||
|
||||
if ( cmd == XWRELAY_MSG_TORELAY ) {
|
||||
stream_putU16( tmpStream, comms->cookieID );
|
||||
stream_putU32( tmpStream, comms->cookieID );
|
||||
stream_putU16( tmpStream, comms->myHostID );
|
||||
stream_putU16( tmpStream, destID );
|
||||
if ( data != NULL && dlen > 0 ) {
|
||||
|
@ -982,14 +982,14 @@ send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd, XWHostID destID,
|
|||
stream_putU8( tmpStream, clen );
|
||||
stream_putBytes( tmpStream, addr.u.ip_relay.cookie, clen );
|
||||
stream_putU16( tmpStream, comms->myHostID );
|
||||
XP_LOGF( "writing cookieID of %d", comms->cookieID );
|
||||
stream_putU16( tmpStream, comms->cookieID );
|
||||
XP_LOGF( "writing cookieID of %ld", comms->cookieID );
|
||||
stream_putU32( tmpStream, comms->cookieID );
|
||||
|
||||
comms->relayState = COMMS_RELAYSTATE_CONNECT_PENDING;
|
||||
} else if ( cmd == XWRELAY_HEARTBEAT ) {
|
||||
/* Add these for grins. Server can assert they match the IP
|
||||
address it expects 'em on. */
|
||||
stream_putU16( tmpStream, comms->cookieID );
|
||||
stream_putU32( tmpStream, comms->cookieID );
|
||||
stream_putU16( tmpStream, comms->myHostID );
|
||||
}
|
||||
|
||||
|
|
|
@ -501,6 +501,15 @@ putNetShort( unsigned char** bufpp, unsigned short s )
|
|||
*bufpp += sizeof(s);
|
||||
}
|
||||
|
||||
static void
|
||||
putNetLong( unsigned char** bufpp, unsigned long s )
|
||||
{
|
||||
s = htonl( s );
|
||||
memcpy( *bufpp, &s, sizeof(s) );
|
||||
*bufpp += sizeof(s);
|
||||
assert( sizeof(s) == 4 ); /* otherwise need to hardcode */
|
||||
}
|
||||
|
||||
void
|
||||
CookieRef::sendResponse( const CRefEvent* evt )
|
||||
{
|
||||
|
@ -514,12 +523,12 @@ CookieRef::sendResponse( const CRefEvent* evt )
|
|||
m_hostSockets.insert( pair<HostID,HostRec>(id,hr) );
|
||||
|
||||
/* Now send the response */
|
||||
unsigned char buf[5];
|
||||
unsigned char buf[7];
|
||||
unsigned char* bufp = buf;
|
||||
|
||||
*bufp++ = XWRELAY_CONNECTRESP;
|
||||
putNetShort( &bufp, GetHeartbeat() );
|
||||
putNetShort( &bufp, GetCookieID() );
|
||||
putNetLong( &bufp, GetCookieID() );
|
||||
|
||||
send_with_length( socket, buf, sizeof(buf) );
|
||||
RecordSent( sizeof(buf), socket );
|
||||
|
@ -603,7 +612,7 @@ CookieRef::PrintCookieInfo( string& out )
|
|||
out += "\n";
|
||||
out += "ID: ";
|
||||
char buf[64];
|
||||
snprintf( buf, sizeof(buf), "%d\n", GetCookieID() );
|
||||
snprintf( buf, sizeof(buf), "%ld\n", GetCookieID() );
|
||||
out += buf;
|
||||
|
||||
snprintf( buf, sizeof(buf), "Bytes sent: %d\n", m_totalSent );
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
#include "xwrelay_priv.h"
|
||||
#include "states.h"
|
||||
|
||||
typedef unsigned short CookieID;
|
||||
|
||||
#ifndef HEARTBEAT
|
||||
# define HEARTBEAT 60
|
||||
#endif
|
||||
|
@ -139,7 +137,7 @@ class CookieMapIterator {
|
|||
};
|
||||
|
||||
CookieRef* get_make_cookieRef( const char* cookie, CookieID connID );
|
||||
CookieRef* get_cookieRef( unsigned short cookieID );
|
||||
CookieRef* get_cookieRef( CookieID cookieID );
|
||||
CookieID CookieIdForName( const char* name );
|
||||
void CheckHeartbeats( time_t now, vector<int>* victims );
|
||||
|
||||
|
|
|
@ -87,14 +87,24 @@ getNetShort( unsigned char** bufpp )
|
|||
memcpy( &tmp, *bufpp, 2 );
|
||||
*bufpp += 2;
|
||||
return ntohs( tmp );
|
||||
}
|
||||
} /* getNetShort */
|
||||
|
||||
static unsigned short
|
||||
getNetLong( unsigned char** bufpp )
|
||||
{
|
||||
unsigned long tmp;
|
||||
memcpy( &tmp, *bufpp, sizeof(tmp) );
|
||||
*bufpp += sizeof(tmp);
|
||||
assert( sizeof(tmp) == 4 );
|
||||
return ntohl( tmp );
|
||||
} /* getNetLong */
|
||||
|
||||
static void
|
||||
processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
||||
{
|
||||
CookieID cookieID = getNetShort( &buf );
|
||||
CookieID cookieID = getNetLong( &buf );
|
||||
HostID hostID = getNetShort( &buf );
|
||||
logf( "processHeartbeat: cookieID 0x%x, hostID 0x%x", cookieID, hostID );
|
||||
logf( "processHeartbeat: cookieID 0x%lx, hostID 0x%x", cookieID, hostID );
|
||||
CookieRef* cref = get_cookieRef( cookieID );
|
||||
if ( cref != NULL ) {
|
||||
cref->HandleHeartbeat( hostID, socket );
|
||||
|
@ -130,9 +140,9 @@ processConnect( unsigned char* bufp, int bufLen, int socket )
|
|||
|
||||
if ( bufp < end ) {
|
||||
HostID srcID = getNetShort( &bufp );
|
||||
CookieID connID = getNetShort( &bufp );
|
||||
CookieID cookieID = getNetLong( &bufp );
|
||||
if ( bufp == end ) {
|
||||
cref = get_make_cookieRef( cookie, connID );
|
||||
cref = get_make_cookieRef( cookie, cookieID );
|
||||
assert( cref != NULL );
|
||||
cref->Connect( socket, srcID );
|
||||
}
|
||||
|
@ -164,7 +174,7 @@ forwardMessage( unsigned char* buf, int buflen, int srcSocket )
|
|||
{
|
||||
int success = 0;
|
||||
unsigned char* bufp = buf + 1; /* skip cmd */
|
||||
unsigned short cookieID = getNetShort( &bufp );
|
||||
CookieID cookieID = getNetLong( &bufp );
|
||||
logf( "cookieID = %d", cookieID );
|
||||
CookieRef* cref = get_cookieRef( cookieID );
|
||||
if ( cref != NULL ) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <time.h>
|
||||
|
||||
typedef unsigned short HostID;
|
||||
typedef unsigned short CookieID; /* stands in for string after connection established */
|
||||
typedef unsigned long CookieID; /* stands in for string after connection established */
|
||||
|
||||
void logf( const char* format, ... );
|
||||
|
||||
|
|
Loading…
Reference in a new issue