Daemon/client protocol proposal issue #11
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
priority
critical
priority
high
priority
low
priority
medium
question
wontfix
No milestone
No project
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
brk/sshechko#11
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Daemon/client protocol proposal issue
Let's discuss in the issue comments below.
Definition of done:
Purpose of the daemon/client protocol
We've come to an agreement that entirely separate resshko processes, each one loading it's own copy of the dictionaries, or simply rereading and refiltering the same disk data for every request is unreasonable (one of these if wasteful in terms of memory, the other in terms of processor time and IO).
However, every time a user logs into the system over SSH, a new process is spawned, usually started from the same executable.
For this problem, several solutions could be proposed (resolved dilemma, but listed here for the curious):
All of these have pros and cons, but we'll only address the first approach here, the biggest con is of course that we have to create a completely different server/daemon program which we have to manage in the codebase. However, the pros are significant:
Therefore we're going with solution 1.
However, because we're creating two different types of process that need to communicate with each other we need to come up with a communication protocol.
Parts of the definition
I think a useful way to think about defining the protocol is to think of the definition in 2 or 3 layers (this isn't TCP/IP networking so let's not get too crazy):
Also, we have to clearly define the general "flow of conversation" that we want to achieve.
Flow of conversation (UNRESOLVED)
The client sends requests, the server responds with data:
The following graph covers what the game should essentially look like for the involved processes.
Question: does this flow seem like it generally makes sense, is there something important to the gameplay that's not covered here, discuss in the comments.
System layer (UNRESOLVED)
Here, we're concerned with which system facilities we will be using to facilitate the communication. And there are plenty of options:
My current proposition: Unix sockets
First I'll elaborate most of the options, then I'll argue for Unix sockets, but keep in mind each one of these options can be split into at least 2 or 3 sub-options, for example there are 4 different ways to use shared memory for communication on Linux, 2 types of message queues, etc.
Anyway, message queues seem to me to be a good learning opportunity, while also not being very complicated and pretty appropriate to our task, so I would recommend them, Unix sockets share a lot of the same advantages but they were my second pick.
However, Unix sockets have by far the best support in both Odin and Go, while message queues have by far the worst, so Unix Sockets may in fact be the best option.
General data format (UNRESOLVED)
We could send the messages over Unix Sockets by passing JSON objects in a certain format, or XML objects, s-expressions, or some other "object-notation format". However I would propose that we use a simple bespoke text format which might be easier to parse and work with.
Perhaps a simple "one line" textual message could represent both the request and response in each case, for example:
Specific commands (UNRESOLVED)
Here, I will give the specific commands I propose, I will be using the bespoke textual format, but obviously, this same logic could be implemented with JSON or something else.
Clients sends:
Server responds:
Client could respond with one of:
anything else is an error, at least until we implement more games.
Server then responds with:
After this, the protocol enters a game state, where different command options are allowed or not allowed depending on the specific game
Here, I'll give the example of a RESSHKO-DAILY run:
Where WORD is a five-letter Cyrillic word, the server keeps a counter of how
many of these are issued, and responds with one of:
Client responds with:
In the end, a client will send an
and
To stop communication with the server, if this happens, or if the server notices a dropped connection with the client, in either case, the server will record the player results in long-term memory.