Commit graph

212 commits

Author SHA1 Message Date
Eric House
b5714e9d14 improve API: hide special numbers inside implementation 2013-07-12 08:24:44 -07:00
Eric House
5814febad5 better client token logging 2013-07-10 23:13:50 -07:00
Eric House
d50c808f96 Merge branch 'android_branch' into gtk_multigame
Conflicts:
	xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java
	xwords4/common/comms.c
	xwords4/linux/cursesmain.c
	xwords4/linux/cursesmain.h
	xwords4/linux/gtkmain.c
	xwords4/linux/gtkmain.h
	xwords4/linux/linuxmain.c
	xwords4/linux/main.h
	xwords4/linux/scripts/discon_ok2.sh
	xwords4/relay/xwrelay.cpp

(Note: The curses app crashes on exit with mempool assertions, but that's a problem before the merge.)
2013-07-09 07:18:00 -07:00
Eric House
e8022d44ea correctly parse hid from relayID, fixing assertion failure. I'm not
sure how it ever worked....
2013-07-05 21:26:17 -07:00
Eric House
a93eb4a511 fix assertion failure: log and drop packet when hid outside of accepted range. 2013-07-05 08:01:31 -07:00
Eric House
0a794f390f fix off-by-one error leading to malformed queries 2013-06-28 18:47:11 -07:00
Eric House
9138cd15b7 fix problems with devices reconnecting when their ACKs didn't arrive
and their slots are empty or have been reassigned: basically we check
if a device goes where it expects, and if not treat it as a new
connection rather than a reconnect, meaning its hostid may change.
Existing device code seems ok with that -- and at any rate I don't
think ACKs get dropped much in the wild.
2013-06-26 00:38:34 -07:00
Eric House
519f90a69a go with non-blocking sockets for tcp connections, adding the ability
to reassemble packets that arrive in separate recv() calls.
2013-06-24 07:09:57 -07:00
Eric House
5dadbfdad3 drop messages without enough delivery info 2013-06-22 06:01:42 -07:00
Eric House
2a35fac1e8 rather than invalidating socket in AddrRec when it's closed, add a
timestamp set when it's opened.  Older copies with the same socket can
be tested against the cannonical copy maintained by tpool and sending
avoided when the timestamp shows the endpoint has likely changed.
Change tpool's list of sockets to a map for faster lookup, and get rid
of similar structure in udpqueue.
2013-06-21 06:05:26 -07:00
Eric House
eccd31472f fix crash when udp not in use 2013-05-27 16:17:58 -07:00
Eric House
d74814a806 part of previous (merge) commit that got left out -- files not saved. 2013-05-09 06:33:19 -07:00
Eric House
7d8cddb31f Merge branch 'android_branch' into gtk_multigame
Conflicts:
	xwords4/linux/gtkmain.c
	xwords4/linux/linuxmain.c
	xwords4/relay/xwrelay.cpp
2013-05-08 07:37:55 -07:00
Eric House
eafac8724e don't stop processing message referring to multiple games as soon as
one of them can't be found.
2013-02-08 20:58:09 -08:00
Eric House
5e0fd89c9e update with all relay/ changes from gtk_multigame. This is what the
live relay's running anyway.
2013-02-04 06:08:39 -08:00
Eric House
9ee16adc3a add support for udp-based delete and anonymous (relay-provided) regIDs 2013-01-29 07:38:07 -08:00
Eric House
4aee75aeab ack all packets from clients; log acks. This is for debugging and may
not need to stay.
2013-01-27 21:26:27 -08:00
Eric House
82dc986c79 remove bad asserts and unused variable 2013-01-26 21:49:17 -08:00
Eric House
a9b459ea2e log rather than assert 2013-01-26 21:16:48 -08:00
Eric House
336e3cd289 handle all three types of message in a single thread, punting all
synchronization issues to a future point where the load demands it.
2013-01-26 11:54:48 -08:00
Eric House
8cb0a8a7a7 fix crash on startup (as done already on gtk branch) 2013-01-26 09:23:44 -08:00
Eric House
036c908b72 remove token from XWPDEV_HAVEMSGS message 2013-01-24 19:33:33 -08:00
Eric House
c465a0bb0c add loop to print when packets haven't been ack'd 2013-01-24 07:43:24 -08:00
Eric House
ce7cdab3f0 add msgid and acking to protocol -- maybe for debugging only. 2013-01-23 07:40:52 -08:00
Eric House
90b8f966f6 comment out unnecessary assert 2013-01-21 19:40:56 -08:00
Eric House
991cc8f04c fail in main mode if udp socket not set 2013-01-20 21:03:43 -08:00
Eric House
016b16a8b2 change relay alert message format to length-plus-string rather than
null-terminated for easier handling on the java end.
2013-01-20 13:06:34 -08:00
Eric House
9023440a88 reply with alert to any connection attempt when in maint mode 2013-01-20 10:03:20 -08:00
Eric House
b768d8fccc fall through to using hard-coded maxsocks value 2013-01-20 09:22:35 -08:00
Eric House
65e9789c3f add mainentance mode, triggered by a commandline flag, that does
nothing but loop waiting for connections on the UDP socket and sending
them back the error message provided on the commandline.
2013-01-19 15:17:51 -08:00
Eric House
63d3f70cdf more changes to storage and fetching of messages and to protocol so
presence of messages is reported on connect (as are bad relayIDs).
Now a game with a robot player in a "closed" game can continue.  Once
the next set of linux-side chances is committed.
2013-01-19 14:34:04 -08:00
Eric House
3984d85795 oops -- prev checkin didn't compile 2013-01-18 07:12:26 -08:00
Eric House
1c5fef6a38 relay improvements for UDP connection: record addresses, prepare to
run in separate thread, etc.
2013-01-18 07:10:47 -08:00
Eric House
7fec736947 add udp socket and protocol for use over it so that a device can
manage a single connection to the relay for all of its games.  Works
so far to the extent that the game's playable with all boards on the
same device (with checkins about to come) as long as all boards are
open.  (Client doesn't handle opening closed games yet.)
2013-01-15 18:41:17 -08:00
Eric House
98679c8363 cleanup: better encapsulation for AddrInfo 2013-01-13 10:14:06 -08:00
Eric House
c567647a8d get rid of mapping of socket->game_connection, which will not work
once UDP sockets and/or per-device (not per-game) connections come
along.  Lots of changes, most not involving code flow but a couple
that did.  So far two gtk games can connect and exchange moves.
Haven't tested reconnection or store-and-forward.
2013-01-12 16:09:24 -08:00
Eric House
2ccc297463 make number of sockets at which we assert/reboot configurable so tests
can be done with large numbers of clients.
2013-01-10 21:10:18 -08:00
Eric House
ad78129e74 changes made over the past couple of months toward tracking an
apparent thread leak.
2013-01-02 21:12:42 -08:00
Eric House
f1ee77882b Send devid with RECONN as well as CONN so games present when device
upgrades can also use GCM.  Tested on relay but not device.
2012-11-09 06:54:12 -08:00
Eric House
af89047969 treat an empty devID string as TYPE_NONE regardless of what the client claims. 2012-11-07 22:03:58 -08:00
Eric House
59937b8514 modify how devids are handled on the relay and the protocol through
which they're communicated to the device.  Device is expected to have
a platform-specific notion of ID which the relay stores in a new
devices table and indexes with a 32-bit number which is returned to
the device -- which is encouraged but not required to use it in lieu
of the longer ID in future communications.  Modify linux client and
test script to use the relay-supplied id.  Some of this is commented
out for now.
2012-11-03 10:58:01 -07:00
Eric House
3469975d2a add, still disabled by compile-time flags, code to transmit device ID
(e.g. ID Android devices get via GCM) to relay and to associate it
there with messages that need to be delivered.
2012-10-30 07:01:47 -07:00
Eric House
0f9500cea3 comment out unused param/variable 2012-10-19 17:53:15 -07:00
Eric House
866aeb2387 change relay connect message format to include client version (meaning
of which is TBD).  When a new-version client connects, store the value
it's passed. At first this will let me track how quickly people
upgrade.  Later I can use it to let different clients have different
formats to their messages e.g. to proxy.
2012-01-26 05:43:54 -08:00
Eric House
caa40fa023 store most recent IP address each device has come in on. Requires new
column in db.  Not really used yet but interesting to watch....
2012-01-04 18:14:12 -08:00
Eric House
cb04eb8840 finally got the socket leak: use keepalive ioctl to detect sockets
whose other ends have gone down without closing properly.
2011-12-21 18:18:30 -08:00
Eric House
dc42e63974 fix read_packet() logging 2011-12-02 18:55:47 -08:00
Eric House
3f5e62c9b7 remove logging 2011-12-02 18:31:05 -08:00
Andy2
d9e97d2f32 reduce logging 2011-09-30 18:10:22 -07:00
Andy2
6553546642 cleanup; add logging for debugging background packets stuff. 2011-09-30 06:36:56 -07:00
Andy2
58be931558 remove messages after sending them if they appear to have been sent
successfully.
2011-08-17 19:52:55 -07:00
Andy2
2c26fc03e3 Track messages sent via proxy and credit nsent (accumulator) if
successful.  Previously messages sent via proxy were not counted.
2011-08-17 18:09:10 -07:00
Andy2
30145deba7 add new proxy message handler for no-conn message, and feed into
existing store-and-forward system.  With this checkin a robot-vs-robot
game plays for quite a few moves without either game every loaded into
the foreground (via a BoardActivity instance on Android), with all
moves transmitted as a result of relay checks.  One of the games
refuses to open later, however, and there are certainly other bugs.
And I'm not sure what happens when a message sent no-conn (without a
cookie ID) is received in the foreground.  But this is progress.
2011-08-16 19:41:33 -07:00
Andy2
dc273c7162 fix proxy msg handling to process more than one relayID per message.
Formerly all but the first were dropped.
2011-08-15 18:27:00 -07:00
Andy2
86e3cc7286 When device reconnects to a dead game, just deny the connection with a
new error message rather than allow it as if it were a normal game
only to send a game-dead message after.  This solves the problem of
how device knows not to put up welcoming message or suggestion to
invite to a game that's suddenly missing players.  BUT: this change is
incompatible with existing versions and so needs to get pushed out
before the in-use relay can be upgraded to include this code.
2011-07-06 06:47:25 -07:00
Eric House
b4a513ce87 reduce logging; log errno on syscall failure 2011-06-29 21:38:31 -07:00
Andy2
fffcbb677e under testing I'm running up against the 1024-files-open limit and
dying with an assert.  Log something -- but still die as there's
nothing to be done in code except hope some connections don't
reconnect right away.  Fixes: 'ulimit -n' or edit 'nofile' param in
/etc/security/limits.conf on the relay host.
2011-06-27 06:20:51 -07:00
Andy2
df60ec648b Don't return new error XWRELAY_ERROR_NORECONN as devices don't have it
yet.
2011-06-24 18:32:53 -07:00
Andy2
e886a1aefe lots more changes -- another snapshot, this, rather than stuff
carefully polished and reviewed.  Shows progress, though, in getting
through tests.
2011-06-23 07:12:50 -07:00
Eric House
85d484a881 major mod to deal with devices that fail to receive ACK and then
reconnect.  I was putting both (i.e. the same device twice) in the
same game.  Now I detect this based on the seed being duplicated and
treat the device as having failed to ACK then proceed with the CONNECT
as if it were new.  Tested pretty heavily but only with two-device
games.
2011-06-20 18:13:15 -07:00
Eric House
7aeb0a4df0 make default socket timeout 5 seconds, not 20. 2011-03-31 18:13:16 -07:00
Andy2
8bb2857e63 The relay is hanging inside recv(). Use setsockopt to set a 20-second
receive (and send) timeout on all sockets accept() returns.  Sockets
that timeout should then get closed and dropped.
2011-03-12 05:13:54 -08:00
Andy2
57ec020330 change format of reply to MSG_GET: include number of messages per
device to support fetching for more than one at once.  This is
meaningless for rq as written now but a device will want to do this.
2011-01-27 06:37:36 -08:00
Eric House
63d16a99a2 turn off http view 2011-01-24 22:20:01 -08:00
Andy2
f96f4a040b add new proxy command that fetches actual messages stored for a device. 2011-01-22 12:52:26 -08:00
Eric House
725888cb6c run proxy sockets through same thread pool as game sockets. This
prevents race conditions that are turning up when I'm running multiple
threads -- by allowing me to really not be running multiple threads.
Tested with the usual script.
2011-01-20 18:14:56 -08:00
Andy2
1720fbbd50 fix parsing of relay ids by replacing separating \n with \0. 2010-11-23 17:46:16 -08:00
Eric House
b91187d6a5 test result when parsing; drop if didn't parse 2010-11-16 20:30:43 -08:00
Andy2
c6bd2125a4 java uses '/' to delimit device id, so we'll make that standard. 2010-11-15 18:27:36 -08:00
Andy2
d4e810c9cb delimiter changed 2010-11-15 06:51:05 -08:00
Eric House
528ae0c986 allow more than one device death per message 2010-11-14 15:19:38 -08:00
Andy2
0787a06eb5 accept new message from device announcing the death of a game
(including seed so it's harder to spoof); respond to that by setting a
DEAD column in the db and flagging the device as gone.  Notify any
connected device of the fact.  Refuse to accept new connections to
that game.  As already-connected devices reconnect, allow them to do
so but send a new status message that their game is dead.  Not heavily
tested yet.
2010-11-11 06:40:50 -08:00
Andy2
2bfb26cded sleep (in thread) before closing proxy socket. This works around
problem where, on PRX_HAS_MSGS path only, device reading socket gets
EOF early though logging here confirms additional bytes have been
written.  Gross but effective.
2010-10-17 06:38:28 -07:00
Eric House
0d1542ca9d tweaks to logging 2010-10-12 05:18:44 -07:00
Eric House
1ff4d67bc0 block TERM and INT from all but the main thread. (Pretty much untested; doesn't fix hang-on-SIGINT.) 2010-10-04 20:03:00 -07:00
Andy2
89f967a016 pass remaining reconnect params in case connName's missing from db.
Should only matter if the relay's db's been deleted.
2010-10-04 18:39:26 -07:00
Andy2
978fa010f1 commented-out sleep positioned to give download progress time to come up. 2010-09-28 18:35:33 -07:00
Andy2
b0c6e6da9c add db method to count messages for connName/hid pairs and handle
query using it.
2010-09-24 05:50:02 -07:00
Andy2
1d0c207521 add test command for proxy feature to fetch for connNames whether
there are messages pending for them.  Not handled yet on relay.
2010-09-21 18:28:31 -07:00
Andy2
e7b5923883 finish first pass at sending open public room names -- but with actual
list harvesting stubbed out.
2010-09-21 06:27:31 -07:00
Andy2
a549ade1fa a bit more work on rc 2010-09-20 18:31:17 -07:00
Andy2
df1ec1628a replace killSocket(), which jumped right into crefmgr and could get
ahead of processing data arrived on the same socket, with EnqueueKill
that adds to same queue from which data's taken.  So if device dies
immediately after sending data there won't be a race between closing
the cref (if this is the last open socket) and handling the data.  I'm
still dying with assert fails when running 100 games at once, but much
less frequently
2010-09-18 08:47:56 -07:00
Andy2
9c8889b429 get rid of mutex guarding reconnect. There shouldn't be any need
since game slots are already assigned, and it's slowing down
reconnects in their race with kills.
2010-09-18 05:07:23 -07:00
Eric House
54d268b718 pass through to database whether room is public 2010-09-14 21:20:11 -07:00
Andy2
3b5b5f0241 factor dbmgr code; add and call method to zero CIDs on boot. 2010-09-15 01:14:28 -07:00
Andy2
821e4d9c39 add ACK to protocol, returned by device after gets connName on initial
connection.  Space is held for device on assumption ack will come
back, then given up if it fails.
2010-09-14 13:54:52 -07:00
Andy2
463e9c3ccf pass langCode in reconnect case too 2010-09-11 01:23:39 -07:00
Andy2
20312144dd tons of changes, still rough, snapshoted here: a gtk device vs device
game works to completion with both signing up as guests (no -s) with
one local and one remote player (identical commandlines.)  Not yet
tested: if any signs up as a host, reconnecting rather than
connecting, etc.  This is just a snapshot.
2010-09-10 01:30:40 -07:00
Andy2
33d60452a3 fork a thread to handle proxy connects. Later may want to use thread
pool as for game threads.
2010-08-23 18:52:52 -07:00
Andy2
a34ccb424f device now passes list of "relayID"s, consisting of connName plus
device id, to relay, one for each stored game that's communicating via
the relay.  Relay parses out each relayID.  Next relay can use these
to look up whether messages are available and reply with that, and
device can put up a notification.
2010-08-22 12:16:57 -07:00
Andy2
56b6a425e2 proxy now writes one byte to relay and reads one byte reply. 2010-08-19 18:34:28 -07:00
Andy2
416b379781 add second class of socket to be listened on, meant for per-device
rather than per-game connection, and when adding connected sockets to
active set track the type.
2010-08-12 06:42:33 -07:00
Eric House
8e5abb189b add mutex for reconns too; log socket and ip addr connecting on it 2010-07-15 18:14:44 -07:00
Eric House
8aaaa06bcb identify rev number as from git 2010-06-05 07:25:24 -07:00
eehouse
4ed87fecb4 add once-per-day date line to logs since they can span weeks now. 2010-05-01 02:48:47 +00:00
ehouse
26469d734c Modify state machine and return new error codes to force host to
connect first, guests second, with clear error messages if the order's
wrong.  This seems to make it simpler for users to get a connection
right.  Code holding multiple games worth of hosts and guests in a
cref is gone.
2009-12-04 08:03:27 +00:00
ehouse
2d4ae3e44a When forwarding message, lookup cref by socket if cookieID == 0, as
can be the case when through to a non-all-connected game.
2009-11-08 21:32:36 +00:00
ehouse
11b586cd4b lookup hearbeat recipient by socket rather then cookieID since
cookieID isn't always correct until later
2009-11-02 00:45:54 +00:00
ehouse
0e43675abf Address problems matching [re]connections to games: first, go back to
setting connName when all in a game are present.  Second, have every
host include in connections a random number.  That number is made part
of the connName and in general used to test whether a host belongs in
a particular game.  Add this "seed" to web interface.  Means new
versions for relay protocol and game stream format.  Latter is handled
correctly so older games can be opened.
2009-09-26 14:37:49 +00:00
ehouse
d5d20293ce print log timestamps with padding 0s for better sorting 2009-09-15 12:54:40 +00:00