mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
Merge branch 'relay_proxy' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into relay_proxy
This commit is contained in:
commit
5d9989eb1b
5 changed files with 55 additions and 28 deletions
|
@ -1254,15 +1254,18 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
|
|||
cookieID, srcID, destID );
|
||||
/* If these values don't check out, drop it */
|
||||
|
||||
consumed = destID != comms->r.myHostID;
|
||||
/* it's ok for cookieID not to match */
|
||||
if ( !consumed ) {
|
||||
if ( COMMS_RELAYSTATE_ALLCONNECTED == comms->r.relayState ) {
|
||||
consumed = cookieID != comms->r.cookieID;
|
||||
} else {
|
||||
XP_ASSERT( COMMS_RELAYSTATE_RECONNECTED == comms->r.relayState ); /* this is firing */
|
||||
}
|
||||
XP_ASSERT( COMMS_RELAYSTATE_ALLCONNECTED == comms->r.relayState
|
||||
|| COMMS_RELAYSTATE_CONNECTED == comms->r.relayState
|
||||
|| COMMS_RELAYSTATE_RECONNECTED == comms->r.relayState );
|
||||
|
||||
if ( destID == comms->r.myHostID ) { /* When would this not happen? */
|
||||
consumed = XP_FALSE;
|
||||
} else if ( cookieID == comms->r.cookieID ) {
|
||||
XP_LOGF( "%s: keeping message though hostID not what expected (%d vs %d)",
|
||||
__func__, destID, comms->r.myHostID );
|
||||
consumed = XP_FALSE;
|
||||
}
|
||||
|
||||
if ( consumed ) {
|
||||
XP_LOGF( "%s: rejecting data message", __func__ );
|
||||
} else {
|
||||
|
|
|
@ -4,16 +4,25 @@ NGAMES=${NGAMES:-1}
|
|||
NROOMS=${NROOMS:-1}
|
||||
HOST=${HOST:-localhost}
|
||||
PORT=${PORT:-10997}
|
||||
TIMEOUT=${TIMEOUT:-1000}
|
||||
DICT=${DICT:-dict.xwd}
|
||||
TIMEOUT=${TIMEOUT:-$((NGAMES*60))}
|
||||
DICTS=${DICTS:-dict.xwd}
|
||||
SAVE_GOOD=${SAVE_GOOD:-YES}
|
||||
|
||||
declare -a DICTS_ARR
|
||||
for DICT in $DICTS; do
|
||||
DICTS_ARR[${#DICTS_ARR[*]}]=$DICT
|
||||
done
|
||||
|
||||
NAMES=(UNUSED Brynn Ariela Kati Eric)
|
||||
|
||||
LOGDIR=$(basename $0)_logs
|
||||
[ -d $LOGDIR ] && mv $LOGDIR /tmp/${LOGDIR}_$$
|
||||
mkdir -p $LOGDIR
|
||||
DONEDIR=$LOGDIR/done
|
||||
mkdir -p $DONEDIR
|
||||
|
||||
if [ "$SAVE_GOOD" = YES ]; then
|
||||
DONEDIR=$LOGDIR/done
|
||||
mkdir -p $DONEDIR
|
||||
fi
|
||||
|
||||
USE_GTK=${USE_GTK:-FALSE}
|
||||
|
||||
|
@ -29,7 +38,7 @@ fi
|
|||
usage() {
|
||||
echo "usage: [env=val *] $0" 1>&2
|
||||
echo " current env variables and their values: " 1>&2
|
||||
for VAR in NGAMES NROOMS USE_GTK TIMEOUT HOST PORT DICT; do
|
||||
for VAR in NGAMES NROOMS USE_GTK TIMEOUT HOST PORT DICTS SAVE_GOOD; do
|
||||
echo "$VAR:" $(eval "echo \$${VAR}") 1>&2
|
||||
done
|
||||
exit 0
|
||||
|
@ -50,14 +59,19 @@ while [ -n "$1" ]; do
|
|||
shift
|
||||
done
|
||||
|
||||
declare -A CHECKED_ROOMS
|
||||
check_room() {
|
||||
ROOM=$1
|
||||
NUM=$(echo "SELECT COUNT(*) FROM games WHERE ntotal!=sum_array(nperdevice) AND room='$ROOM'" |
|
||||
psql -q -t xwgames)
|
||||
NUM=$((NUM+0))
|
||||
if [ "$NUM" -gt 0 ]; then
|
||||
echo "There are unconsummated games in $ROOM in the DB. This test will fail if you don't remove them."
|
||||
exit 0
|
||||
if [ -z "${CHECKED_ROOMS[$ROOM]}" ]; then
|
||||
NUM=$(echo "SELECT COUNT(*) FROM games WHERE ntotal!=sum_array(nperdevice) AND room='$ROOM'" |
|
||||
psql -q -t xwgames)
|
||||
NUM=$((NUM+0))
|
||||
if [ "$NUM" -gt 0 ]; then
|
||||
echo "$ROOM in the DB has unconsummated games. Remove them."
|
||||
exit 0
|
||||
else
|
||||
CHECKED_ROOMS[$ROOM]=1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -67,6 +81,7 @@ build_cmds() {
|
|||
ROOM=ROOM_$((GAME % NROOMS))
|
||||
check_room $ROOM
|
||||
NDEVS=$(($RANDOM%3+2))
|
||||
DICT=${DICTS_ARR[$((GAME%${#DICTS_ARR[*]}))]}
|
||||
|
||||
unset OTHERS
|
||||
for II in $(seq 2 $NDEVS); do
|
||||
|
@ -103,9 +118,14 @@ close_device() {
|
|||
fi
|
||||
unset PIDS[$ID]
|
||||
unset CMDS[$ID]
|
||||
[ -f ${FILES[$ID]} ] && mv ${FILES[$ID]} $MVTO
|
||||
if [ -n "$MVTO" ]; then
|
||||
[ -f ${FILES[$ID]} ] && mv ${FILES[$ID]} $MVTO
|
||||
mv ${LOGS[$ID]} $MVTO
|
||||
else
|
||||
rm -f ${FILES[$ID]}
|
||||
rm -f ${LOGS[$ID]}
|
||||
fi
|
||||
unset FILES[$ID]
|
||||
mv ${LOGS[$ID]} $MVTO
|
||||
unset LOGS[$ID]
|
||||
}
|
||||
|
||||
|
@ -176,10 +196,11 @@ print_stats() {
|
|||
:
|
||||
}
|
||||
|
||||
echo "*********$0 starting: $(date)**************"
|
||||
|
||||
build_cmds
|
||||
run_cmds
|
||||
print_stats
|
||||
|
||||
wait
|
||||
echo -n "$0 done: "
|
||||
date
|
||||
echo "*********$0 finished: $(date)**************"
|
||||
|
|
|
@ -233,8 +233,9 @@ DBMgr::ClearCIDs( void )
|
|||
void
|
||||
DBMgr::PublicRooms( int lang, int nPlayers, int* nNames, string& names )
|
||||
{
|
||||
const char* fmt = "SELECT room, nTotal-sum_array(nPerDevice)"
|
||||
" FROM " GAMES_TABLE
|
||||
const char* fmt = "SELECT room, nTotal-sum_array(nPerDevice),"
|
||||
" round( extract( epoch from age('now', ctime)))"
|
||||
" FROM " GAMES_TABLE
|
||||
" WHERE pub = TRUE"
|
||||
" AND lang = %d"
|
||||
" AND nTotal>sum_array(nPerDevice)"
|
||||
|
@ -250,6 +251,8 @@ DBMgr::PublicRooms( int lang, int nPlayers, int* nNames, string& names )
|
|||
names.append( PQgetvalue( result, ii, 0 ) );
|
||||
names.append( "/" );
|
||||
names.append( PQgetvalue( result, ii, 1 ) );
|
||||
names.append( "/" );
|
||||
names.append( PQgetvalue( result, ii, 2 ) );
|
||||
names.append( "\n" );
|
||||
}
|
||||
PQclear( result );
|
||||
|
|
|
@ -53,7 +53,7 @@ class DBMgr {
|
|||
void ClearCID( const char* connName );
|
||||
void RecordSent( const char* const connName, int nBytes );
|
||||
|
||||
/* Return list of roomName/playersStillWanted for open public games
|
||||
/* Return list of roomName/playersStillWanted/age for open public games
|
||||
matching this language and total game size. Will probably want to cache
|
||||
lists locally and only update them every few seconds to avoid to many
|
||||
queries.*/
|
||||
|
|
|
@ -41,8 +41,8 @@ cid integer
|
|||
,nPerDevice INTEGER[]
|
||||
,seeds INTEGER[]
|
||||
,nSent INTEGER DEFAULT 0
|
||||
,ctime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
,mtime TIMESTAMP
|
||||
,ctime TIMESTAMP (0) DEFAULT CURRENT_TIMESTAMP
|
||||
,mtime TIMESTAMP (0)
|
||||
);
|
||||
EOF
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue