Project

General

Profile

DiningHackersProtocol » History » Version 3

Matthieu Herrb, 2018-08-01 12:20

1 1 Matthieu Herrb
h1. THE DINING HACKERS PROTOCOL
2
3
April 14th 2001
4
Felipe Bergo @<bergo@seul.org>@
5
6
_"You may have read April 1st RFCs, but no text ever came so close to a February-30th-RFC as this"_
7
8
9
h2. ABSTRACT
10
11
This document describes a protocol meant to provide a centralized service for clients ('dining hackers') who are fighting (more literally than in previous similar protocols) for a finite set of resources.
12
13
h2. INTRODUCTION
14
15 3 Matthieu Herrb
The Dining Hacker protocol implements a situation similar to that shown in Dijkstra's Dining Philosophers paper. A finite set of clients with different personalities are competing for a set of resources (chopsticks).
16 1 Matthieu Herrb
     
17 3 Matthieu Herrb
The situation is a round table with at N hackers, N <= 256. There are always N chopsticks and N chinese food boxes on the table. Hackers wish to eat, but one must first acquire the two chopsticks adjacent to his own position to start eating. How much time and how frequently a hacker will eat depends on the client. But conflict resolution is arbitrated by the server, using RPG-like character sheets.
18 1 Matthieu Herrb
19
The protocol itself is divided into 2 sub-protocols, each running on a TCP connection.
20
21
h2. CLIENT SUB-PROTOCOL
22
23
The Client Sub-Protocol is used to connect a client (hacker)     to the dinner table (server). The client connects to     TCP 8081 of the server, which will send a greeting message     and wait for requests.
24
25
The greeting message is terminated by a newline (0x0a) and     the only requirement is that it contains the "DINNERD"     string (in uppercase characters). Usually it will contain     also a version number.
26
27
The following operations can be triggered by the client:
28
29
h3. GROUP 1 : SET PROPERTIES
30
31
Each client has an associated "character sheet", with 5
32
properties: name (up to 16 octets), ST (Strength, 1 octet),
33
DX (Dexterity, 1 octet), Aggr (Aggressivity, 1 octet) and
34
HT (Health, 1 octet). All properties are read/write,
35
except HT which starts at 100 and is read only.
36
37 2 Matthieu Herrb
*Operations*
38 1 Matthieu Herrb
39
# SET NAME
40
           Client sends 0x30 (up to 16 octets) 0x0a.
41
           The command always succeeds.
42
# SET ST
43
           Client sends 0x31 ST-octet
44
           The command always succeeds.
45
# SET DX
46
           Client sends 0x32 ST-octet
47
           The command always succeeds.
48
# SET Aggr
49
           Client sends 0x33 Aggr-octet
50
           The command always succeeds.
51 2 Matthieu Herrb
52
h3. GROUP 2: GET PROPERTIES
53
54
*Operations*
55
56
# GET NAME
57
           Client sends  0x3f 0x30     ("?0")
58
           Server replies with 16 octets. The name is
59
           a zero-terminated string.
60
           The command always succeeds.
61
# GET ST
62
           Client sends  0x3f 0x31     ("?1")
63
           Server replies with the ST octet.
64
           The command always succeeds.
65
# GET DX
66
           Client sends  0x3f 0x32     ("?2")
67
           Server replies with the DX octet.
68
           The command always succeeds.
69
# GET Aggr
70
           Client sends  0x3f 0x33     ("?3")
71
           Server replies with the Aggr octet.
72
           The command always succeeds.
73
# GET HT
74
           Client sends  0x3f 0x34     ("?4")
75
           Server replies with the HT octet.
76
           The command always succeeds.
77
78
79
h3. GROUP 3: RESOURCE USAGE
80
81
# REQUEST LEFT CHOPSTICK
82
           Client sends 0x4c           ("L")
83
           Server replies 0x30 on failure, 0x31 on success.
84
# REQUEST RIGHT CHOPSTICK
85
           Client sends 0x52           ("R")
86
           Server replies 0x30 on failure, 0x31 on success.
87
# DROP LEFT CHOPSTICK
88
           Client sends 0x6c           ("l")
89
           The command always succeds.
90
# DROP RIGHT CHOPSTICK
91
           Client sends 0x72           ("r")
92
           The command always succeds.
93
94
h3. GROUP 4: OTHER
95
96
97
# SUICIDE
98
           Client sends 0x51           ("Q")
99
           The command always suceeds. The hacker and his
100
           chopstick are removed from the table.
101
           Disconnecting has the same effect.
102
103
h2. INITIALIZATION
104
105
The character sheet is generated from random bits upon
106
connection. Until the client supplies data with SET
107
requests, he'll have a random 3-character name, HT 100,
108
ST in [5,15], DX in [5,15] and Aggr in [5,15].
109
110
h2. RESOURCE MANAGEMENT
111
112
The great difference from the Dining Philosophers
113
situation is that hackers have an attitude. They won't
114
starve while the neighbour is eating happily. They'll
115
attack their neighbours phisically with punches.
116
117
The ST, Aggr and DX stats shape the behavior. A
118
situation when a hacker may hit a neighbour is
119
called a hit roll, and is performed by the server.
120
Clients only find out they've been hit by checking the
121
HT with GET requests.
122
123
A hit roll is performed when a hacker already has 
124
acquired a chopstick, tries to acquire the second
125
and fails. The hacker is anger at the neighbour who
126
caused the request to fail, and the server performs
127
a hit roll.
128
129
First the server rolls 3D6 (3 6-faced dice) against
130
the hacker's Aggr parameter. If the roll is greater
131
than Aggr, the hacker wasn't upset enough, and won't
132
proceed with the hit.
133
134
If the hacker proceeds with the hit, the server
135
rolls a dexterity dispute between the attacker
136
and the defender, with a +2 innitiative bonus for the
137
attacker. The roll is :
138
139
* Attacker:  Attacker.DX + 1D6 + 2
140
* Defender:  Defender.DX + 1D6
141
142
If the defender's result is greater or equal than the
143
attacker's result, he successfully dodged the punch, and
144
the hit roll is over.
145
146
Else, the punch hit, and the server will roll the
147
damage, which is
148
149
 (Attacker.ST x 1D6) / 3
150
151
The damage is subtracted from the defender's HT.
152
A character is knocked out if his HT reaches 0 or
153
less. Knocked out characters are disconnected from
154
the server, and both the character and his associated
155
chopstick are removed from the table.
156
157
h2. STARVATION
158
159
The starvation timeout is ST x 3 seconds. The server
160
knocks off starved hackers.
161
162
h2. OBSERVATION SUB-PROTOCOL
163
        
164
The server also provides a secondary protocol for
165
processes willing to observe the global table
166
situation. The watcher makes a TCP connection
167
to port 8082. There's no greeting message, the
168
server starts listening for requests immediatelly.
169
To request a global overview the client sends
170
any octet to the server.
171
172
The server replies with a table snapshot made of
173
174
  1 octet   - H# : NUMBER OF ACTIVE HACKERS
175
176
and H# hacker state messages. Adjacent messages
177
represent adjacent hackers. Each message is 21
178
octets long:
179
180
        16 octets    - hacker name, zero-terminated
181
         1 octet     - ST
182
         1 octet     - HT
183
         1 octet     - DX
184
         1 octet     - Aggr
185
         1 octet     - eating flag, non-zero if the hacker
186
                       currently has two chopsticks in his
187
                       possession, zero otherwise.