tkbd
is a daemon run on the faculty of sciences of the
Radboud University Nijmegen to register
which computer lab PC's are free and which are taken.
tkb.js is a frontend.
tkbd
maintains three bits of information. See state.py
.
- occupation: for each PC its current state, which is either:
o
the PC is turned offx
the PC is in an unknown statewf
the PC is free and booted in Windowslf
the PC is free and booted in Linuxwu
the PC is used and booted in Windowslu
the PC is used and booted in Linuxwx
the PC is booted in Windows, but we do not know if it is usedlx
the PC is booted in Linux, but we do not know if it is used
- roomMap: a list of rooms and the PC's in it.
- schedule: for each room, the possible reservations of it.
- tagMap: a list of tags and the rooms belonging to each tag.
For instance, in the
hg
tag (which is short for Huygens Gebouw) are all the rooms of the Huygens Gebouw.
When people log in and out of computers, this is logged.
A script watches the log and pushes changes to tkbd
via
HTTP requests on port 1235. See cnczPush.py
.
Secondly, another script periodically polls all PCs. The results of this scan are also pushed to port 1235.
The schedule is pulled from Ruuster.
See ruuster.py
.
tkbd
uses a bidirectional JSON message exchanging protocol over HTTP
called Joyce. A client can create many channels with the server.
On each of these channels, the server and the client can send messages
to eachother.
- To create a channel, send a HTTP GET request to the server for
/?m=null
. The server wil respond with an array[<token>, <messages>, <streams>]
.token
contains the token assigned to this channel.messages
is a list of messages the server has send.streams
is not important fortkbd
. - After this, you should send another HTTP GET request to the server. This
time for
/?m=[<token>]
. This time the server might not respond immediately. When there is a message (or after a timeout), the server will respond with a similar array[<token>, <messages>, <streams>]
. - To send a list of messages
messages
, send a HTTP GET request to the server for/?m=[<token>, <messages>]
. Now there are two outstanding HTTP requests. The one to send these messages and another to receive. One of these two will be responded to immediately. The other will stay open to receive messages.
So, what messages does tkbd
send and tkbd
likes to receive?
These are the messages understood by tkbd
. See cometApi.py
.
-
{"type": "set_msgFilter", "schedule":filter1, "roomMap":filter2, "occupation":filter3}
When checking the occupation of PC's in the Huygens Gebouw, one is not interested occupation updates for PC's in other faculties. When the server receives this message, it will set a message filter for the three types of messages. A filter is either a list of tags to allow (eg.
["hg"]
) ornull
which means "do not filter".The default filters are all
[]
. That is: all rooms and PC's are filtered out and thus no update is sent. -
{"type": "get_occupation"}
When received, the server will send in return an
occupation
message. (See below.) -
{"type": "get_roomMap"}
When received, the server will send in return a
roomMap
message. (See below.) -
{"type": "get_schedule"}
When received, the server will send in return a
schedule
message. (See below.) -
{"type": "get_tag_names"}
When received, the server will send in return a
tags
message. (See below.) -
{"type": "get_tagMap"}
When received, the server will send in return a
tagMap
message. (See below.) -
{"type": "get_historic_updates", "offset": <offset>, "count": <count>}
When received, the server will send in return a
historic_updates
message. (See below.)
Every messages sent by tkbd
is one of the following. See cometApi.py
.
-
{"type": "welcome", "protocols" : [1]}
This is the first message sent. It tells which protocols
tkbd
understands. Currently, there is only protocol supported:1
. -
{"type": "occupation", "version": <version>, "occupation": <occupation>}
It contains the current occupation of PC's.
occupation
is a dictionary with as keys names of PC's and as values the state of the corresponding PC's. Only PC's are included that match the currentoccupation
filter. (Seeset_msgFilter
.) -
{"type": "roomMap", "version": <version>, "roomMap": <roomMap>}
roomMap
is a dictionary with as keys names of rooms and as values the corresponding list of PC's in that room. Only PC's are included that match the currentroomMap
filter. (Seeset_msgFilter
.) -
{"type": "schedule", "version": <version>, "schedule": <schedule>}
schedule
is a dictionary with as keys names of rooms and as values the corresponding schedule of that room. A schedule of a room is a list of events. An event is a list with three element: the first element is the starting time; the second is the ending time and the third is a decription of the event. Only rooms are included that match the currentschedule
filter. (Seeset_msgFilter
.) -
{"type": "occupation_update", "version": <version>, "update": <update>}
This message is sent, when the occupation of one or more PCs changes.
update
is a dictionary with as keys PC names and as values the new state of the corresponding PC. Only updates are sent for PC's that match the currentoccupation
filter. (Seeset_msgFilter
.) -
{"type": "tags", "tags": <tags>}
This is the second message sent.
tags
is the list of tags. -
{"type": "tagMap", "tagMap": <tagMap>}
tagMap
is a dictionary with as keys names of tags and as values the corresponding list of rooms that have the tag. -
{"type": "historic_updates", "count": <count>, "offset": <offset>, "updates": <updates>}
This gives
count
historic updates from theoffset
th one.updates
is a list of quadrupels[<pc>, <source>, <unix timestamp>, <occupation>]
.
On every update of the occupation, roomMap, tagMap or schedule, the corresponding version is incremented by one.
The simplest way to install tkbd
is to run
$ easy_install tkbd
easy_install
is a part of Python's
setuptools.
(In Debian, try apt-get install python-setuptools
).
To run, simply execute:
$ mirte tkbd/setups/default
This will run the default setup of tkbd
. For changes in occupation
it will listen on port 1235. This is not useful if you are not
the IT guys of the faculty.
You can configure tkbd
to mirror another tkbd
instance. To
mirror the default tk.science.ru.nl
, simply run:
$ mirte tkbd/setups/slave
To create a custom configuration, copy and edit one of the .mirte
files
in src/setups
.
- 0.3.10:
- Add mytimetable to fetch schedule from mytimetable (eg. persoonlijkrooster.ru.nl). By Wouter Geraedts.
- 0.3.9
- ruuster: use event comment when course name equals Reserveringen
- state: updated rooms
- 0.3.8:
- state: handle schedule exceptions correctly
- 0.3.7:
- ruuster: handle more exceptions gracefully
- 0.3.6:
- Add get_historic_updates to API
- 0.3.5:
- Some minor improvements and bugfixes in the history and mirror modules
- 0.3.4:
- keep history of occupation updates in a SQQLite3 database
- 0.3.3:
- mirror: support tags
- ruuster: normalize event names
- ruuster: handle errors more gracefully
- 0.3.2
- Fix: do not crash on new schedule.
- 0.3.1
- Fix: special `null' tag filter to disable filter is properly set
- 0.3.0
- Feature: add tags. This will allow multiple `screens' running on the same tkbd.
- 0.2.4
- Fix: keep mirror running if master is down for a while
- Fix: ignore PCs with names ending with `docent'
- 0.2.3
- Fix: properly package .mirte files
- Fix: send proper start and ending times for the scheduled events
- 0.2.0
- Support for mirroring
- Fix some bugs