From 43bd3c018a923ab83132ca49e1edd782e4fa623b Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 25 Sep 2014 20:05:37 -0700 Subject: [PATCH] make an addr's conType a bitfield rather than holding a single value. Works for large numbers of relay games in test, but will not yet actually hold more than one value. Should be safe to merge to main branch once stream upgrade is verified. --- xwords4/common/comms.c | 227 +++++++++++++++++++++++------------- xwords4/common/comms.h | 10 +- xwords4/common/comtypes.h | 3 +- xwords4/linux/cursesmain.c | 6 +- xwords4/linux/gamesdb.c | 2 +- xwords4/linux/gtkboard.c | 2 +- xwords4/linux/gtkconnsdlg.c | 20 ++-- xwords4/linux/linuxmain.c | 10 +- xwords4/linux/linuxsms.c | 2 +- 9 files changed, 179 insertions(+), 103 deletions(-) diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index 61af4a2da..9145f99c1 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -181,6 +181,8 @@ static void freeElem( const CommsCtxt* comms, MsgQueueElem* elem ); static XP_U16 countAddrRecs( const CommsCtxt* comms ); static void sendConnect( CommsCtxt* comms, XP_Bool breakExisting ); +static XP_Bool addr_iter( const CommsAddrRec* addr, CommsConnType* typp, + XP_U32* state ); #ifdef XWFEATURE_RELAY static XP_Bool relayConnect( CommsCtxt* comms ); @@ -455,7 +457,7 @@ comms_transportFailed( CommsCtxt* comms ) { LOG_FUNC(); XP_ASSERT( !!comms ); - if ( COMMS_CONN_RELAY == comms->addr.conType + if ( COMMS_CONN_RELAY == addr_getType(&comms->addr) && comms->rr.relayState != COMMS_RELAYSTATE_DENIED ) { relayDisconnect( comms ); @@ -469,10 +471,10 @@ void comms_destroy( CommsCtxt* comms ) { /* did I call comms_stop()? */ - XP_ASSERT( COMMS_CONN_RELAY != comms->addr.conType + XP_ASSERT( COMMS_CONN_RELAY != addr_getType(&comms->addr) || COMMS_RELAYSTATE_UNCONNECTED == comms->rr.relayState ); - CommsAddrRec aNew = { .conType = COMMS_CONN_NONE }; + CommsAddrRec aNew = {0}; util_addrChange( comms->util, &comms->addr, &aNew ); cleanupInternal( comms ); @@ -493,54 +495,68 @@ comms_setConnID( CommsCtxt* comms, XP_U32 connID ) } /* comms_setConnID */ static void -addrFromStream( CommsAddrRec* addrP, XWStreamCtxt* stream ) +addrFromStreamOne( CommsAddrRec* addrP, XWStreamCtxt* stream, CommsConnType typ ) { - CommsAddrRec addr; - - addr.conType = stream_getU8( stream ); - - switch( addr.conType ) { + switch( typ ) { case COMMS_CONN_NONE: break; case COMMS_CONN_BT: - stringFromStreamHere( stream, addr.u.bt.hostName, - sizeof(addr.u.bt.hostName) ); - stringFromStreamHere( stream, addr.u.bt.btAddr.chars, - sizeof(addr.u.bt.btAddr.chars) ); + stringFromStreamHere( stream, addrP->u.bt.hostName, + sizeof(addrP->u.bt.hostName) ); + stringFromStreamHere( stream, addrP->u.bt.btAddr.chars, + sizeof(addrP->u.bt.btAddr.chars) ); break; case COMMS_CONN_IR: /* nothing to save */ break; case COMMS_CONN_IP_DIRECT: - stringFromStreamHere( stream, addr.u.ip.hostName_ip, - sizeof(addr.u.ip.hostName_ip) ); - addr.u.ip.ipAddr_ip = stream_getU32( stream ); - addr.u.ip.port_ip = stream_getU16( stream ); + stringFromStreamHere( stream, addrP->u.ip.hostName_ip, + sizeof(addrP->u.ip.hostName_ip) ); + addrP->u.ip.ipAddr_ip = stream_getU32( stream ); + addrP->u.ip.port_ip = stream_getU16( stream ); break; case COMMS_CONN_RELAY: - stringFromStreamHere( stream, addr.u.ip_relay.invite, - sizeof(addr.u.ip_relay.invite) ); - stringFromStreamHere( stream, addr.u.ip_relay.hostName, - sizeof(addr.u.ip_relay.hostName) ); - addr.u.ip_relay.ipAddr = stream_getU32( stream ); - addr.u.ip_relay.port = stream_getU16( stream ); + stringFromStreamHere( stream, addrP->u.ip_relay.invite, + sizeof(addrP->u.ip_relay.invite) ); + stringFromStreamHere( stream, addrP->u.ip_relay.hostName, + sizeof(addrP->u.ip_relay.hostName) ); + addrP->u.ip_relay.ipAddr = stream_getU32( stream ); + addrP->u.ip_relay.port = stream_getU16( stream ); if ( stream_getVersion( stream ) >= STREAM_VERS_DICTLANG ) { - addr.u.ip_relay.seeksPublicRoom = stream_getBits( stream, 1 ); - addr.u.ip_relay.advertiseRoom = stream_getBits( stream, 1 ); + addrP->u.ip_relay.seeksPublicRoom = stream_getBits( stream, 1 ); + addrP->u.ip_relay.advertiseRoom = stream_getBits( stream, 1 ); } break; case COMMS_CONN_SMS: - stringFromStreamHere( stream, addr.u.sms.phone, - sizeof(addr.u.sms.phone) ); - addr.u.sms.port = stream_getU16( stream ); + stringFromStreamHere( stream, addrP->u.sms.phone, + sizeof(addrP->u.sms.phone) ); + addrP->u.sms.port = stream_getU16( stream ); break; default: /* shut up, compiler */ break; } +} /* addrFromStreamOne */ - XP_MEMCPY( addrP, &addr, sizeof(*addrP) ); -} /* addrFromStream */ +static void +addrFromStream( CommsAddrRec* addrP, XWStreamCtxt* stream ) +{ + XP_U8 tmp = stream_getU8( stream ); + if ( STREAM_VERS_MULTIADDR <= stream_getVersion( stream ) ) { + /* do nothing */ + } else { + if ( COMMS_CONN_NONE != tmp ) { + tmp = 1 << (tmp - 1); + } + } + addrP->_conTypes = tmp; + + CommsConnType typ; + XP_U32 state = 0; + while ( addr_iter( addrP, &typ, &state ) ) { + addrFromStreamOne( addrP, stream, typ ); + } +} CommsCtxt* comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, @@ -556,14 +572,9 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, short ii; isServer = stream_getU8( stream ); - if ( version < STREAM_VERS_RELAY ) { - XP_MEMSET( &addr, 0, sizeof(addr) ); - addr.conType = COMMS_CONN_IR; /* all there was back then */ - } else { - addrFromStream( &addr, stream ); - } + addrFromStream( &addr, stream ); - if ( addr.conType == COMMS_CONN_RELAY ) { + if ( addr_getType( &addr ) == COMMS_CONN_RELAY ) { nPlayersHere = (XP_U16)stream_getBits( stream, 4 ); nPlayersTotal = (XP_U16)stream_getBits( stream, 4 ); } else { @@ -590,7 +601,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, comms->resendBackoff = stream_getU16( stream ); comms->nextResend = stream_getU32( stream ); } - if ( addr.conType == COMMS_CONN_RELAY ) { + if ( addr_getType(&addr) == COMMS_CONN_RELAY ) { comms->rr.myHostID = stream_getU8( stream ); stringFromStreamHere( stream, comms->rr.connName, sizeof(comms->rr.connName) ); @@ -611,7 +622,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, rec->lastMsgAckd = stream_getU16( stream ); } rec->channelNo = stream_getU16( stream ); - if ( rec->addr.conType == COMMS_CONN_RELAY ) { + if ( addr_getType( &rec->addr ) == COMMS_CONN_RELAY ) { rec->rr.hostID = stream_getU8( stream ); } @@ -671,7 +682,7 @@ comms_start( CommsCtxt* comms ) void comms_stop( CommsCtxt* comms ) { - if ( COMMS_CONN_RELAY == comms->addr.conType ) { + if ( COMMS_CONN_RELAY == addr_getType( &comms->addr ) ) { relayDisconnect( comms ); } } @@ -679,7 +690,7 @@ comms_stop( CommsCtxt* comms ) static void sendConnect( CommsCtxt* comms, XP_Bool breakExisting ) { - switch( comms->addr.conType ) { + switch( addr_getType( &comms->addr ) ) { #ifdef XWFEATURE_RELAY case COMMS_CONN_RELAY: if ( breakExisting @@ -708,47 +719,54 @@ sendConnect( CommsCtxt* comms, XP_Bool breakExisting ) } /* comms_start */ static void -addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addrP ) +addrToStreamOne( XWStreamCtxt* stream, CommsConnType typ, const CommsAddrRec* addrP ) { - CommsAddrRec addr; - XP_MEMCPY( &addr, addrP, sizeof(addr) ); /* does this really speed things - or reduce code size? */ - stream_putU8( stream, addr.conType ); - - switch( addr.conType ) { + switch( typ ) { case COMMS_CONN_NONE: /* nothing to write */ break; case COMMS_CONN_BT: - stringToStream( stream, addr.u.bt.hostName ); + stringToStream( stream, addrP->u.bt.hostName ); /* sizeof(.bits) below defeats ARM's padding. */ - stringToStream( stream, addr.u.bt.btAddr.chars ); + stringToStream( stream, addrP->u.bt.btAddr.chars ); break; case COMMS_CONN_IR: /* nothing to save */ break; case COMMS_CONN_IP_DIRECT: - stringToStream( stream, addr.u.ip.hostName_ip ); - stream_putU32( stream, addr.u.ip.ipAddr_ip ); - stream_putU16( stream, addr.u.ip.port_ip ); + stringToStream( stream, addrP->u.ip.hostName_ip ); + stream_putU32( stream, addrP->u.ip.ipAddr_ip ); + stream_putU16( stream, addrP->u.ip.port_ip ); break; case COMMS_CONN_RELAY: - stringToStream( stream, addr.u.ip_relay.invite ); - stringToStream( stream, addr.u.ip_relay.hostName ); - stream_putU32( stream, addr.u.ip_relay.ipAddr ); - stream_putU16( stream, addr.u.ip_relay.port ); - stream_putBits( stream, 1, addr.u.ip_relay.seeksPublicRoom ); - stream_putBits( stream, 1, addr.u.ip_relay.advertiseRoom ); + stringToStream( stream, addrP->u.ip_relay.invite ); + stringToStream( stream, addrP->u.ip_relay.hostName ); + stream_putU32( stream, addrP->u.ip_relay.ipAddr ); + stream_putU16( stream, addrP->u.ip_relay.port ); + stream_putBits( stream, 1, addrP->u.ip_relay.seeksPublicRoom ); + stream_putBits( stream, 1, addrP->u.ip_relay.advertiseRoom ); break; case COMMS_CONN_SMS: - stringToStream( stream, addr.u.sms.phone ); - stream_putU16( stream, addr.u.sms.port ); + stringToStream( stream, addrP->u.sms.phone ); + stream_putU16( stream, addrP->u.sms.port ); break; default: XP_ASSERT(0); break; } -} /* addrToStream */ +} /* addrToStreamOne */ + +static void +addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addrP ) +{ + stream_putU8( stream, addrP->_conTypes ); + + CommsConnType typ; + XP_U32 state = 0; + while ( addr_iter( addrP, &typ, &state ) ) { + addrToStreamOne( stream, typ, addrP ); + } +} void comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream, @@ -760,7 +778,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream, stream_putU8( stream, (XP_U8)comms->isServer ); addrToStream( stream, &comms->addr ); - if ( comms->addr.conType == COMMS_CONN_RELAY ) { + if ( COMMS_CONN_RELAY == addr_getType( &comms->addr ) ) { stream_putBits( stream, 4, comms->rr.nPlayersHere ); stream_putBits( stream, 4, comms->rr.nPlayersTotal ); } @@ -770,7 +788,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream, stream_putU16( stream, comms->channelSeed ); stream_putU16( stream, comms->resendBackoff ); stream_putU32( stream, comms->nextResend ); - if ( comms->addr.conType == COMMS_CONN_RELAY ) { + if ( COMMS_CONN_RELAY == addr_getType( &comms->addr ) ) { stream_putU8( stream, comms->rr.myHostID ); stringToStream( stream, comms->rr.connName ); } @@ -790,7 +808,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream, stream_putU16( stream, (XP_U16)rec->lastMsgRcd ); stream_putU16( stream, (XP_U16)rec->lastMsgAckd ); stream_putU16( stream, rec->channelNo ); - if ( rec->addr.conType == COMMS_CONN_RELAY ) { + if ( COMMS_CONN_RELAY == addr_getType( &rec->addr ) ) { stream_putU8( stream, rec->rr.hostID ); /* unneeded unless RELAY */ } } @@ -913,7 +931,7 @@ comms_getInitialAddr( CommsAddrRec* addr ) { #if defined XWFEATURE_RELAY - addr->conType = COMMS_CONN_RELAY; /* for temporary ease in debugging */ + addr_setType( addr, COMMS_CONN_RELAY ); /* for temporary ease in debugging */ addr->u.ip_relay.ipAddr = 0L; /* force 'em to set it */ addr->u.ip_relay.port = relayPort; { @@ -939,7 +957,7 @@ comms_checkAddr( DeviceRole role, const CommsAddrRec* addr, XW_UtilCtxt* util ) XP_Bool ok = XP_TRUE; /* make sure the user's given us enough information to make a connection */ if ( role == SERVER_ISCLIENT ) { - if ( addr->conType == COMMS_CONN_BT ) { + if ( COMMS_CONN_BT == addr_getType( addr ) ) { XP_U32 empty = 0L; /* check four bytes to save some code */ if ( !XP_MEMCMP( &empty, &addr->u.bt.btAddr, sizeof(empty) ) ) { ok = XP_FALSE; @@ -957,7 +975,7 @@ comms_getConType( const CommsCtxt* comms ) { CommsConnType typ; if ( !!comms ) { - typ = comms->addr.conType; + typ = addr_getType( &comms->addr ); } else { typ = COMMS_CONN_NONE; XP_LOGF( "%s: returning COMMS_CONN_NONE for null comms", __func__ ); @@ -1664,14 +1682,14 @@ preProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* XP_UNUSED_RELAY(senderID) ) { XP_Bool consumed = XP_FALSE; - switch ( comms->addr.conType ) { + switch ( addr_getType( &comms->addr ) ) { #ifdef XWFEATURE_RELAY /* relayPreProcess returns true if consumes the message. May just eat the header and leave a regular message to be processed below. */ case COMMS_CONN_RELAY: consumed = relayPreProcess( comms, stream, senderID ); if ( !consumed ) { - *usingRelay = comms->addr.conType == COMMS_CONN_RELAY; + *usingRelay = COMMS_CONN_RELAY == addr_getType( &comms->addr ); } break; #endif @@ -1698,10 +1716,10 @@ getRecordFor( CommsCtxt* comms, const CommsAddrRec* addr, XP_U16 mask = maskChannel? ~CHANNEL_MASK : ~0; /* Use addr if we have it. Otherwise use channelNo if non-0 */ - conType = !!addr? addr->conType : COMMS_CONN_NONE; + conType = !!addr? addr_getType( addr ) : COMMS_CONN_NONE; for ( rec = comms->recs; !!rec; rec = rec->next ) { - XP_ASSERT( !addr || (conType == rec->addr.conType) ); + XP_ASSERT( !addr || (conType == addr_getType( &rec->addr ) ) ); switch( conType ) { case COMMS_CONN_RELAY: XP_ASSERT(0); /* is this being used? */ @@ -1881,7 +1899,7 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID senderID = 0; /* unset; default for non-relay cases */ XP_Bool usingRelay = XP_FALSE; - XP_ASSERT( retAddr == NULL || comms->addr.conType == retAddr->conType ); + XP_ASSERT( retAddr == NULL || addr_getType( &comms->addr ) == addr_getType( retAddr ) ); #ifdef COMMS_CHECKSUM XP_U16 initialLen = stream_getSize( stream ); #endif @@ -1960,7 +1978,7 @@ comms_checkComplete( const CommsAddrRec* addr ) { XP_Bool result; - switch ( addr->conType ) { + switch ( addr_getType( addr ) ) { case COMMS_CONN_RELAY: result = !!addr->u.ip_relay.invite[0] && !!addr->u.ip_relay.hostName[0] @@ -1986,7 +2004,7 @@ XP_Bool comms_isConnected( const CommsCtxt* const comms ) { XP_Bool result = XP_FALSE; - switch ( comms->addr.conType ) { + switch ( addr_getType( &comms->addr ) ) { case COMMS_CONN_RELAY: result = 0 != comms->rr.connName[0]; break; @@ -2131,6 +2149,7 @@ ConnType2Str( CommsConnType typ ) CASESTR( COMMS_CONN_RELAY ); CASESTR( COMMS_CONN_BT ); CASESTR( COMMS_CONN_SMS ); + CASESTR( COMMS_CONN_NTYPES ); default: XP_ASSERT(0); } @@ -2199,7 +2218,7 @@ rememberChannelAddress( CommsCtxt* comms, XP_PlayerAddr channelNo, XP_ASSERT( recs->rr.hostID == hostID ); } else { XP_MEMSET( &recs->addr, 0, sizeof(recs->addr) ); - recs->addr.conType = comms->addr.conType; + addr_setType( &recs->addr, addr_getType( &comms->addr ) ); } } return recs; @@ -2235,6 +2254,58 @@ countAddrRecs( const CommsCtxt* comms ) return count; } /* countAddrRecs */ +static XP_Bool +addr_iter( const CommsAddrRec* addr, CommsConnType* typp, XP_U32* state ) +{ + CommsConnType typ = *state; + XP_U16 flags = addr->_conTypes; + while ( ++typ < COMMS_CONN_NTYPES ) { + *state = typ; + XP_U16 mask = 1 << (typ - 1); + if ( mask == (flags & mask) ) { + break; + } + } + XP_Bool result = typ < COMMS_CONN_NTYPES; + if ( result ) { + *typp = typ; + } + XP_LOGF( "%s(flag=%x)=>%d (typ=%s)", __func__, flags, result, ConnType2Str( typ ) ); + return result; +} + +CommsConnType +addr_getType( const CommsAddrRec* addr ) +{ + CommsConnType typ; + XP_U16 flags = addr->_conTypes; + if ( 0 == flags ) { + typ = COMMS_CONN_NONE; + } else { + for ( typ = COMMS_CONN_NONE + 1; typ < COMMS_CONN_NTYPES; ++typ ) { + XP_U16 mask = (1 << (typ - 1)); + if ( 0 != (flags & mask) ) { + XP_ASSERT( 0 == (flags & ~mask )); /* confirm only bit set */ + break; + } + } + } + XP_ASSERT( COMMS_CONN_NTYPES != typ ); + // LOG_RETURNF( "%s", ConnType2Str( typ ) ); + return typ; +} + +void +addr_setType( CommsAddrRec* addr, CommsConnType type ) +{ + XP_U16 flags = 0; + if ( COMMS_CONN_NONE != type ) { + flags = 1 << (type - 1); + } + addr->_conTypes = flags; + XP_ASSERT( type == addr_getType( addr ) ); +} + #ifdef XWFEATURE_RELAY static XWHostID getDestID( CommsCtxt* comms, XP_PlayerAddr channelNo ) @@ -2421,7 +2492,7 @@ relayConnect( CommsCtxt* comms ) { XP_Bool success = XP_TRUE; LOG_FUNC(); - if ( comms->addr.conType == COMMS_CONN_RELAY && !comms->rr.connecting ) { + if ( addr_getType( &comms->addr ) == COMMS_CONN_RELAY && !comms->rr.connecting ) { comms->rr.connecting = XP_TRUE; success = send_via_relay( comms, comms->rr.connName[0]? XWRELAY_GAME_RECONNECT : XWRELAY_GAME_CONNECT, @@ -2468,7 +2539,7 @@ static void relayDisconnect( CommsCtxt* comms ) { LOG_FUNC(); - if ( comms->addr.conType == COMMS_CONN_RELAY ) { + if ( addr_getType( &comms->addr ) == COMMS_CONN_RELAY ) { if ( comms->rr.relayState > COMMS_RELAYSTATE_CONNECT_PENDING ) { (void)send_via_relay( comms, XWRELAY_GAME_DISCONNECT, HOST_ID_NONE, NULL, 0 ); diff --git a/xwords4/common/comms.h b/xwords4/common/comms.h index d83f7b0b6..9af691d07 100644 --- a/xwords4/common/comms.h +++ b/xwords4/common/comms.h @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* - * Copyright 2001-2009 by Eric House (xwords@eehouse.org). All rights + * Copyright 2001 - 2014 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -76,9 +76,9 @@ typedef struct XP_BtAddrStr { XP_UCHAR chars[18]; } XP_BtAddrStr; #define MAX_PHONE_LEN 31 typedef struct _CommsAddrRec { - CommsConnType conType; + XP_U16 _conTypes; - union { + struct { struct { XP_UCHAR hostName_ip[MAX_HOSTNAME_LEN + 1]; XP_U32 ipAddr_ip; /* looked up from above */ @@ -221,6 +221,10 @@ XP_Bool comms_checkComplete( const CommsAddrRec* const addr ); XP_Bool comms_canChat( const CommsCtxt* comms ); XP_Bool comms_isConnected( const CommsCtxt* const comms ); +CommsConnType addr_getType( const CommsAddrRec* addr ); +void addr_setType( CommsAddrRec* addr, CommsConnType type ); + + # ifdef DEBUG void comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream ); const char* ConnType2Str( CommsConnType typ ); diff --git a/xwords4/common/comtypes.h b/xwords4/common/comtypes.h index dc0abf2d3..1a9af66f0 100644 --- a/xwords4/common/comtypes.h +++ b/xwords4/common/comtypes.h @@ -47,6 +47,7 @@ #endif #define MAX_COLS MAX_ROWS +#define STREAM_VERS_MULTIADDR 0x17 #define STREAM_VERS_COMMSBACKOFF 0x16 #define STREAM_VERS_DICTNAME 0x15 #ifdef HASH_STREAM @@ -84,7 +85,7 @@ #define STREAM_VERS_405 0x01 /* search for FIX_NEXT_VERSION_CHANGE next time this is changed */ -#define CUR_STREAM_VERS STREAM_VERS_COMMSBACKOFF +#define CUR_STREAM_VERS STREAM_VERS_MULTIADDR typedef struct XP_Rect { XP_S16 left; diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index 5d64e603c..2eedc4232 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -2131,7 +2131,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) if ( 0 ) { # ifdef XWFEATURE_RELAY } else if ( params->conType == COMMS_CONN_RELAY ) { - addr.conType = COMMS_CONN_RELAY; + addr_setType( &addr, COMMS_CONN_RELAY ); addr.u.ip_relay.ipAddr = 0; /* ??? */ addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort; addr.u.ip_relay.seeksPublicRoom = params->connInfo.relay.seeksPublicRoom; @@ -2143,14 +2143,14 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) # endif # ifdef XWFEATURE_SMS } else if ( params->conType == COMMS_CONN_SMS ) { - addr.conType = COMMS_CONN_SMS; + addr_setType( &addr, COMMS_CONN_SMS ); XP_STRNCPY( addr.u.sms.phone, params->connInfo.sms.phone, sizeof(addr.u.sms.phone) - 1 ); addr.u.sms.port = params->connInfo.sms.port; # endif # ifdef XWFEATURE_BLUETOOTH } else if ( params->conType == COMMS_CONN_BT ) { - addr.conType = COMMS_CONN_BT; + addr_setType( &addr, COMMS_CONN_BT ); XP_ASSERT( sizeof(addr.u.bt.btAddr) >= sizeof(params->connInfo.bt.hostAddr)); XP_MEMCPY( &addr.u.bt.btAddr, ¶ms->connInfo.bt.hostAddr, diff --git a/xwords4/linux/gamesdb.c b/xwords4/linux/gamesdb.c index d0ba975c2..9fc3e2103 100644 --- a/xwords4/linux/gamesdb.c +++ b/xwords4/linux/gamesdb.c @@ -135,7 +135,7 @@ summarize( CommonGlobals* cGlobals ) if ( !!cGlobals->game.comms ) { nMissing = server_getMissingPlayers( cGlobals->game.server ); comms_getAddr( cGlobals->game.comms, &addr ); - switch( addr.conType ) { + switch( addr_getType( &addr ) ) { case COMMS_CONN_RELAY: room = addr.u.ip_relay.invite; connvia = "Relay"; diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index 51f7e3091..d5768ce41 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -510,7 +510,7 @@ createOrLoadObjects( GtkGameGlobals* globals ) &cGlobals->cp, &procs, params->gameSeed ); // addr.conType = params->conType; - switch( addr.conType ) { + switch( addr_getType( &addr ) ) { #ifdef XWFEATURE_RELAY case COMMS_CONN_RELAY: /* addr.u.ip_relay.ipAddr = 0; */ diff --git a/xwords4/linux/gtkconnsdlg.c b/xwords4/linux/gtkconnsdlg.c index e83a29e8c..931dc0b90 100644 --- a/xwords4/linux/gtkconnsdlg.c +++ b/xwords4/linux/gtkconnsdlg.c @@ -123,7 +123,7 @@ handle_ok( GtkWidget* XP_UNUSED(widget), gpointer closure ) break; } - state->addr->conType = conType; + addr_setType( state->addr, conType ); } state->cancelled = XP_FALSE; @@ -184,7 +184,7 @@ makeRelayPage( GtkConnsState* state ) gtk_box_pack_start( GTK_BOX(vbox), gtk_label_new( hint ), FALSE, TRUE, 0 ); GtkWidget* hbox = makeLabeledField( "Room", &state->invite, NULL ); - if ( COMMS_CONN_RELAY == state->addr->conType ) { + if ( COMMS_CONN_RELAY == addr_getType( state->addr ) ) { gtk_entry_set_text( GTK_ENTRY(state->invite), state->addr->u.ip_relay.invite ); } @@ -192,7 +192,7 @@ makeRelayPage( GtkConnsState* state ) gtk_widget_set_sensitive( state->invite, !state->readOnly ); hbox = makeLabeledField( "Relay address", &state->hostName, NULL ); - if ( COMMS_CONN_RELAY == state->addr->conType ) { + if ( COMMS_CONN_RELAY == addr_getType( state->addr ) ) { gtk_entry_set_text( GTK_ENTRY(state->hostName), state->addr->u.ip_relay.hostName ); } @@ -200,7 +200,7 @@ makeRelayPage( GtkConnsState* state ) gtk_widget_set_sensitive( state->hostName, !state->readOnly ); hbox = makeLabeledField( "Relay port", &state->port, NULL ); - if ( COMMS_CONN_RELAY == state->addr->conType ) { + if ( COMMS_CONN_RELAY == addr_getType( state->addr ) ) { char buf[16]; snprintf( buf, sizeof(buf), "%d", state->addr->u.ip_relay.port ); gtk_entry_set_text( GTK_ENTRY(state->port), buf ); @@ -219,7 +219,7 @@ makeBTPage( GtkConnsState* state ) GtkWidget* vbox = gtk_vbox_new( FALSE, 0 ); GtkWidget* hbox = makeLabeledField( "Host device", &state->bthost, NULL ); - if ( COMMS_CONN_BT == state->addr->conType ) { + if ( COMMS_CONN_BT == addr_getType( state->addr ) ) { gtk_entry_set_text( GTK_ENTRY(state->bthost), state->addr->u.bt.hostName ); } gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); @@ -243,13 +243,13 @@ makeIPDirPage( GtkConnsState* state ) /* XP_UCHAR hostName_ip[MAX_HOSTNAME_LEN + 1]; */ /* XP_U16 port_ip; */ - const gchar* name = COMMS_CONN_IP_DIRECT == state->addr->conType ? + const gchar* name = COMMS_CONN_IP_DIRECT == addr_getType( state->addr ) ? state->addr->u.ip.hostName_ip : state->globals->cGlobals.params->connInfo.ip.hostName; GtkWidget* hbox = makeLabeledField( "Hostname", &state->iphost, name ); gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); hbox = makeLabeledField( "Relay port", &state->ipport, NULL ); - if ( COMMS_CONN_IP_DIRECT == state->addr->conType ) { + if ( COMMS_CONN_IP_DIRECT == addr_getType( state->addr ) ) { char buf[16]; snprintf( buf, sizeof(buf), "%d", state->addr->u.ip.port_ip ); gtk_entry_set_text( GTK_ENTRY(state->ipport), buf ); @@ -265,13 +265,13 @@ makeSMSPage( GtkConnsState* state ) { GtkWidget* vbox = gtk_vbox_new( FALSE, 0 ); - const gchar* phone = COMMS_CONN_SMS == state->addr->conType ? + const gchar* phone = COMMS_CONN_SMS == addr_getType( state->addr ) ? state->addr->u.sms.phone : state->globals->cGlobals.params->connInfo.sms.phone; GtkWidget* hbox = makeLabeledField( "Host phone", &state->smsphone, phone ); gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); gtk_widget_set_sensitive( state->smsphone, !state->readOnly ); - int portVal = COMMS_CONN_SMS == state->addr->conType + int portVal = COMMS_CONN_SMS == addr_getType( state->addr ) ? state->addr->u.sms.port : state->globals->cGlobals.params->connInfo.sms.port; gchar port[32]; @@ -331,7 +331,7 @@ gtkConnsDlg( GtkGameGlobals* globals, CommsAddrRec* addr, DeviceRole role, gtk_box_pack_start( GTK_BOX(vbox), state.notebook, FALSE, TRUE, 0 ); state.pageTypes[nTypes++] = COMMS_CONN_NONE; /* mark end of list */ - gint pageNo = conTypeToPageNum( &state, addr->conType ); + gint pageNo = conTypeToPageNum( &state, addr_getType( addr ) ); gtk_notebook_set_current_page( GTK_NOTEBOOK(state.notebook), pageNo ); gtk_widget_show( state.notebook ); diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index b5ef0ff92..f7e436212 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -1144,7 +1144,7 @@ linux_send( const XP_U8* buf, XP_U16 buflen, const CommsAddrRec* addrRec, CommsConnType conType; if ( !!addrRec ) { - conType = addrRec->conType; + conType = addr_getType( addrRec ); } else { conType = cGlobals->params->conType; } @@ -1395,7 +1395,7 @@ linux_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* newAddr ) { CommonGlobals* cGlobals = (CommonGlobals*)uc->closure; - switch ( newAddr->conType ) { + switch ( addr_getType( newAddr ) ) { #ifdef XWFEATURE_BLUETOOTH case COMMS_CONN_BT: { XP_Bool isServer = comms_getIsServer( cGlobals->game.comms ); @@ -1814,7 +1814,7 @@ initFromParams( CommonGlobals* cGlobals, LaunchParams* params ) if ( 0 ) { #ifdef XWFEATURE_RELAY } else if ( params->conType == COMMS_CONN_RELAY ) { - addr->conType = COMMS_CONN_RELAY; + addr_setType( addr, COMMS_CONN_RELAY ); addr->u.ip_relay.ipAddr = 0; /* ??? */ addr->u.ip_relay.port = params->connInfo.relay.defaultSendPort; addr->u.ip_relay.seeksPublicRoom = @@ -1828,14 +1828,14 @@ initFromParams( CommonGlobals* cGlobals, LaunchParams* params ) #endif #ifdef XWFEATURE_SMS } else if ( params->conType == COMMS_CONN_SMS ) { - addr->conType = COMMS_CONN_SMS; + addr_setType( addr, COMMS_CONN_SMS ); XP_STRNCPY( addr->u.sms.phone, params->connInfo.sms.phone, sizeof(addr->u.sms.phone) - 1 ); addr->u.sms.port = params->connInfo.sms.port; #endif #ifdef XWFEATURE_BLUETOOTH } else if ( params->conType == COMMS_CONN_BT ) { - addr->conType = COMMS_CONN_BT; + addr_setType( addr, COMMS_CONN_BT ); XP_ASSERT( sizeof(addr->u.bt.btAddr) >= sizeof(params->connInfo.bt.hostAddr)); XP_MEMCPY( &addr->u.bt.btAddr, ¶ms->connInfo.bt.hostAddr, diff --git a/xwords4/linux/linuxsms.c b/xwords4/linux/linuxsms.c index 3aafdb015..766d15a0a 100644 --- a/xwords4/linux/linuxsms.c +++ b/xwords4/linux/linuxsms.c @@ -188,7 +188,7 @@ decodeAndDelete( LinSMSData* storage, const gchar* name, if ( valid && outlen <= buflen ) { XP_MEMCPY( buf, out, outlen ); nRead = outlen; - addr->conType = COMMS_CONN_SMS; + addr_setType( addr, COMMS_CONN_SMS ); XP_STRNCPY( addr->u.sms.phone, phone, sizeof(addr->u.sms.phone) ); XP_LOGF( "%s: message came from phone: %s", __func__, phone ); addr->u.sms.port = 1; /* for now */