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