mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
add new stream version that skips relay and allows longer string
And remove some dead code
This commit is contained in:
parent
41d9d4a254
commit
924695d3fb
7 changed files with 54 additions and 78 deletions
|
@ -64,7 +64,8 @@ public class JNIThread extends Thread implements AutoCloseable {
|
|||
CMD_SAVE,
|
||||
CMD_DO,
|
||||
CMD_RECEIVE,
|
||||
CMD_TRANSFAIL,
|
||||
// can I remove this? What if ordinal of enum's being saved somewhere
|
||||
_CMD_TRANSFAIL,
|
||||
CMD_PREFS_CHANGE,
|
||||
CMD_PEN_DOWN,
|
||||
CMD_PEN_MOVE,
|
||||
|
@ -543,11 +544,6 @@ public class JNIThread extends Thread implements AutoCloseable {
|
|||
}
|
||||
break;
|
||||
|
||||
case CMD_TRANSFAIL:
|
||||
CommsConnType typ = (CommsConnType)args[0];
|
||||
XwJNI.comms_transportFailed( m_jniGamePtr, typ );
|
||||
break;
|
||||
|
||||
case CMD_PREFS_CHANGE:
|
||||
// need to inval all because some of prefs,
|
||||
// e.g. colors, aren't known by common code so
|
||||
|
|
|
@ -547,8 +547,6 @@ public class XwJNI {
|
|||
public static native int comms_countPendingPackets( GamePtr gamePtr );
|
||||
|
||||
public static native void comms_ackAny( GamePtr gamePtr );
|
||||
public static native void comms_transportFailed( GamePtr gamePtr,
|
||||
CommsConnType failed );
|
||||
public static native boolean comms_isConnected( GamePtr gamePtr );
|
||||
public static native String comms_getStats( GamePtr gamePtr );
|
||||
public static native void comms_addMQTTDevID( GamePtr gamePtr, int channelNo,
|
||||
|
|
|
@ -2634,22 +2634,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1ackAny
|
|||
}
|
||||
#endif
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1transportFailed
|
||||
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject failedTyp )
|
||||
{
|
||||
XWJNI_START(gamePtr);
|
||||
XP_ASSERT( !!state->game.comms );
|
||||
|
||||
CommsConnType typ = jEnumToInt( env, failedTyp );
|
||||
(void)comms_transportFailed( state->game.comms,
|
||||
#ifdef XWFEATURE_RELAY
|
||||
env,
|
||||
#endif
|
||||
typ );
|
||||
XWJNI_END();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1isConnected
|
||||
( JNIEnv* env, jclass C, GamePtrType gamePtr )
|
||||
|
|
|
@ -619,25 +619,6 @@ set_reset_timer( CommsCtxt* comms, XWEnv xwe )
|
|||
} /* set_reset_timer */
|
||||
#endif /* XWFEATURE_RELAY */
|
||||
|
||||
void
|
||||
comms_transportFailed( CommsCtxt* comms,
|
||||
#ifdef XWFEATURE_RELAY
|
||||
XWEnv xwe,
|
||||
#endif
|
||||
CommsConnType failed )
|
||||
{
|
||||
XP_LOGFF( "(%s)", ConnType2Str(failed) );
|
||||
XP_ASSERT( !!comms );
|
||||
if ( COMMS_CONN_RELAY == failed && addr_hasType( &comms->selfAddr, COMMS_CONN_RELAY )
|
||||
&& comms->rr.relayState != COMMS_RELAYSTATE_DENIED ) {
|
||||
relayDisconnect( comms, xwe );
|
||||
#ifdef XWFEATURE_RELAY
|
||||
set_reset_timer( comms, xwe );
|
||||
#endif /* XWFEATURE_RELAY */
|
||||
}
|
||||
LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
void
|
||||
comms_destroy( CommsCtxt* comms, XWEnv xwe )
|
||||
{
|
||||
|
@ -689,19 +670,21 @@ addrFromStreamOne( CommsAddrRec* addrP, XWStreamCtxt* stream, CommsConnType typ
|
|||
break;
|
||||
case COMMS_CONN_RELAY: {
|
||||
IpRelay ip_relay = {{0}};
|
||||
stringFromStreamHere( stream, ip_relay.invite,
|
||||
sizeof(ip_relay.invite) );
|
||||
stringFromStreamHere( stream, ip_relay.hostName,
|
||||
sizeof(ip_relay.hostName) );
|
||||
ip_relay.ipAddr = stream_getU32( stream );
|
||||
ip_relay.port = stream_getU16( stream );
|
||||
if ( version >= STREAM_VERS_DICTLANG ) {
|
||||
ip_relay.seeksPublicRoom = stream_getBits( stream, 1 );
|
||||
ip_relay.advertiseRoom = stream_getBits( stream, 1 );
|
||||
}
|
||||
if ( version < STREAM_VERS_NORELAY ) {
|
||||
stringFromStreamHere( stream, ip_relay.invite,
|
||||
sizeof(ip_relay.invite) );
|
||||
stringFromStreamHere( stream, ip_relay.hostName,
|
||||
sizeof(ip_relay.hostName) );
|
||||
ip_relay.ipAddr = stream_getU32( stream );
|
||||
ip_relay.port = stream_getU16( stream );
|
||||
if ( version >= STREAM_VERS_DICTLANG ) {
|
||||
ip_relay.seeksPublicRoom = stream_getBits( stream, 1 );
|
||||
ip_relay.advertiseRoom = stream_getBits( stream, 1 );
|
||||
}
|
||||
#ifdef XWFEATURE_RELAY
|
||||
XP_MEMCPY( &addrP->u.ip_relay, &ip_relay, sizeof(ip_relay) );
|
||||
XP_MEMCPY( &addrP->u.ip_relay, &ip_relay, sizeof(ip_relay) );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
|
@ -1069,14 +1052,18 @@ addrToStreamOne( XWStreamCtxt* stream, CommsConnType typ,
|
|||
stream_putU16( stream, addrP->u.ip.port_ip );
|
||||
break;
|
||||
case COMMS_CONN_RELAY:
|
||||
if ( stream_getVersion( stream ) < STREAM_VERS_NORELAY ) {
|
||||
IpRelay ip_relay = {{0}};
|
||||
#ifdef XWFEATURE_RELAY
|
||||
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 );
|
||||
ip_relay = addrP->u.ip_relay;
|
||||
#endif
|
||||
stringToStream( stream, ip_relay.invite );
|
||||
stringToStream( stream, ip_relay.hostName );
|
||||
stream_putU32( stream, ip_relay.ipAddr );
|
||||
stream_putU16( stream, ip_relay.port );
|
||||
stream_putBits( stream, 1, ip_relay.seeksPublicRoom );
|
||||
stream_putBits( stream, 1, ip_relay.advertiseRoom );
|
||||
}
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
stringToStream( stream, addrP->u.sms.phone );
|
||||
|
@ -1102,10 +1089,13 @@ void
|
|||
addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addrP )
|
||||
{
|
||||
stream_setVersion( stream, CUR_STREAM_VERS );
|
||||
stream_putU8( stream, addrP->_conTypes );
|
||||
XP_ASSERT( CUR_STREAM_VERS >= STREAM_VERS_NORELAY );
|
||||
XP_U16 conTypes = addrP->_conTypes;
|
||||
types_rmType( &conTypes, COMMS_CONN_RELAY );
|
||||
stream_putU8( stream, conTypes );
|
||||
|
||||
CommsConnType typ;
|
||||
for ( XP_U32 st = 0; addr_iter( addrP, &typ, &st ); ) {
|
||||
for ( XP_U32 st = 0; types_iter( conTypes, &typ, &st ); ) {
|
||||
addrToStreamOne( stream, typ, addrP );
|
||||
}
|
||||
}
|
||||
|
@ -1269,6 +1259,7 @@ augmentSelfAddr( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* addr )
|
|||
setDoHeartbeat( comms );
|
||||
#endif
|
||||
if ( addingRelay ) {
|
||||
XP_ASSERT(0);
|
||||
sendConnect( comms, xwe
|
||||
#ifdef XWFEATURE_RELAY
|
||||
, XP_TRUE
|
||||
|
@ -3490,12 +3481,16 @@ augmentChannelAddr( CommsCtxt* comms, AddressRecord* const rec,
|
|||
const CommsAddrRec* addr, XWHostID hostID )
|
||||
{
|
||||
augmentAddrIntrnl( comms, &rec->addr, addr, XP_TRUE );
|
||||
#ifdef XWFEATURE_RELAY
|
||||
if ( addr_hasType( &rec->addr, COMMS_CONN_RELAY ) ) {
|
||||
if ( 0 != hostID ) {
|
||||
rec->rr.hostID = hostID;
|
||||
XP_LOGFF( "set hostID for rec %p to %d", rec, hostID );
|
||||
}
|
||||
}
|
||||
#else
|
||||
XP_USE(hostID);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
CommsConnType typ;
|
||||
|
|
|
@ -166,11 +166,6 @@ void comms_reset( CommsCtxt* comms, XWEnv xwe, XP_Bool isServer
|
|||
#endif
|
||||
);
|
||||
void comms_resetSame( CommsCtxt* comms, XWEnv xwe );
|
||||
void comms_transportFailed( CommsCtxt* comms,
|
||||
#ifdef XWFEATURE_RELAY
|
||||
XWEnv xwe,
|
||||
#endif
|
||||
CommsConnType failed );
|
||||
|
||||
void comms_destroy( CommsCtxt* comms, XWEnv xwe );
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#define MAX_COLS MAX_ROWS
|
||||
#define MIN_COLS 11
|
||||
|
||||
#define STREAM_VERS_NORELAY 0x22
|
||||
#define STREAM_VERS_MSGTIMESTAMP 0x21
|
||||
#define STREAM_VERS_GI_ISO 0x20
|
||||
#define STREAM_VERS_SMALLCOMMS 0x1F
|
||||
|
@ -96,7 +97,7 @@
|
|||
#define STREAM_VERS_405 0x01
|
||||
|
||||
/* search for FIX_NEXT_VERSION_CHANGE next time this is changed */
|
||||
#define CUR_STREAM_VERS STREAM_VERS_MSGTIMESTAMP
|
||||
#define CUR_STREAM_VERS STREAM_VERS_NORELAY
|
||||
|
||||
typedef struct XP_Rect {
|
||||
XP_S16 left;
|
||||
|
|
|
@ -248,8 +248,6 @@ p_stringFromStream( MPFORMAL XWStreamCtxt* stream
|
|||
return str;
|
||||
} /* makeStringFromStream */
|
||||
|
||||
/* FIX_NEXT_VERSION_CHANGE: use stream_getU32VL() for length so string can be
|
||||
* larger than 256 bytes */
|
||||
XP_U16
|
||||
stringFromStreamHereImpl( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen
|
||||
#ifdef DEBUG
|
||||
|
@ -257,7 +255,10 @@ stringFromStreamHereImpl( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen
|
|||
#endif
|
||||
)
|
||||
{
|
||||
XP_U16 len = stream_getU8( stream );
|
||||
XP_U16 version = stream_getVersion( stream );
|
||||
|
||||
XP_U32 len = version < STREAM_VERS_NORELAY ? stream_getU8( stream )
|
||||
: stream_getU32VL( stream );
|
||||
if ( len > 0 ) {
|
||||
if ( buflen <= len ) {
|
||||
XP_LOGFF( "BAD: buflen %d < len %d (from %s(), line %d)", buflen, len, func, line );
|
||||
|
@ -276,14 +277,20 @@ stringFromStreamHereImpl( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen
|
|||
void
|
||||
stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str )
|
||||
{
|
||||
XP_U16 len = str == NULL? 0: XP_STRLEN( str );
|
||||
if ( len > 0xFF ) {
|
||||
XP_LOGFF( "truncating string '%s', dropping len from %d to %d",
|
||||
str, len, 0xFF );
|
||||
XP_ASSERT(0);
|
||||
len = 0xFF;
|
||||
XP_U16 version = stream_getVersion( stream );
|
||||
|
||||
XP_U32 len = str == NULL? 0: XP_STRLEN( str );
|
||||
if ( version < STREAM_VERS_NORELAY ) {
|
||||
if ( len > 0xFF ) {
|
||||
XP_LOGFF( "truncating string '%s', dropping len from %d to %d",
|
||||
str, len, 0xFF );
|
||||
XP_ASSERT(0);
|
||||
len = 0xFF;
|
||||
}
|
||||
stream_putU8( stream, (XP_U8)len );
|
||||
} else {
|
||||
stream_putU32VL( stream, len );
|
||||
}
|
||||
stream_putU8( stream, (XP_U8)len );
|
||||
stream_putBytes( stream, str, len );
|
||||
} /* putStringToStream */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue