From bd23f43cfa35d46181841a70109d95c4a72c33a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 4 Aug 2019 11:31:07 +0300 Subject: [PATCH] Notify frotend of Speak version packets --- ethermess-backend.c | 27 +++++++++++++++++++++++++++ ethermess.py | 9 ++++++++- frontend-backend-protocol.md | 6 ++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/ethermess-backend.c b/ethermess-backend.c index 1e40d5a..a86f073 100644 --- a/ethermess-backend.c +++ b/ethermess-backend.c @@ -646,6 +646,29 @@ bool check_utf8(const unsigned char *data, size_t data_length, bool newline_tab_ return true; } +void handle_speak_version(const unsigned char source_mac[6], const unsigned char *data, size_t data_length) { + if (data_length < 1) { + // Too short + return; + } + + unsigned char version = data[0]; + + if (!check_padding(data, 1, data_length)) { + // Malformed padding + return; + } + + // Type of event: Speak version + writeallx(1, "v", 1); + + // MAC + writeallx(1, source_mac, 6); + + // Version + writeallx(1, &version, 1); +} + void handle_status(const unsigned char source_mac[6], const unsigned char *data, size_t data_length) { if (data_length < 2) { // Too short @@ -885,6 +908,10 @@ void process_frame(void) { // Process the packet based on the version and packet type if (version == 0) { switch (packet_type) { + case EMT_SPEAK_VERSION: + handle_speak_version(source_mac, &frame[16], packet_length - 16); + break; + case EMT_STATUS_REQUEST: if (check_padding(&frame[16], 0, packet_length - 16)) { send_status(source_mac); diff --git a/ethermess.py b/ethermess.py index 1be7832..fba2cec 100644 --- a/ethermess.py +++ b/ethermess.py @@ -435,7 +435,14 @@ def eventloop(proc): for fd, event in poll.poll(wait): if fd == proc.stdout.fileno() and event & select.POLLIN: event_type = readall(proc.stdout, 1) - if event_type == b's': + if event_type == b'v': + # Speak version + source_mac = readall(proc.stdout, 6) + version, = readall(proc.stdout, 1) + + print('--- Speak version %s %i' % (format_mac(source_mac), version)) #debg + + elif event_type == b's': # Status source_mac = readall(proc.stdout, 6) status, = readall(proc.stdout, 1) diff --git a/frontend-backend-protocol.md b/frontend-backend-protocol.md index 092a0f7..e562478 100644 --- a/frontend-backend-protocol.md +++ b/frontend-backend-protocol.md @@ -70,6 +70,12 @@ Events Frontend receives events from the backend. +### Speak version +Format: 'v' + MAC + version (u8) + +Generated when an EtherMess Speak version packet is received by the +backend. + ### Status Format: 's' + MAC + status + nick length in bytes (u8) + nick