Commit graph

420 commits

Author SHA1 Message Date
Eric House
2dfc9129f3 add timestamp to saved msgs, modify mqtt header to include later
I want receiver to know when message was originally created. This adds
timestamp to messages and passes it via send proc. Client needs to
send it where possible. So far, MQTT format can't include it without
change, so I'm adding a new proto version. This change can read the
new version. Once that's well-enough distributed I can start sending
using it. Other transmission types than MQTT are for later.
2022-06-29 12:34:27 -07:00
Eric House
df1606c8fb use ifdef to remove relay-only params 2022-05-15 12:10:37 -07:00
Eric House
babccc9e21 logf -> logff 2022-05-10 20:54:25 -07:00
Eric House
63b0d7c2fb always clear initial address and add MQTT 2022-05-10 20:54:25 -07:00
Eric House
0eaa71fce6 remove relay from linux client via conditional compile 2022-05-10 20:54:25 -07:00
Eric House
1c644d7af0 fix wasm build 2022-03-14 07:42:47 +01:00
Eric House
2175600190 use new webapi to fetch mqttid to replace relayid
And drop relay once we have it. Makes perfecting RelayService backoff
less an issue.
2022-02-12 13:27:24 -08:00
Eric House
4bfcf2afb4 deal better with old relay games
Attempting to stop calling the relay, but to let relay-only games finish
and issue invitations. Big changes are that relay is removed from games
if they have viable mqtt connections, and relay timers fire less often,
then eventually stop getting set if there are no active games. Result is
that a relay-only invitation won't likely be received, but there should
be few or none of those now.
2022-02-10 08:28:34 -08:00
Eric House
d9b1fb4df6 cleanup -- no behavior change 2022-01-10 08:42:41 -08:00
Eric House
8095a0da54 fix uninitialized memory getting treated as a mqtt address
augmentAddrIntrnl() sets the has-mqtt bit in comms->addr but not the
address data (has none). If that address had been loaded from stream
the address bits will be random, not 0, and so get treated as an
address.
2022-01-08 18:55:53 -08:00
Eric House
a8963c952e use variable length ints to store msgID and len 2022-01-04 11:12:58 -08:00
Eric House
a85f5df4e3 another tweak: make version imply format 2021-12-29 07:35:43 -08:00
Eric House
b67ab9e32a refactor, and make msgids variable-length 2021-12-28 20:59:15 -08:00
Eric House
140e1210cc cleanup 2021-12-22 13:01:22 -08:00
Eric House
2b7daf067d shrink the comms header
Sending in 32 bits what can probably fit in 8 -- twice -- is dumb. As is
sending the gameID (as connID) when it's already known. In 2016 I added
a fixed marker, so I can count on all current code sending that. If I
fail to find that, I know the sender is new (current release or better.)
In that case, use 12 bits instead of 32 for two fields, drop the marker
and the connID. Result is that an ACK's size, including MQTT headers,
drops from 28 bytes to 21.
2021-12-21 16:34:04 -08:00
Eric House
0fa43a7394 remove duplicate code 2021-12-16 08:47:12 -08:00
Eric House
14c879a752 fix so ack format is same for DEBUG and RELEASE builds
Was appending garbage to ACKs that, somehow, receiver didn't
mind. Fix. And use the new BEEF format for linux too.
2021-12-15 10:03:09 -08:00
Eric House
e3ba122ca0 fix to compile with XWFEATURE_RELAY undefined
Didn't change the stream format. That will wait!
2021-03-19 18:51:34 -07:00
Eric House
87621c3b51 fix compile 2021-03-19 17:26:48 -07:00
Eric House
4612ca70c7 snapshot: message exchange mostly works 2021-03-19 14:26:18 -07:00
Eric House
d5546b484d cleanup (mostly non-DBG compile errors) 2021-03-19 13:03:39 -07:00
Eric House
3f6f16c2f4 add script to print comms msg exchange details 2021-03-19 12:50:32 -07:00
Eric House
ca88d9c0bf backout ack change for now 2021-03-12 07:16:28 -08:00
Eric House
f947382f4c in comms, send ack on receipt of duplicate msg 2021-03-11 21:43:26 -08:00
Eric House
5d4fd0e58b don't dispose gi before game
gathering players was failing because disposed gi was pointing at
garbage. I'm lucky it didn't segfault.
2020-10-23 19:03:26 -07:00
Eric House
af37fb45f7 Rewrite BT comms to not use a Service
It's simpler this way, and I'm tired of stuff not happening because the
OS chooses not to schedule e.g. an invitation send for minutes. Goal's
to be running BluetoothServerSocket.accept() as much as possible when
there are active BT games in play OR when the game's in the foreground.
If that's happening, sent invitations and moves will be received when
users expect. When there's no traffic and app isn't being brought to
foreground, backoff will ensure I don't try to run accept() too often.

FWIW, BTLE seems to offer a better way to do this (to have an app be
responsive to incoming invitations when it hasn't run in the foreground
in a while), but it requires users to accept FINE_LOCATION
permission. I'm hoping I can make this work to avoid asking for that
permission.
2020-10-21 21:10:09 -07:00
Eric House
b0c1c5ac1b don't deref ptr after free(); cleanup 2020-09-26 11:00:11 -07:00
Eric House
fad252d8c0 use created stamp to decide between conflicting addresses
Not at all tested, but now the game's timestamp is kept and passed in to
where it can be used to determine, e.g., which of two Bluetooth device
names to keep for a given opponent.
2020-09-26 09:48:35 -07:00
Eric House
c4b55385a3 add creation timestamp to game struct
Address resolution will want to know which address is older. Game
creation is a good enough proxy for that, so add it in a cross-platform
way.
2020-09-26 09:48:35 -07:00
Eric House
f0f2a598e0 make up new name rather than drop new player 2020-09-26 09:48:35 -07:00
Eric House
49909c84d6 make known-player stuff conditional
and ifdefs to C and BuildConfig flag to java so the feature can be
hidden in release builds until it's ready.
2020-09-26 09:48:35 -07:00
Eric House
736c9f3503 harvest players on open; save and make available
Got as far as having gtk client display list of previously harvested
known players to be invited. Their addresses, or at least mqtt ids are
saved. Next is to actually invite one.
2020-09-26 09:48:35 -07:00
Eric House
8072a0c629 write 0 where flags will be
unused for now.
2020-09-22 10:56:06 -07:00
Eric House
e26fd23df1 add addrType to comms' main addr when added to channel
I'm fixing android client not showing stats for or allowing to disable
mqtt after it's added automatically to a game that connects
otherwise. Problem was that only the channel got the mqtt address
flag. So now add the flag for any type that's added.
2020-09-10 15:11:22 -07:00
Eric House
93a98820e1 cleanup 2020-09-06 14:06:51 -07:00
Eric House
8c3c1b59f6 cleanup 2020-09-05 17:52:00 -07:00
Eric House
5c150d2f58 don't save isServer in comms
Pass it in so don't have to keep two state locations in sync
2020-08-25 22:27:43 -07:00
Eric House
b0f7176b6c fix relay game failure to change roles
If a configured-as-host game joined an existing game the relay would
make it a guest. The android util_ callback for that change was only
implemented in BoardDelegate and so the change was dropped unless the
game was open/visible. Because comms recorded the change, though, the
callback would never be called again and so the game never learned to
behave as a guest and never registered: permanent failure to join game!
Implemented with a new server state so initClientConnection can be
called from server_do() instead of inside comms while processing an
incoming packet.
2020-08-25 14:53:33 -07:00
Eric House
d10d2597d4 add logging; cleanup
I'm chasing a relay problem that's hard to repro and need more info when
it's happened. (These won't show up in shipping builds.)
2020-08-24 17:02:49 -07:00
Eric House
a7acc37395 adding logging 2020-08-24 12:10:25 -07:00
Eric House
99d47fd067 log number of channels 2020-08-23 20:09:21 -07:00
Eric House
55c50ca8b6 don't try to send via mqtt when to dest address 2020-08-23 19:08:29 -07:00
Eric House
0f61a6d9f4 pass and use mqttid in game-connection code
To avoid inviteless relay games not having an mqtt channel (and so
yielding a crappy experience) pass the mqtt devid when device registers
and when server replies with all-here.
2020-08-23 08:34:12 -07:00
Eric House
27e784e784 change mqtt proto
Making return address part of a header of all messages so server-side
listener can snoop.
2020-05-31 13:13:31 -07:00
Eric House
f6d7eed84d add mqtt as a new transport
This is meant to replace the relay eventually, but for now it's a new
option, like BT or SMS, to be chosen. Protocol is handled in common/
code for the first time, meaning that linux and android interact without
the need to keep two platforms in sync. Linux uses lib-mosquitto, and
Android uses eclipse's Paho client (the generic java version, not the
one that uses four-year-old Service patterns and so crashes for SDK >=
26.)
2020-05-20 13:58:53 -07:00
Eric House
182b8e0489 fix compilation where DEBUG not set 2020-04-26 13:49:54 -07:00
Eric House
88335d38f2 stop using thread->env mapping for util callbacks 2020-04-26 13:39:21 -07:00
Eric House
eb9ef738e4 remove comms/transport from using thread->env map 2020-04-26 13:39:21 -07:00
Eric House
cfaa6849b2 pass env into dict-related methods
I was getting an occasional crash using a stale env to delete a dict's
resources because the dict was cacheing the env that created it. Dumb!
Using the thread->env mapping stuff worked, but that felt risky and so I
tried just passing it in. It's safe, and involves an amount of change I
can tolerate. So likely going that way.
2020-04-26 13:39:16 -07:00
Eric House
87802150d5 fix logging macro to allow a single argument 2020-04-10 07:12:56 -07:00
Eric House
0a696cf203 cleanup 2020-04-10 07:12:56 -07:00
Eric House
8bd623d91a fix NFC
A change in how sendMsg() figured out what address types to use dropped
NFC, breaking sending on Android. Fix.
2020-03-24 15:58:06 -07:00
Eric House
5611d17849 fix so games don't stall after undo
With these changes the test script no longer produces games that don't
finish. I think they are recovering from the problems produced by one
device doing an undo while another is making a move, or other problems
produced by undo being allowed to happen on any device at any time, but
haven't analyzed the games beyond the test script's verifying that they
all finish with a Winner after all tiles are consumed.
2020-03-19 16:53:44 -07:00
Eric House
5cae732a60 fix release builds 2020-03-17 20:33:24 -07:00
katianderic
1d8bb1d0db fix Android build (requires adding new comms method) 2020-03-14 18:52:28 -07:00
katianderic
b1f7b13e78 toward fixing stalls when undo used
There are still some stalls turning up when running the test script,
especially with more than two players in a game, but but it'll be
easier to do the final debugging off my pathetic travel-only
chromebook. And things are already much better. :-)
2020-03-14 14:47:26 -07:00
katianderic
126172220f changes to fix curses app test script
especially on the 'sms' side it was broken. Now Android's broken for sure.
2020-03-14 13:43:43 -07:00
Eric House
598be04bef make curses app more like the rest
Lots of changes adding a games-list view to the app from which you
create new games, open and delete existing ones, etc. There's still
plenty that's unimplemented, but it's already more useful for testing
and development. Which is the point.
2020-01-24 09:05:16 -08:00
Eric House
0153928bcd support sending invites and moves via NFC
Use low-level NFC, a combination of emulated card and reader mode, to
work around Google's removal of "beaming" support from Android 10. App
emulates a card by declaring support in its AndroidManifest. When a game
is open that has data to send, it goes periodically into read mode. If
two devices are touched while one is in read mode and the other isn't,
they handshake and open a connection that should last until they're
separated. The devices loop, sending messages back and forth with or
without data (as available.)
2019-12-23 08:45:55 -08:00
Eric House
c7ebe6e80e add debug-only pending-msg count to connstatus display
I'm bringing this in from another branch because it'll be useful for
debugging bluetooth problems.
2019-12-10 14:42:54 -08:00
Eric House
ee9f3c36f8 fix crash opening older games
I'd forgotten that merely adding a new type changed the game's binary format.
2019-11-30 18:43:28 -08:00
Eric House
496ef73da2 cleanup and remove one bad assertion 2019-11-27 11:47:46 -08:00
Eric House
ced26e8e37 remove release-build-only warning 2019-11-27 08:44:09 -08:00
Eric House
7eaa466f78 add ability to send moves via NFC
You can now play an entire game via NFC. There's no UI though: big
question is how to make the feature "discoverable."
2019-11-23 10:53:51 -08:00
Eric House
8da3c5fc68 add comms_getPending(), and refactor to implement 2019-11-18 09:26:46 -08:00
Eric House
c69ec52502 add comms stats to conn status display (DEBUG only) 2019-11-05 08:30:38 -08:00
Eric House
685c8879c3 don't consider message received until it's processed
I think I'm seeing a bug where msg <n> is received, I record that I'm
now looking for msg <n+1>, fail to process <n> (perhaps because some
resource is temporarily unavailable?), and am now in a state where I
won't accept <n> when it's resent. This fixes this by only recording <n>
received after processing code has accepted it.
2019-11-03 08:35:56 +00:00
Eric House
96ee5bec8c start adding logging specific to comms' windowing
(Hi from Santiago)
2019-11-01 07:22:56 -07:00
Eric House
21b0815923 make msgNo reflect srcID, not channelNo
It's more useful if it's per-device unique within a game. (Just used for
debugging now, so no impact on anything.)
2019-03-18 10:55:40 -07:00
Eric House
d1881e7fc4 logging toward tracking a rare assertion failure 2019-02-26 14:33:18 -08:00
Eric House
f5c9962b66 tweak/reduce logging 2019-02-06 19:36:17 -08:00
Eric House
bdf1bd3b84 fix problems with RelayService
Darned thing was dropping packets, failing to connect games built in
response to invitations, and otherwise misbehaving. First was due to not
resheduling when exited with outbound packets in queue; second to not
overriding relayNoConnProc() (due to signature change.) Though it still
happens occasionally.... Also added timestamps to track how long it
takes a packet to be sent and ACK'd.
2019-02-04 13:28:05 -08:00
Eric House
15a2897112 Revert "toward compiling with gcc8"
This reverts commit d293517e7c.
2019-01-29 09:05:54 -08:00
Eric House
d293517e7c toward compiling with gcc8
My VSIZE is no longer legal, and apparently there's no workaround (no
way to safely figure the length of an array whose size is known at
compile time.) To avoid the risk of duplicating little constants, added
macros that define length in a way a new VSIZE can pick it up. Couldn't
make that work for struct field arrays, however, so there I'm using
constants.
2019-01-28 17:24:53 -08:00
Eric House
db641c4664 log gameSeed; generate on linux too
I'm seeing a rare case where a game connectes to relay specifying a room
and somehow gets both slots, having provided different gameSeeds the two
times. This means an opponent won't connect, the room being full in that
game. I can't reproduce, so am logging seed changes better and switching
linux client to leave seed generation to comms as Android does.
2019-01-08 08:16:50 -08:00
Eric House
84f636cbd5 always resend via SMS when opening game
It's done for other comm types too, and is necessary to get linux test
script to pass once I make SMS delivery unreliable. But it may duplicate
the tickle that Android's doing and result in duplicate messages: test.
2018-07-17 07:05:33 -07:00
Eric House
d4436b7706 Break part of util into dutil
Trying to separate what's game-specific from what can be app/device
specific (i.e. with a long lifespan, and available when a game isn't
open.)

Android will be broken after this commit and fixed after the next
2018-07-05 07:58:50 -07:00
Eric House
d46a4d13ba use mem_stream_make_raw() where possible in common code 2018-06-27 23:42:50 -07:00
Eric House
4504302b3b make "release" builds compile again
Release isn't really a thing on linux, but I'm fixing something that
only reproduces when DEBUG is undefined.
2018-02-18 11:30:54 -08:00
Eric House
ec075eff18 comment out assertion that's firing when db wiped 2017-11-11 18:49:23 -08:00
Eric House
f2c4c82129 a shot at no-conn connecting
Ideally the comms module wouldn't go through its connecting routine in
order to join a game. To that end I added a join() method to relay.py
and code to call it. Joins happen (pairing games, starting new ones,
etc.), but after that communication doesn't. First part of fixing that
would be to make cookieID persistent and transmit it back with the rest
of what join sends (since it's used by all the messages currently sent
in a connected state), but I suspect there's more to be done, and even
that requires a fair number of changes on the relay side. So all that's
wrapped in #ifdef RELAY_VIA_HTTP (and turned off.)
2017-11-10 21:34:02 -08:00
Eric House
55f5b500e3 cleanup: method names and logging 2017-11-02 06:19:35 -07:00
Eric House
bd250cfe1e log before asserting 2017-07-19 07:16:18 -07:00
Eric House
bdc1f5ff51 when game full drop message but don't assert
I'm seeing assertions when a game gets into a state I don't fully
understand: host receives messages that need a channelNo assigned but
the game's full. With luck they're duplicates and can be ignored,
because that's all I can do.
2017-06-28 07:04:15 -07:00
Eric House
95ec573169 save disabled booleans in comms state
I want them persisted since the GTK UI doesn't make sense and they
should effect background sends and receives too.
2017-05-26 07:30:42 -07:00
Eric House
b96d44393a add and use boolToStr
Just to make log messages a bit more helpful. Should be no behavior
change, and no change in code generated in release builds.
2017-01-22 14:15:29 -08:00
Eric House
8bf65622b5 fix crash duplicating no-address network game
An edge case, but: doing "new from" on a game without any connection
types crashed because of an assertion in comms that assumed
addr_setType() was being called on zero-initialized flags, which
shouldn't have been a requirement. Pulled that as well as java code that
added RELAY-type connectivity to any game that had none. If a game has
none, leave it that way.
2017-01-07 07:41:38 -08:00
Eric House
68104bcf83 remove logging 2016-12-19 22:21:51 -08:00
Eric House
33326d38a7 wifi direct: harvest and send mac address
Grab and store the local device's mac address. Add p2p as a type of
address, represented by the mac address of the recipient. Include the
local device's address in invitations sent when specified by user. Now
the WifiDirectService class is being passed a packet and the address of
the recipient; it will next need to set up sockets with every device it
encounters and map them to their mac addresses so that it can do a send.
2016-11-14 08:06:53 -08:00
Eric House
87150c7d91 replace assertion with logging and dropping event
Until I figure out why I'm see it, as it's getting in the way of other
things.
2016-08-13 17:16:20 -07:00
Eric House
19713a40ad add param to comms_resendAll to limit type of message sent
(e.g. BT). Meant to be used when a single type has become available.
2016-02-02 07:01:48 -08:00
Eric House
87517edd6f fix counting of messages sent by "Resend messages" menuitem: actually
count them, and do so based on new msgNo passed from comms that's
concatenation of channelNo and msgID so that duplicates (over multiple
transports) aren't counted twice.
2015-09-30 06:50:04 -07:00
Eric House
389a09ac1a Merge branch 'android_branch' into relay_noconn
Conflicts:
	xwords4/android/XWords4/archive/R.java
	xwords4/android/XWords4/res/values/strings.xml
	xwords4/android/XWords4/res_src/values-ba_CK/strings.xml
	xwords4/android/XWords4/res_src/values-ca_PS/strings.xml
2015-08-13 07:30:55 -07:00
Eric House
3a32d3a17b return count of messages sent from comms_resendAll(), and post it as a
toast so user sees something happened.
2015-08-13 07:05:06 -07:00
Eric House
517cfe6fda bring over saved file format change from relay_conn branch so builds
from each will be able to open each other's files.
2015-08-10 06:24:40 -07:00
Eric House
0a95bc0f42 drop messages using comms methods (e.g. SMS) for which comms hasn't
been set up. Fixes assertion firing when SMS messages go to wrong app
(normal vs CrossDbg), though the right fix is to have the two apps
using different ports so they don't get each other's messages.
2015-07-31 22:15:57 -07:00
Eric House
dad39eedde Remove devID from comms address. It's not needed yet, may never be,
and I don't want to store it until it is.
2015-07-22 06:16:29 -07:00
Eric House
0f33228155 get rematch working on linux, at least for two-device games. (Handling
the case where one of several guests wants to rematch is a hard
problem for later.) Requires passing old-style relayIDs (connname plus
device index) when devIDs aren't available, which they may not always
be.
2015-07-06 20:28:16 -07:00
Eric House
8f794fbd32 beginning of support for invite-by-relay (which is mostly interesting
for Rematch): works for linux version, provided you know the relayID
of the device you're inviting. Added to common/ a stream-saving
version of java's NetLaunchInfo I'll probably want to use there too
for cross-platform compatibility (there being no jni support for
json.)
2015-07-01 07:10:45 -07:00
Eric House
2e8c7695f3 fix failure to connect using means (e.g. BT) that becomes available
partway through a game. Problem was that once a channel was working
with one means we wouldn't fall back to default addressing for the
means for which we didn't have a return address yet. (NOTE: Not yet
fully tested...)
2015-06-11 07:29:47 -07:00