Refactor Logging

This commit is contained in:
Florian Märkl 2019-07-28 17:25:46 +02:00
commit 17ca818dcd
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
16 changed files with 292 additions and 233 deletions

View file

@ -21,25 +21,40 @@
#include <stdint.h>
#include <stdlib.h>
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
CHIAKI_LOG_DEBUG,
CHIAKI_LOG_INFO,
CHIAKI_LOG_WARNING,
CHIAKI_LOG_ERROR
CHIAKI_LOG_DEBUG = (1 << 3),
CHIAKI_LOG_INFO = (1 << 2),
CHIAKI_LOG_WARNING = (1 << 1),
CHIAKI_LOG_ERROR = (1 << 0)
} ChiakiLogLevel;
#define CHIAKI_LOG_ALL ((1 << 4) - 1)
typedef void (*ChiakiLogCb)(ChiakiLogLevel level, const char *msg, void *user);
typedef struct chiaki_log_t
{
uint8_t placeholder; // TODO
uint32_t level_mask;
ChiakiLogCb cb;
void *user;
} ChiakiLog;
void chiaki_log(ChiakiLog *log, ChiakiLogLevel level, const char *fmt, ...);
void chiaki_log_hexdump(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size);
void chiaki_log_hexdump_raw(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size);
CHIAKI_EXPORT void chiaki_log_init(ChiakiLog *log, uint32_t level_mask, ChiakiLogCb cb, void *user);
/**
* Logging callback (ChiakiLogCb) that prints to stdout
*/
CHIAKI_EXPORT void chiaki_log_cb_print(ChiakiLogLevel level, const char *msg, void *user);
CHIAKI_EXPORT void chiaki_log(ChiakiLog *log, ChiakiLogLevel level, const char *fmt, ...);
CHIAKI_EXPORT void chiaki_log_hexdump(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size);
CHIAKI_EXPORT void chiaki_log_hexdump_raw(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size);
#define CHIAKI_LOGD(log, ...) do { chiaki_log((log), CHIAKI_LOG_DEBUG, __VA_ARGS__); } while(0)
#define CHIAKI_LOGI(log, ...) do { chiaki_log((log), CHIAKI_LOG_INFO, __VA_ARGS__); } while(0)

View file

@ -49,12 +49,12 @@ CHIAKI_EXPORT void chiaki_audio_receiver_stream_info(ChiakiAudioReceiver *audio_
{
chiaki_mutex_lock(&audio_receiver->mutex);
CHIAKI_LOGI(audio_receiver->log, "Audio Header:\n");
CHIAKI_LOGI(audio_receiver->log, " channels = %d\n", audio_header->channels);
CHIAKI_LOGI(audio_receiver->log, " bits = %d\n", audio_header->bits);
CHIAKI_LOGI(audio_receiver->log, " rate = %d\n", audio_header->rate);
CHIAKI_LOGI(audio_receiver->log, " frame size = %d\n", audio_header->frame_size);
CHIAKI_LOGI(audio_receiver->log, " unknown = %d\n", audio_header->unknown);
CHIAKI_LOGI(audio_receiver->log, "Audio Header:");
CHIAKI_LOGI(audio_receiver->log, " channels = %d", audio_header->channels);
CHIAKI_LOGI(audio_receiver->log, " bits = %d", audio_header->bits);
CHIAKI_LOGI(audio_receiver->log, " rate = %d", audio_header->rate);
CHIAKI_LOGI(audio_receiver->log, " frame size = %d", audio_header->frame_size);
CHIAKI_LOGI(audio_receiver->log, " unknown = %d", audio_header->unknown);
memcpy(&audio_receiver->audio_header, audio_header, sizeof(audio_receiver->audio_header));
opus_decoder_destroy(audio_receiver->opus_decoder);
@ -63,9 +63,9 @@ CHIAKI_EXPORT void chiaki_audio_receiver_stream_info(ChiakiAudioReceiver *audio_
audio_receiver->opus_decoder = opus_decoder_create(audio_header->rate, audio_header->channels, &error);
if(error != OPUS_OK)
CHIAKI_LOGE(audio_receiver->log, "Audio Receiver failed to initialize opus decoder: %s\n", opus_strerror(error));
CHIAKI_LOGE(audio_receiver->log, "Audio Receiver failed to initialize opus decoder: %s", opus_strerror(error));
else
CHIAKI_LOGI(audio_receiver->log, "Audio Receiver initialized opus decoder with the settings above\n");
CHIAKI_LOGI(audio_receiver->log, "Audio Receiver initialized opus decoder with the settings above");
chiaki_mutex_unlock(&audio_receiver->mutex);
}
@ -77,7 +77,7 @@ CHIAKI_EXPORT void chiaki_audio_receiver_frame_packet(ChiakiAudioReceiver *audio
if(!audio_receiver->opus_decoder)
{
CHIAKI_LOGE(audio_receiver->log, "Received audio frame, but opus decoder is not initialized\n");
CHIAKI_LOGE(audio_receiver->log, "Received audio frame, but opus decoder is not initialized");
chiaki_mutex_unlock(&audio_receiver->mutex);
return;
}
@ -87,7 +87,7 @@ CHIAKI_EXPORT void chiaki_audio_receiver_frame_packet(ChiakiAudioReceiver *audio
int r = opus_decode(audio_receiver->opus_decoder, buf, (opus_int32)buf_size, pcm, audio_receiver->audio_header.frame_size, 0);
if(r < 1)
CHIAKI_LOGE(audio_receiver->log, "Decoding audio frame with opus failed: %s\n", opus_strerror(r));
CHIAKI_LOGE(audio_receiver->log, "Decoding audio frame with opus failed: %s", opus_strerror(r));
else
{
audio_receiver->session->audio_frame_cb(pcm, (size_t)r, audio_receiver->session->audio_frame_cb_user);

View file

@ -35,7 +35,7 @@ static void *congestion_control_thread_func(void *user)
if(err != CHIAKI_ERR_TIMEOUT)
break;
//CHIAKI_LOGD(control->takion->log, "Sending Congestion Control Packet\n");
//CHIAKI_LOGD(control->takion->log, "Sending Congestion Control Packet");
ChiakiTakionCongestionPacket packet = { 0 }; // TODO: fill with real values
chiaki_takion_send_congestion(control->takion, &packet);
}

View file

@ -68,7 +68,7 @@ static void *ctrl_thread_func(void *user)
return NULL;
}
CHIAKI_LOGI(&ctrl->session->log, "Ctrl connected\n");
CHIAKI_LOGI(&ctrl->session->log, "Ctrl connected");
while(true)
{
@ -82,7 +82,7 @@ static void *ctrl_thread_func(void *user)
{
if(8 + payload_size > sizeof(ctrl->recv_buf))
{
CHIAKI_LOGE(&ctrl->session->log, "Ctrl buffer overflow!\n");
CHIAKI_LOGE(&ctrl->session->log, "Ctrl buffer overflow!");
overflow = true;
}
break;
@ -129,7 +129,7 @@ static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, CtrlMessageType type,
ssize_t sent = send(ctrl->sock, header, sizeof(header), 0);
if(sent < 0)
{
CHIAKI_LOGE(&ctrl->session->log, "Failed to send Ctrl Message Header\n");
CHIAKI_LOGE(&ctrl->session->log, "Failed to send Ctrl Message Header");
return CHIAKI_ERR_NETWORK;
}
@ -138,7 +138,7 @@ static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, CtrlMessageType type,
sent = send(ctrl->sock, payload, payload_size, 0);
if(sent < 0)
{
CHIAKI_LOGE(&ctrl->session->log, "Failed to send Ctrl Message Payload\n");
CHIAKI_LOGE(&ctrl->session->log, "Failed to send Ctrl Message Payload");
return CHIAKI_ERR_NETWORK;
}
}
@ -157,7 +157,7 @@ static void ctrl_message_received(ChiakiCtrl *ctrl, uint16_t msg_type, uint8_t *
ChiakiErrorCode err = chiaki_rpcrypt_decrypt(&ctrl->session->rpcrypt, ctrl->crypt_counter_remote++, payload, payload, payload_size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&ctrl->session->log, "Failed to decrypt payload for Ctrl Message type %#x\n", msg_type);
CHIAKI_LOGE(&ctrl->session->log, "Failed to decrypt payload for Ctrl Message type %#x", msg_type);
return;
}
}
@ -171,7 +171,7 @@ static void ctrl_message_received(ChiakiCtrl *ctrl, uint16_t msg_type, uint8_t *
ctrl_message_received_heartbeat_req(ctrl, payload, payload_size);
break;
default:
CHIAKI_LOGW(&ctrl->session->log, "Received Ctrl Message with unknown type %#x\n", msg_type);
CHIAKI_LOGW(&ctrl->session->log, "Received Ctrl Message with unknown type %#x", msg_type);
break;
}
}
@ -181,13 +181,13 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
{
if(ctrl->session->ctrl_session_id_received)
{
CHIAKI_LOGW(&ctrl->session->log, "Received another Session Id Message\n");
CHIAKI_LOGW(&ctrl->session->log, "Received another Session Id Message");
return;
}
if(payload_size < 2 || (char)payload[0] != 'J')
{
CHIAKI_LOGE(&ctrl->session->log, "Invalid Session Id received\n");
CHIAKI_LOGE(&ctrl->session->log, "Invalid Session Id received");
return;
}
@ -197,7 +197,7 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
if(payload_size >= CHIAKI_SESSION_ID_SIZE_MAX - 1)
{
CHIAKI_LOGE(&ctrl->session->log, "Received Session Id is too long\n");
CHIAKI_LOGE(&ctrl->session->log, "Received Session Id is too long");
return;
}
@ -210,7 +210,7 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
continue;
if(c >= '0' && c <= '9')
continue;
CHIAKI_LOGE(&ctrl->session->log, "Received Session Id contains invalid characters\n");
CHIAKI_LOGE(&ctrl->session->log, "Received Session Id contains invalid characters");
return;
}
@ -221,15 +221,15 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
chiaki_cond_signal(&ctrl->session->ctrl_cond);
chiaki_mutex_unlock(&ctrl->session->ctrl_cond_mutex);
CHIAKI_LOGI(&ctrl->session->log, "Received valid Session Id: %s\n", ctrl->session->session_id);
CHIAKI_LOGI(&ctrl->session->log, "Received valid Session Id: %s", ctrl->session->session_id);
}
static void ctrl_message_received_heartbeat_req(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size)
{
if(payload_size != 0)
CHIAKI_LOGW(&ctrl->session->log, "Received Heartbeat request with non-empty payload\n");
CHIAKI_LOGW(&ctrl->session->log, "Received Heartbeat request with non-empty payload");
CHIAKI_LOGI(&ctrl->session->log, "Received Ctrl Heartbeat, sending reply\n");
CHIAKI_LOGI(&ctrl->session->log, "Received Ctrl Heartbeat, sending reply");
ctrl_message_send(ctrl, CTRL_MESSAGE_TYPE_HEARTBEAT_REP, NULL, 0);
}
@ -286,7 +286,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
int sock = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP);
if(sock < 0)
{
CHIAKI_LOGE(&session->log, "Session ctrl socket creation failed.\n");
CHIAKI_LOGE(&session->log, "Session ctrl socket creation failed.");
chiaki_session_set_quit_reason(session, CHIAKI_QUIT_REASON_CTRL_UNKNOWN);
return CHIAKI_ERR_NETWORK;
}
@ -296,7 +296,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
if(r < 0)
{
int errsv = errno;
CHIAKI_LOGE(&session->log, "Ctrl connect failed: %s\n", strerror(errsv));
CHIAKI_LOGE(&session->log, "Ctrl connect failed: %s", strerror(errsv));
if(errsv == ECONNREFUSED)
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_CONNECTION_REFUSED;
else
@ -305,7 +305,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
return CHIAKI_ERR_NETWORK;
}
CHIAKI_LOGI(&session->log, "Connected to %s:%d\n", session->connect_info.hostname, SESSION_CTRL_PORT);
CHIAKI_LOGI(&session->log, "Connected to %s:%d", session->connect_info.hostname, SESSION_CTRL_PORT);
uint8_t auth_enc[CHIAKI_KEY_BYTES];
@ -359,12 +359,12 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
if(request_len < 0 || request_len >= sizeof(buf))
goto error;
CHIAKI_LOGI(&session->log, "Sending ctrl request\n");
CHIAKI_LOGI(&session->log, "Sending ctrl request");
ssize_t sent = send(sock, buf, (size_t)request_len, 0);
if(sent < 0)
{
CHIAKI_LOGE(&session->log, "Failed to send ctrl request\n");
CHIAKI_LOGE(&session->log, "Failed to send ctrl request");
goto error;
}
@ -373,7 +373,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
err = chiaki_recv_http_header(sock, buf, sizeof(buf), &header_size, &received_size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Failed to receive ctrl request response\n");
CHIAKI_LOGE(&session->log, "Failed to receive ctrl request response");
goto error;
}
@ -381,7 +381,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
err = chiaki_http_response_parse(&http_response, buf, header_size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Failed to parse ctrl request response\n");
CHIAKI_LOGE(&session->log, "Failed to parse ctrl request response");
goto error;
}
@ -406,7 +406,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
}
if(!response.server_type_valid)
CHIAKI_LOGE(&session->log, "No valid Server Type in ctrl response\n");
CHIAKI_LOGE(&session->log, "No valid Server Type in ctrl response");
ctrl->sock = sock;

View file

@ -48,7 +48,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery,
discovery->socket = socket(AF_INET, SOCK_DGRAM, 0);
if(discovery->socket < 0)
{
CHIAKI_LOGE(discovery->log, "Discovery failed to create socket\n");
CHIAKI_LOGE(discovery->log, "Discovery failed to create socket");
return CHIAKI_ERR_NETWORK;
}
@ -71,7 +71,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery,
int r = bind(discovery->socket, &discovery->local_addr, sizeof(discovery->local_addr));
if(r < 0)
{
CHIAKI_LOGE(discovery->log, "Discovery failed to bind\n");
CHIAKI_LOGE(discovery->log, "Discovery failed to bind");
close(discovery->socket);
return CHIAKI_ERR_NETWORK;
}
@ -79,7 +79,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery,
const int broadcast = 1;
r = setsockopt(discovery->socket, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
if(r < 0)
CHIAKI_LOGE(discovery->log, "Discovery failed to setsockopt SO_BROADCAST\n");
CHIAKI_LOGE(discovery->log, "Discovery failed to setsockopt SO_BROADCAST");
return CHIAKI_ERR_SUCCESS;
}
@ -117,7 +117,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThrea
ChiakiErrorCode err = chiaki_stop_pipe_init(&thread->stop_pipe);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(discovery->log, "Discovery (thread) failed to create pipe\n");
CHIAKI_LOGE(discovery->log, "Discovery (thread) failed to create pipe");
return err;
}
@ -153,7 +153,7 @@ static void *discovery_thread_func(void *user)
break;
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(discovery->log, "Discovery thread failed to select\n");
CHIAKI_LOGE(discovery->log, "Discovery thread failed to select");
break;
}
@ -163,7 +163,7 @@ static void *discovery_thread_func(void *user)
ssize_t n = recvfrom(discovery->socket, buf, sizeof(buf) - 1, 0, &client_addr, &client_addr_size);
if(n < 0)
{
CHIAKI_LOGE(discovery->log, "Discovery thread failed to read from socket\n");
CHIAKI_LOGE(discovery->log, "Discovery thread failed to read from socket");
break;
}
@ -175,7 +175,7 @@ static void *discovery_thread_func(void *user)
buf[n] = '\00';
CHIAKI_LOGD(discovery->log, "Discovery received:\n%s\n", buf);
CHIAKI_LOGD(discovery->log, "Discovery received:\n%s", buf);
}
return NULL;

View file

@ -111,7 +111,7 @@ static void feedback_sender_send_state(ChiakiFeedbackSender *feedback_sender)
state.right_y = feedback_sender->controller_state.right_y;
ChiakiErrorCode err = chiaki_takion_send_feedback_state(feedback_sender->takion, feedback_sender->state_seq_num++, &state);
if(err != CHIAKI_ERR_SUCCESS)
CHIAKI_LOGE(feedback_sender->log, "FeedbackSender failed to send Feedback State\n");
CHIAKI_LOGE(feedback_sender->log, "FeedbackSender failed to send Feedback State");
}
static bool controller_state_equals_for_feedback_history(ChiakiControllerState *a, ChiakiControllerState *b)
@ -140,7 +140,7 @@ static void feedback_sender_send_history(ChiakiFeedbackSender *feedback_sender)
ChiakiErrorCode err = chiaki_feedback_history_event_set_button(&event, button_id, now ? 0xff : 0);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format button history event for button id %llu\n", (unsigned long long)button_id);
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format button history event for button id %llu", (unsigned long long)button_id);
continue;
}
chiaki_feedback_history_buffer_push(&feedback_sender->history_buf, &event);
@ -158,7 +158,7 @@ static void feedback_sender_send_history(ChiakiFeedbackSender *feedback_sender)
new_events_count++;
}
else
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format button history event for L2\n");
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format button history event for L2");
}
if(state_prev->r2_state != state_now->r2_state)
@ -171,7 +171,7 @@ static void feedback_sender_send_history(ChiakiFeedbackSender *feedback_sender)
new_events_count++;
}
else
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format button history event for R2\n");
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format button history event for R2");
}
if(!new_events_count) // TODO: also send on timeout sometimes?
@ -182,11 +182,11 @@ static void feedback_sender_send_history(ChiakiFeedbackSender *feedback_sender)
ChiakiErrorCode err = chiaki_feedback_history_buffer_format(&feedback_sender->history_buf, buf, &buf_size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format history buffer\n");
CHIAKI_LOGE(feedback_sender->log, "Feedback Sender failed to format history buffer");
return;
}
//CHIAKI_LOGD(feedback_sender->log, "Feedback History:\n");
//CHIAKI_LOGD(feedback_sender->log, "Feedback History:");
//chiaki_log_hexdump(feedback_sender->log, CHIAKI_LOG_DEBUG, buf, buf_size);
chiaki_takion_send_feedback_history(feedback_sender->takion, feedback_sender->history_seq_num++, buf, buf_size);
}

View file

@ -50,7 +50,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_alloc_frame(ChiakiFrameProc
{
if(packet->units_in_frame_total < packet->units_in_frame_additional)
{
CHIAKI_LOGE(frame_processor->log, "Packet has units_in_frame_total < units_in_frame_additional\n");
CHIAKI_LOGE(frame_processor->log, "Packet has units_in_frame_total < units_in_frame_additional");
return CHIAKI_ERR_INVALID_DATA;
}
@ -64,7 +64,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_alloc_frame(ChiakiFrameProc
{
if(packet->data_size < 2)
{
CHIAKI_LOGE(frame_processor->log, "Packet too small to read buf size extension\n");
CHIAKI_LOGE(frame_processor->log, "Packet too small to read buf size extension");
return CHIAKI_ERR_BUF_TOO_SMALL;
}
frame_processor->buf_size_per_unit += ntohs(((uint16_t *)packet->data)[0]);
@ -72,7 +72,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_alloc_frame(ChiakiFrameProc
if(frame_processor->buf_size_per_unit == 0)
{
CHIAKI_LOGE(frame_processor->log, "Frame Processor doesn't handle empty units\n");
CHIAKI_LOGE(frame_processor->log, "Frame Processor doesn't handle empty units");
return CHIAKI_ERR_BUF_TOO_SMALL;
}
@ -82,7 +82,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_alloc_frame(ChiakiFrameProc
size_t unit_slots_size_required = frame_processor->units_regular_expected + frame_processor->units_additional_expected;
if(unit_slots_size_required > UNIT_SLOTS_MAX)
{
CHIAKI_LOGE(frame_processor->log, "Packet suggests more than %u unit slots\n", UNIT_SLOTS_MAX);
CHIAKI_LOGE(frame_processor->log, "Packet suggests more than %u unit slots", UNIT_SLOTS_MAX);
return CHIAKI_ERR_INVALID_DATA;
}
if(unit_slots_size_required != frame_processor->unit_slots_size)
@ -131,26 +131,26 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_put_unit(ChiakiFrameProcess
{
if(packet->unit_index > frame_processor->unit_slots_size)
{
CHIAKI_LOGE(frame_processor->log, "Packet's unit index is too high\n");
CHIAKI_LOGE(frame_processor->log, "Packet's unit index is too high");
return CHIAKI_ERR_INVALID_DATA;
}
if(!packet->data_size)
{
CHIAKI_LOGW(frame_processor->log, "Unit is empty\n");
CHIAKI_LOGW(frame_processor->log, "Unit is empty");
return CHIAKI_ERR_INVALID_DATA;
}
if(packet->data_size > frame_processor->buf_size_per_unit)
{
CHIAKI_LOGW(frame_processor->log, "Unit is bigger than pre-calculated size!\n");
CHIAKI_LOGW(frame_processor->log, "Unit is bigger than pre-calculated size!");
return CHIAKI_ERR_INVALID_DATA;
}
ChiakiFrameUnit *unit = frame_processor->unit_slots + packet->unit_index;
if(unit->data_size)
{
CHIAKI_LOGW(frame_processor->log, "Received duplicate unit\n");
CHIAKI_LOGW(frame_processor->log, "Received duplicate unit");
return CHIAKI_ERR_INVALID_DATA;
}
@ -186,7 +186,7 @@ CHIAKI_EXPORT ChiakiFrameProcessorFlushResult chiaki_frame_processor_flush(Chiak
ChiakiFrameUnit *unit = frame_processor->unit_slots + i;
if(unit->data_size < 2)
{
CHIAKI_LOGE(frame_processor->log, "Saved unit has size < 2\n");
CHIAKI_LOGE(frame_processor->log, "Saved unit has size < 2");
continue;
}
size_t part_size = unit->data_size - 2;

View file

@ -42,7 +42,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_gkcrypt_init(ChiakiGKCrypt *gkcrypt, Chiaki
ChiakiErrorCode err = gkcrypt_gen_key_iv(gkcrypt, index, handshake_key, ecdh_secret);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(gkcrypt->log, "GKCrypt failed to generate key and IV\n");
CHIAKI_LOGE(gkcrypt->log, "GKCrypt failed to generate key and IV");
free(gkcrypt->key_buf);
return CHIAKI_ERR_UNKNOWN;
}

View file

@ -20,10 +20,16 @@
#include <stdio.h>
#include <stdarg.h>
void chiaki_log(ChiakiLog *log, ChiakiLogLevel level, const char *fmt, ...)
CHIAKI_EXPORT void chiaki_log_init(ChiakiLog *log, uint32_t level_mask, ChiakiLogCb cb, void *user)
{
va_list args;
va_start(args, fmt);
log->level_mask = level_mask;
log->cb = cb;
log->user = user;
}
CHIAKI_EXPORT void chiaki_log_cb_print(ChiakiLogLevel level, const char *msg, void *user)
{
(void)user;
char c;
const char *color = NULL;
@ -54,16 +60,52 @@ void chiaki_log(ChiakiLog *log, ChiakiLogLevel level, const char *fmt, ...)
printf("[%c] ", c);
if(color)
printf("\033[0m");
vprintf(fmt, args);
printf("%s\n", msg);
}
CHIAKI_EXPORT void chiaki_log(ChiakiLog *log, ChiakiLogLevel level, const char *fmt, ...)
{
va_list args;
char buf[0x100];
char *msg = buf;
va_start(args, fmt);
int written = vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
if(written < 0)
return;
if(written >= sizeof(buf))
{
msg = malloc(written + 1);
if(!msg)
return;
va_start(args, fmt);
written = vsnprintf(msg, written + 1, fmt, args);
va_end(args);
if(written < 0)
{
free(msg);
return;
}
}
ChiakiLogCb cb = log && log->cb ? log->cb : chiaki_log_cb_print;
void *user = log ? log->user : NULL;
cb(level, msg, user);
if(msg != buf)
free(msg);
}
#define HEXDUMP_WIDTH 0x10
static const char hex_char[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
void chiaki_log_hexdump(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size)
CHIAKI_EXPORT void chiaki_log_hexdump(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size)
{
chiaki_log(log, level, "offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef\n");
@ -114,7 +156,7 @@ void chiaki_log_hexdump(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf
}
}
void chiaki_log_hexdump_raw(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size)
CHIAKI_EXPORT void chiaki_log_hexdump_raw(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size)
{
char *str = malloc(buf_size * 2 + 1);
if(!str)

View file

@ -86,7 +86,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSession *session)
free(takion_info.sa);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Senkusha connect failed\n");
CHIAKI_LOGE(&session->log, "Senkusha connect failed");
goto error_bang_mirai;
}
@ -96,14 +96,14 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSession *session)
if(!senkusha.bang_mirai.response)
{
if(err == CHIAKI_ERR_TIMEOUT)
CHIAKI_LOGE(&session->log, "Senkusha connect timeout\n");
CHIAKI_LOGE(&session->log, "Senkusha connect timeout");
CHIAKI_LOGE(&session->log, "Senkusha Takion connect failed\n");
CHIAKI_LOGE(&session->log, "Senkusha Takion connect failed");
err = CHIAKI_ERR_UNKNOWN;
goto error_takion;
}
CHIAKI_LOGI(&session->log, "Senkusha sending big\n");
CHIAKI_LOGI(&session->log, "Senkusha sending big");
err = chiaki_mirai_request_begin(&senkusha.bang_mirai, MIRAI_REQUEST_BANG, true);
assert(err == CHIAKI_ERR_SUCCESS);
@ -111,7 +111,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSession *session)
err = senkusha_send_big(&senkusha);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Senkusha failed to send big\n");
CHIAKI_LOGE(&session->log, "Senkusha failed to send big");
goto error_takion;
}
@ -121,23 +121,23 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSession *session)
if(!senkusha.bang_mirai.response)
{
if(err == CHIAKI_ERR_TIMEOUT)
CHIAKI_LOGE(&session->log, "Senkusha bang receive timeout\n");
CHIAKI_LOGE(&session->log, "Senkusha bang receive timeout");
CHIAKI_LOGE(&session->log, "Senkusha didn't receive bang\n");
CHIAKI_LOGE(&session->log, "Senkusha didn't receive bang");
err = CHIAKI_ERR_UNKNOWN;
goto error_takion;
}
CHIAKI_LOGI(&session->log, "Senkusha successfully received bang\n");
CHIAKI_LOGI(&session->log, "Senkusha successfully received bang");
CHIAKI_LOGI(&session->log, "Senkusha is disconnecting\n");
CHIAKI_LOGI(&session->log, "Senkusha is disconnecting");
senkusha_send_disconnect(&senkusha);
err = CHIAKI_ERR_SUCCESS;
error_takion:
chiaki_takion_close(&senkusha.takion);
CHIAKI_LOGI(&session->log, "Senkusha closed takion\n");
CHIAKI_LOGI(&session->log, "Senkusha closed takion");
error_bang_mirai:
chiaki_mirai_fini(&senkusha.bang_mirai);
return err;
@ -174,7 +174,7 @@ static void senkusha_takion_data(Senkusha *senkusha, ChiakiTakionMessageDataType
bool r = pb_decode(&stream, tkproto_TakionMessage_fields, &msg);
if(!r)
{
CHIAKI_LOGE(senkusha->log, "Senkusha failed to decode data protobuf\n");
CHIAKI_LOGE(senkusha->log, "Senkusha failed to decode data protobuf");
return;
}
@ -182,7 +182,7 @@ static void senkusha_takion_data(Senkusha *senkusha, ChiakiTakionMessageDataType
{
if(msg.type != tkproto_TakionMessage_PayloadType_BANG || !msg.has_bang_payload)
{
CHIAKI_LOGE(senkusha->log, "Senkusha expected bang payload but received something else\n");
CHIAKI_LOGE(senkusha->log, "Senkusha expected bang payload but received something else");
return;
}
chiaki_mirai_signal(&senkusha->bang_mirai, 1);
@ -211,7 +211,7 @@ static ChiakiErrorCode senkusha_send_big(Senkusha *senkusha)
bool pbr = pb_encode(&stream, tkproto_TakionMessage_fields, &msg);
if(!pbr)
{
CHIAKI_LOGE(senkusha->log, "Senkusha big protobuf encoding failed\n");
CHIAKI_LOGE(senkusha->log, "Senkusha big protobuf encoding failed");
return CHIAKI_ERR_UNKNOWN;
}
@ -238,7 +238,7 @@ static ChiakiErrorCode senkusha_send_disconnect(Senkusha *senkusha)
bool pbr = pb_encode(&stream, tkproto_TakionMessage_fields, &msg);
if(!pbr)
{
CHIAKI_LOGE(senkusha->log, "Senkusha disconnect protobuf encoding failed\n");
CHIAKI_LOGE(senkusha->log, "Senkusha disconnect protobuf encoding failed");
return CHIAKI_ERR_UNKNOWN;
}

View file

@ -49,6 +49,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, Chiaki
{
memset(session, 0, sizeof(ChiakiSession));
chiaki_log_init(&session->log, CHIAKI_LOG_ALL, NULL, NULL);
session->quit_reason = CHIAKI_QUIT_REASON_NONE;
ChiakiErrorCode err = chiaki_cond_init(&session->ctrl_cond);
@ -62,7 +64,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, Chiaki
err = chiaki_stream_connection_init(&session->stream_connection, session);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "StreamConnection init failed\n");
CHIAKI_LOGE(&session->log, "StreamConnection init failed");
goto error_ctrl_cond_mutex;
}
@ -151,19 +153,19 @@ static void *session_thread_func(void *arg)
ChiakiSession *session = arg;
bool success;
CHIAKI_LOGI(&session->log, "Starting session request\n");
CHIAKI_LOGI(&session->log, "Starting session request");
success = session_thread_request_session(session);
if(!success)
goto quit;
CHIAKI_LOGI(&session->log, "Session request successful\n");
CHIAKI_LOGI(&session->log, "Session request successful");
chiaki_rpcrypt_init(&session->rpcrypt, session->nonce, session->connect_info.morning);
usleep(5000);
CHIAKI_LOGI(&session->log, "Starting ctrl\n");
CHIAKI_LOGI(&session->log, "Starting ctrl");
chiaki_mutex_lock(&session->ctrl_cond_mutex);
session->ctrl_session_id_received = false;
@ -177,16 +179,16 @@ static void *session_thread_func(void *arg)
if(!session->ctrl_session_id_received)
{
CHIAKI_LOGE(&session->log, "Ctrl has failed, shutting down\n");
CHIAKI_LOGE(&session->log, "Ctrl has failed, shutting down");
goto quit_ctrl;
}
CHIAKI_LOGI(&session->log, "Starting Senkusha\n");
CHIAKI_LOGI(&session->log, "Starting Senkusha");
/* TODO err = chiaki_senkusha_run(session);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Senkusha failed\n");
CHIAKI_LOGE(&session->log, "Senkusha failed");
goto quit_ctrl;
}*/
@ -194,44 +196,44 @@ static void *session_thread_func(void *arg)
session->mtu = 1454;
session->rtt = 12;
CHIAKI_LOGI(&session->log, "Senkusha completed successfully\n");
CHIAKI_LOGI(&session->log, "Senkusha completed successfully");
err = chiaki_random_bytes(session->handshake_key, sizeof(session->handshake_key));
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Session failed to generate handshake key\n");
CHIAKI_LOGE(&session->log, "Session failed to generate handshake key");
goto quit_ctrl;
}
err = chiaki_ecdh_init(&session->ecdh);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Session failed to initialize ECDH\n");
CHIAKI_LOGE(&session->log, "Session failed to initialize ECDH");
goto quit_ctrl;
}
session->audio_receiver = chiaki_audio_receiver_new(session);
if(!session->audio_receiver)
{
CHIAKI_LOGE(&session->log, "Session failed to initialize Audio Receiver\n");
CHIAKI_LOGE(&session->log, "Session failed to initialize Audio Receiver");
goto quit_ctrl;
}
session->video_receiver = chiaki_video_receiver_new(session);
if(!session->video_receiver)
{
CHIAKI_LOGE(&session->log, "Session failed to initialize Video Receiver\n");
CHIAKI_LOGE(&session->log, "Session failed to initialize Video Receiver");
goto quit_audio_receiver;
}
err = chiaki_stream_connection_run(&session->stream_connection);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "StreamConnection run failed\n");
CHIAKI_LOGE(&session->log, "StreamConnection run failed");
goto quit_stream_connection;
}
CHIAKI_LOGI(&session->log, "StreamConnection completed successfully\n");
CHIAKI_LOGI(&session->log, "StreamConnection completed successfully");
quit_stream_connection:
chiaki_stream_connection_fini(&session->stream_connection);
@ -246,7 +248,7 @@ quit_audio_receiver:
quit_ctrl:
chiaki_ctrl_join(&session->ctrl);
CHIAKI_LOGI(&session->log, "Ctrl stopped\n");
CHIAKI_LOGI(&session->log, "Ctrl stopped");
ChiakiEvent quit_event;
quit:
@ -321,7 +323,7 @@ static bool session_thread_request_session(ChiakiSession *session)
continue;
}
CHIAKI_LOGI(&session->log, "Trying to request session from %s:%d\n", session->connect_info.hostname, SESSION_PORT);
CHIAKI_LOGI(&session->log, "Trying to request session from %s:%d", session->connect_info.hostname, SESSION_PORT);
session_sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if(session_sock < 0)
@ -330,7 +332,7 @@ static bool session_thread_request_session(ChiakiSession *session)
if(r < 0)
{
int errsv = errno;
CHIAKI_LOGE(&session->log, "Session request connect failed: %s\n", strerror(errsv));
CHIAKI_LOGE(&session->log, "Session request connect failed: %s", strerror(errsv));
if(errsv == ECONNREFUSED)
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_CONNECTION_REFUSED;
else
@ -349,13 +351,13 @@ static bool session_thread_request_session(ChiakiSession *session)
if(session_sock < 0)
{
CHIAKI_LOGE(&session->log, "Session request connect failed eventually.\n");
CHIAKI_LOGE(&session->log, "Session request connect failed eventually.");
if(session->quit_reason == CHIAKI_QUIT_REASON_NONE)
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
return false;
}
CHIAKI_LOGI(&session->log, "Connected to %s:%d\n", session->connect_info.hostname, SESSION_PORT);
CHIAKI_LOGI(&session->log, "Connected to %s:%d", session->connect_info.hostname, SESSION_PORT);
static const char session_request_fmt[] =
"GET /sce/rp/session HTTP/1.1\r\n"
@ -377,12 +379,12 @@ static bool session_thread_request_session(ChiakiSession *session)
return false;
}
CHIAKI_LOGI(&session->log, "Sending session request\n");
CHIAKI_LOGI(&session->log, "Sending session request");
ssize_t sent = send(session_sock, buf, (size_t)request_len, 0);
if(sent < 0)
{
CHIAKI_LOGE(&session->log, "Failed to send session request\n");
CHIAKI_LOGE(&session->log, "Failed to send session request");
close(session_sock);
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
return false;
@ -393,7 +395,7 @@ static bool session_thread_request_session(ChiakiSession *session)
ChiakiErrorCode err = chiaki_recv_http_header(session_sock, buf, sizeof(buf), &header_size, &received_size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Failed to receive session request response\n");
CHIAKI_LOGE(&session->log, "Failed to receive session request response");
close(session_sock);
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
return false;
@ -403,7 +405,7 @@ static bool session_thread_request_session(ChiakiSession *session)
err = chiaki_http_response_parse(&http_response, buf, header_size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "Failed to parse session request response\n");
CHIAKI_LOGE(&session->log, "Failed to parse session request response");
close(session_sock);
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
return false;
@ -418,7 +420,7 @@ static bool session_thread_request_session(ChiakiSession *session)
err = chiaki_base64_decode(response.nonce, strlen(response.nonce), session->nonce, &nonce_len);
if(err != CHIAKI_ERR_SUCCESS || nonce_len != CHIAKI_KEY_BYTES)
{
CHIAKI_LOGE(&session->log, "Nonce invalid\n");
CHIAKI_LOGE(&session->log, "Nonce invalid");
response.success = false;
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
}
@ -428,11 +430,11 @@ static bool session_thread_request_session(ChiakiSession *session)
switch(response.error_code)
{
case RP_APPLICATION_REASON_IN_USE:
CHIAKI_LOGE(&session->log, "Remote is already in use\n");
CHIAKI_LOGE(&session->log, "Remote is already in use");
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_IN_USE;
break;
case RP_APPLICATION_REASON_CRASH:
CHIAKI_LOGE(&session->log, "Remote seems to have crashed\n");
CHIAKI_LOGE(&session->log, "Remote seems to have crashed");
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_CRASH;
break;
default:

View file

@ -149,7 +149,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
free(takion_info.sa);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "StreamConnection connect failed\n");
CHIAKI_LOGE(&session->log, "StreamConnection connect failed");
return err;
}
@ -157,11 +157,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "StreamConnection Takion connect failed\n");
CHIAKI_LOGE(&session->log, "StreamConnection Takion connect failed");
goto close_takion;
}
CHIAKI_LOGI(&session->log, "StreamConnection sending big\n");
CHIAKI_LOGI(&session->log, "StreamConnection sending big");
stream_connection->state = STATE_EXPECT_BANG;
stream_connection->state_finished = false;
@ -169,7 +169,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
err = stream_connection_send_big(stream_connection);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(&session->log, "StreamConnection failed to send big\n");
CHIAKI_LOGE(&session->log, "StreamConnection failed to send big");
goto disconnect;
}
@ -179,14 +179,14 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
if(!stream_connection->state_finished)
{
if(err == CHIAKI_ERR_TIMEOUT)
CHIAKI_LOGE(&session->log, "StreamConnection bang receive timeout\n");
CHIAKI_LOGE(&session->log, "StreamConnection bang receive timeout");
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive bang or failed to handle it\n");
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive bang or failed to handle it");
err = CHIAKI_ERR_UNKNOWN;
goto disconnect;
}
CHIAKI_LOGI(&session->log, "StreamConnection successfully received bang\n");
CHIAKI_LOGI(&session->log, "StreamConnection successfully received bang");
stream_connection->state = STATE_EXPECT_STREAMINFO;
stream_connection->state_finished = false;
@ -197,14 +197,14 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
if(!stream_connection->state_finished)
{
if(err == CHIAKI_ERR_TIMEOUT)
CHIAKI_LOGE(&session->log, "StreamConnection streaminfo receive timeout\n");
CHIAKI_LOGE(&session->log, "StreamConnection streaminfo receive timeout");
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive streaminfo\n");
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive streaminfo");
err = CHIAKI_ERR_UNKNOWN;
goto disconnect;
}
CHIAKI_LOGI(&session->log, "StreamConnection successfully received streaminfo\n");
CHIAKI_LOGI(&session->log, "StreamConnection successfully received streaminfo");
err = chiaki_mutex_lock(&stream_connection->feedback_sender_mutex);
assert(err == CHIAKI_ERR_SUCCESS);
@ -212,7 +212,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
if(err != CHIAKI_ERR_SUCCESS)
{
chiaki_mutex_unlock(&stream_connection->feedback_sender_mutex);
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to start Feedback Sender\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to start Feedback Sender");
goto disconnect;
}
stream_connection->feedback_sender_active = true;
@ -230,9 +230,9 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
err = stream_connection_send_heartbeat(stream_connection);
if(err != CHIAKI_ERR_SUCCESS)
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to send heartbeat\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to send heartbeat");
else
CHIAKI_LOGI(stream_connection->log, "StreamConnection sent heartbeat\n");
CHIAKI_LOGI(stream_connection->log, "StreamConnection sent heartbeat");
}
err = chiaki_mutex_lock(&stream_connection->feedback_sender_mutex);
@ -244,17 +244,17 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
err = CHIAKI_ERR_SUCCESS;
disconnect:
CHIAKI_LOGI(&session->log, "StreamConnection is disconnecting\n");
CHIAKI_LOGI(&session->log, "StreamConnection is disconnecting");
stream_connection_send_disconnect(stream_connection);
if(stream_connection->should_stop)
CHIAKI_LOGI(stream_connection->log, "StreamConnection was requested to stop\n");
CHIAKI_LOGI(stream_connection->log, "StreamConnection was requested to stop");
chiaki_mutex_unlock(&stream_connection->state_mutex);
close_takion:
chiaki_takion_close(&stream_connection->takion);
CHIAKI_LOGI(&session->log, "StreamConnection closed takion\n");
CHIAKI_LOGI(&session->log, "StreamConnection closed takion");
return err;
}
@ -328,12 +328,12 @@ static void stream_connection_takion_data_idle(ChiakiStreamConnection *stream_co
bool r = pb_decode(&stream, tkproto_TakionMessage_fields, &msg);
if(!r)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to decode data protobuf\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to decode data protobuf");
chiaki_log_hexdump(stream_connection->log, CHIAKI_LOG_ERROR, buf, buf_size);
return;
}
//CHIAKI_LOGD(stream_connection->log, "StreamConnection received data\n");
//CHIAKI_LOGD(stream_connection->log, "StreamConnection received data");
//chiaki_log_hexdump(stream_connection->log, CHIAKI_LOG_DEBUG, buf, buf_size);
}
@ -344,13 +344,13 @@ static ChiakiErrorCode stream_connection_init_crypt(ChiakiStreamConnection *stre
stream_connection->gkcrypt_local = chiaki_gkcrypt_new(stream_connection->log, 0 /* TODO */, 2, session->handshake_key, stream_connection->ecdh_secret);
if(!stream_connection->gkcrypt_local)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to initialize local GKCrypt with index 2\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to initialize local GKCrypt with index 2");
return CHIAKI_ERR_UNKNOWN;
}
stream_connection->gkcrypt_remote = chiaki_gkcrypt_new(stream_connection->log, 0 /* TODO */, 3, session->handshake_key, stream_connection->ecdh_secret);
if(!stream_connection->gkcrypt_remote)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to initialize remote GKCrypt with index 3\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to initialize remote GKCrypt with index 3");
free(stream_connection->gkcrypt_local);
stream_connection->gkcrypt_local = NULL;
return CHIAKI_ERR_UNKNOWN;
@ -380,39 +380,39 @@ static void stream_connection_takion_data_expect_bang(ChiakiStreamConnection *st
bool r = pb_decode(&stream, tkproto_TakionMessage_fields, &msg);
if(!r)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to decode data protobuf\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to decode data protobuf");
return;
}
if(msg.type != tkproto_TakionMessage_PayloadType_BANG || !msg.has_bang_payload)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection expected bang payload but received something else\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection expected bang payload but received something else");
return;
}
CHIAKI_LOGD(stream_connection->log, "Got a bang\n");
CHIAKI_LOGD(stream_connection->log, "Got a bang");
if(!msg.bang_payload.version_accepted)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection bang remote didn't accept version\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection bang remote didn't accept version");
goto error;
}
if(!msg.bang_payload.encrypted_key_accepted)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection bang remote didn't accept encrypted key\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection bang remote didn't accept encrypted key");
goto error;
}
if(!ecdh_pub_key_buf.size)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection didn't get remote ECDH pub key from bang\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection didn't get remote ECDH pub key from bang");
goto error;
}
if(!ecdh_sig_buf.size)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection didn't get remote ECDH sig from bang\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection didn't get remote ECDH sig from bang");
goto error;
}
@ -420,7 +420,7 @@ static void stream_connection_takion_data_expect_bang(ChiakiStreamConnection *st
stream_connection->ecdh_secret = malloc(CHIAKI_ECDH_SECRET_SIZE);
if(!stream_connection->ecdh_secret)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to alloc ECDH secret memory\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to alloc ECDH secret memory");
goto error;
}
@ -434,14 +434,14 @@ static void stream_connection_takion_data_expect_bang(ChiakiStreamConnection *st
{
free(stream_connection->ecdh_secret);
stream_connection->ecdh_secret = NULL;
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to derive secret from bang\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to derive secret from bang");
goto error;
}
err = stream_connection_init_crypt(stream_connection);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to init crypt after receiving bang\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to init crypt after receiving bang");
goto error;
}
@ -474,13 +474,13 @@ static bool pb_decode_resolution(pb_istream_t *stream, const pb_field_t *field,
if(!header_buf.buf)
{
CHIAKI_LOGE(&ctx->stream_connection->session->log, "Failed to decode video header\n");
CHIAKI_LOGE(&ctx->stream_connection->session->log, "Failed to decode video header");
return true;
}
if(ctx->video_profiles_count >= CHIAKI_VIDEO_PROFILES_MAX)
{
CHIAKI_LOGE(&ctx->stream_connection->session->log, "Received more resolutions than the maximum\n");
CHIAKI_LOGE(&ctx->stream_connection->session->log, "Received more resolutions than the maximum");
return true;
}
@ -514,19 +514,19 @@ static void stream_connection_takion_data_expect_streaminfo(ChiakiStreamConnecti
bool r = pb_decode(&stream, tkproto_TakionMessage_fields, &msg);
if(!r)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to decode data protobuf\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to decode data protobuf");
return;
}
if(msg.type != tkproto_TakionMessage_PayloadType_STREAMINFO || !msg.has_stream_info_payload)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection expected streaminfo payload but received something else\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection expected streaminfo payload but received something else");
return;
}
if(audio_header_buf.size != CHIAKI_AUDIO_HEADER_SIZE)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection received invalid audio header in streaminfo\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection received invalid audio header in streaminfo");
goto error;
}
@ -580,12 +580,12 @@ static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream
ssize_t launch_spec_json_size = chiaki_launchspec_format(launch_spec_buf.json, sizeof(launch_spec_buf.json), &launch_spec);
if(launch_spec_json_size < 0)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to format LaunchSpec json\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to format LaunchSpec json");
return CHIAKI_ERR_UNKNOWN;
}
launch_spec_json_size += 1; // we also want the trailing 0
CHIAKI_LOGD(stream_connection->log, "LaunchSpec: %s\n", launch_spec_buf.json);
CHIAKI_LOGD(stream_connection->log, "LaunchSpec: %s", launch_spec_buf.json);
uint8_t launch_spec_json_enc[LAUNCH_SPEC_JSON_BUF_SIZE];
memset(launch_spec_json_enc, 0, (size_t)launch_spec_json_size);
@ -593,7 +593,7 @@ static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream
(size_t)launch_spec_json_size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to encrypt LaunchSpec\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to encrypt LaunchSpec");
return err;
}
@ -601,7 +601,7 @@ static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream
err = chiaki_base64_encode(launch_spec_json_enc, (size_t)launch_spec_json_size, launch_spec_buf.b64, sizeof(launch_spec_buf.b64));
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to encode LaunchSpec as base64\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to encode LaunchSpec as base64");
return err;
}
@ -615,7 +615,7 @@ static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream
ecdh_sig, &ecdh_sig_buf.size);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to get ECDH key and sig\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to get ECDH key and sig");
return err;
}
@ -642,7 +642,7 @@ static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream
bool pbr = pb_encode(&stream, tkproto_TakionMessage_fields, &msg);
if(!pbr)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection big protobuf encoding failed\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection big protobuf encoding failed");
return CHIAKI_ERR_UNKNOWN;
}
@ -665,7 +665,7 @@ static ChiakiErrorCode stream_connection_send_streaminfo_ack(ChiakiStreamConnect
bool pbr = pb_encode(&stream, tkproto_TakionMessage_fields, &msg);
if(!pbr)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection streaminfo ack protobuf encoding failed\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection streaminfo ack protobuf encoding failed");
return CHIAKI_ERR_UNKNOWN;
}
@ -690,7 +690,7 @@ static ChiakiErrorCode stream_connection_send_disconnect(ChiakiStreamConnection
bool pbr = pb_encode(&stream, tkproto_TakionMessage_fields, &msg);
if(!pbr)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection disconnect protobuf encoding failed\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection disconnect protobuf encoding failed");
return CHIAKI_ERR_UNKNOWN;
}
@ -705,7 +705,7 @@ static void stream_connection_takion_av(ChiakiStreamConnection *stream_connectio
{
chiaki_gkcrypt_decrypt(stream_connection->gkcrypt_remote, packet->key_pos + CHIAKI_GKCRYPT_BLOCK_SIZE, packet->data, packet->data_size);
/*CHIAKI_LOGD(stream_connection->log, "AV: index: %u,%u; b@0x1a: %d; is_video: %d; 0xa: %u; 0xc: %u; 0xe: %u; codec: %u; 0x18: %u; adaptive_stream: %u, 0x2c: %u\n",
/*CHIAKI_LOGD(stream_connection->log, "AV: index: %u,%u; b@0x1a: %d; is_video: %d; 0xa: %u; 0xc: %u; 0xe: %u; codec: %u; 0x18: %u; adaptive_stream: %u, 0x2c: %u",
header->packet_index, header->frame_index, header->byte_at_0x1a, header->is_video ? 1 : 0, header->word_at_0xa, header->units_in_frame_total, header->units_in_frame_additional, header->codec,
header->word_at_0x18, header->adaptive_stream_index, header->byte_at_0x2c);
chiaki_log_hexdump(stream_connection->log, CHIAKI_LOG_DEBUG, buf, buf_size);*/
@ -718,21 +718,21 @@ static void stream_connection_takion_av(ChiakiStreamConnection *stream_connectio
{
if(packet->codec == 5/*buf[0] == 0xf4 && buf_size >= 0x50*/)
{
//CHIAKI_LOGD(stream_connection->log, "audio!\n");
//CHIAKI_LOGD(stream_connection->log, "audio!");
chiaki_audio_receiver_frame_packet(stream_connection->session->audio_receiver, packet->data, 0x50); // TODO: why 0x50? this is dangerous!!!
}
else
{
//CHIAKI_LOGD(stream_connection->log, "NON-audio\n");
//CHIAKI_LOGD(stream_connection->log, "NON-audio");
}
}
/*else if(base_type == 2 && buf[0] != 0xf4)
{
CHIAKI_LOGD(stream_connection->log, "av frame 2, which is not audio\n");
CHIAKI_LOGD(stream_connection->log, "av frame 2, which is not audio");
}*/
//CHIAKI_LOGD(stream_connection->log, "StreamConnection AV %lu\n", buf_size);
//CHIAKI_LOGD(stream_connection->log, "StreamConnection AV %lu", buf_size);
//chiaki_log_hexdump(stream_connection->log, CHIAKI_LOG_DEBUG, buf, buf_size);
}
@ -748,7 +748,7 @@ static ChiakiErrorCode stream_connection_send_heartbeat(ChiakiStreamConnection *
bool pbr = pb_encode(&stream, tkproto_TakionMessage_fields, &msg);
if(!pbr)
{
CHIAKI_LOGE(stream_connection->log, "StreamConnection heartbeat protobuf encoding failed\n");
CHIAKI_LOGE(stream_connection->log, "StreamConnection heartbeat protobuf encoding failed");
return CHIAKI_ERR_UNKNOWN;
}

View file

@ -196,19 +196,19 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
takion->postponed_packets_size = 0;
takion->postponed_packets_count = 0;
CHIAKI_LOGI(takion->log, "Takion connecting\n");
CHIAKI_LOGI(takion->log, "Takion connecting");
ChiakiErrorCode err = chiaki_stop_pipe_init(&takion->stop_pipe);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion failed to create stop pipe\n");
CHIAKI_LOGE(takion->log, "Takion failed to create stop pipe");
return err;
}
takion->sock = socket(info->sa->sa_family, SOCK_DGRAM, IPPROTO_UDP);
if(takion->sock < 0)
{
CHIAKI_LOGE(takion->log, "Takion failed to create socket\n");
CHIAKI_LOGE(takion->log, "Takion failed to create socket");
ret = CHIAKI_ERR_NETWORK;
goto error_pipe;
}
@ -217,7 +217,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
int r = setsockopt(takion->sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf_val, sizeof(rcvbuf_val));
if(r < 0)
{
CHIAKI_LOGE(takion->log, "Takion failed to setsockopt SO_RCVBUF: %s\n", strerror(errno));
CHIAKI_LOGE(takion->log, "Takion failed to setsockopt SO_RCVBUF: %s", strerror(errno));
ret = CHIAKI_ERR_NETWORK;
goto error_sock;
}
@ -225,7 +225,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
r = connect(takion->sock, info->sa, info->sa_len);
if(r < 0)
{
CHIAKI_LOGE(takion->log, "Takion failed to connect: %s\n", strerror(errno));
CHIAKI_LOGE(takion->log, "Takion failed to connect: %s", strerror(errno));
ret = CHIAKI_ERR_NETWORK;
goto error_sock;
}
@ -335,7 +335,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send(ChiakiTakion *takion, uint8_t *
if(err != CHIAKI_ERR_SUCCESS)
return err;
//CHIAKI_LOGD(takion->log, "Takion sending:\n");
//CHIAKI_LOGD(takion->log, "Takion sending:");
//chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, buf, buf_size);
return chiaki_takion_send_raw(takion, buf, buf_size);
@ -370,7 +370,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_message_data(ChiakiTakion *taki
err = chiaki_takion_send(takion, packet_buf, packet_size); // will alter packet_buf with gmac
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion failed to send data packet: %s\n", chiaki_error_string(err));
CHIAKI_LOGE(takion->log, "Takion failed to send data packet: %s", chiaki_error_string(err));
free(packet_buf);
return err;
}
@ -501,11 +501,11 @@ static ChiakiErrorCode takion_handshake(ChiakiTakion *takion, uint32_t *seq_num_
err = takion_send_message_init(takion, &init_payload);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion failed to send init\n");
CHIAKI_LOGE(takion->log, "Takion failed to send init");
return err;
}
CHIAKI_LOGI(takion->log, "Takion sent init\n");
CHIAKI_LOGI(takion->log, "Takion sent init");
// INIT_ACK <-
@ -514,17 +514,17 @@ static ChiakiErrorCode takion_handshake(ChiakiTakion *takion, uint32_t *seq_num_
err = takion_recv_message_init_ack(takion, &init_ack_payload);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion failed to receive init ack\n");
CHIAKI_LOGE(takion->log, "Takion failed to receive init ack");
return err;
}
if(init_ack_payload.tag == 0)
{
CHIAKI_LOGE(takion->log, "Takion remote tag in init ack is 0\n");
CHIAKI_LOGE(takion->log, "Takion remote tag in init ack is 0");
return CHIAKI_ERR_INVALID_RESPONSE;
}
CHIAKI_LOGI(takion->log, "Takion received init ack with remote tag %#x, outbound streams: %#x, inbound streams: %#x\n",
CHIAKI_LOGI(takion->log, "Takion received init ack with remote tag %#x, outbound streams: %#x, inbound streams: %#x",
init_ack_payload.tag, init_ack_payload.outbound_streams, init_ack_payload.inbound_streams);
takion->tag_remote = init_ack_payload.tag;
@ -534,7 +534,7 @@ static ChiakiErrorCode takion_handshake(ChiakiTakion *takion, uint32_t *seq_num_
|| init_ack_payload.outbound_streams > TAKION_INBOUND_STREAMS
|| init_ack_payload.inbound_streams < TAKION_OUTBOUND_STREAMS)
{
CHIAKI_LOGE(takion->log, "Takion min/max check failed\n");
CHIAKI_LOGE(takion->log, "Takion min/max check failed");
return CHIAKI_ERR_INVALID_RESPONSE;
}
@ -544,11 +544,11 @@ static ChiakiErrorCode takion_handshake(ChiakiTakion *takion, uint32_t *seq_num_
err = takion_send_message_cookie(takion, init_ack_payload.cookie);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion failed to send cookie\n");
CHIAKI_LOGE(takion->log, "Takion failed to send cookie");
return err;
}
CHIAKI_LOGI(takion->log, "Takion sent cookie\n");
CHIAKI_LOGI(takion->log, "Takion sent cookie");
// COOKIE_ACK <-
@ -556,16 +556,16 @@ static ChiakiErrorCode takion_handshake(ChiakiTakion *takion, uint32_t *seq_num_
err = takion_recv_message_cookie_ack(takion);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion failed to receive cookie ack\n");
CHIAKI_LOGE(takion->log, "Takion failed to receive cookie ack");
return err;
}
CHIAKI_LOGI(takion->log, "Takion received cookie ack\n");
CHIAKI_LOGI(takion->log, "Takion received cookie ack");
// done!
CHIAKI_LOGI(takion->log, "Takion connected\n");
CHIAKI_LOGI(takion->log, "Takion connected");
return CHIAKI_ERR_SUCCESS;
}
@ -573,7 +573,7 @@ static ChiakiErrorCode takion_handshake(ChiakiTakion *takion, uint32_t *seq_num_
static void takion_data_drop(uint64_t seq_num, void *elem_user, void *cb_user)
{
ChiakiTakion *takion = cb_user;
CHIAKI_LOGE(takion->log, "Takion dropping data with seq num %#llx\n", (unsigned long long)seq_num);
CHIAKI_LOGE(takion->log, "Takion dropping data with seq num %#llx", (unsigned long long)seq_num);
TakionDataPacketEntry *entry = elem_user;
free(entry->packet_buf);
free(entry);
@ -613,7 +613,7 @@ static void *takion_thread_func(void *user)
if(takion->enable_crypt && !crypt_available && takion->gkcrypt_remote)
{
crypt_available = true;
CHIAKI_LOGI(takion->log, "Crypt has become available. Re-checking MACs of %llu packets\n", (unsigned long long)chiaki_reorder_queue_count(&takion->data_queue));
CHIAKI_LOGI(takion->log, "Crypt has become available. Re-checking MACs of %llu packets", (unsigned long long)chiaki_reorder_queue_count(&takion->data_queue));
for(uint64_t i=0; i<chiaki_reorder_queue_count(&takion->data_queue); i++)
{
TakionDataPacketEntry *packet;
@ -625,7 +625,7 @@ static void *takion_thread_func(void *user)
uint8_t base_type = (uint8_t)(packet->packet_buf[0] & TAKION_PACKET_BASE_TYPE_MASK);
if(takion_handle_packet_mac(takion, base_type, packet->packet_buf, packet->packet_size) != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGW(takion->log, "Found an invalid MAC\n");
CHIAKI_LOGW(takion->log, "Found an invalid MAC");
chiaki_reorder_queue_drop(&takion->data_queue, i);
}
}
@ -636,7 +636,7 @@ static void *takion_thread_func(void *user)
{
// there are some postponed packets that were waiting until crypt is initialized and it is now :-)
CHIAKI_LOGI(takion->log, "Takion flushing %llu postpone packet(s)\n", (unsigned long long)takion->postponed_packets_count);
CHIAKI_LOGI(takion->log, "Takion flushing %llu postpone packet(s)", (unsigned long long)takion->postponed_packets_count);
for(size_t i=0; i<takion->postponed_packets_count; i++)
{
@ -691,7 +691,7 @@ static ChiakiErrorCode takion_recv(ChiakiTakion *takion, uint8_t *buf, size_t *b
return err;
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion select failed: %s\n", strerror(errno));
CHIAKI_LOGE(takion->log, "Takion select failed: %s", strerror(errno));
return err;
}
@ -699,9 +699,9 @@ static ChiakiErrorCode takion_recv(ChiakiTakion *takion, uint8_t *buf, size_t *b
if(received_sz <= 0)
{
if(received_sz < 0)
CHIAKI_LOGE(takion->log, "Takion recv failed: %s\n", strerror(errno));
CHIAKI_LOGE(takion->log, "Takion recv failed: %s", strerror(errno));
else
CHIAKI_LOGE(takion->log, "Takion recv returned 0\n");
CHIAKI_LOGE(takion->log, "Takion recv returned 0");
return CHIAKI_ERR_NETWORK;
}
*buf_size = (size_t)received_sz;
@ -720,17 +720,17 @@ static ChiakiErrorCode takion_handle_packet_mac(ChiakiTakion *takion, uint8_t ba
ChiakiErrorCode err = chiaki_takion_packet_mac(takion->gkcrypt_remote, buf, buf_size, mac_expected, mac, &key_pos);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Takion failed to calculate mac for received packet\n");
CHIAKI_LOGE(takion->log, "Takion failed to calculate mac for received packet");
return err;
}
if(memcmp(mac_expected, mac, sizeof(mac)) != 0)
{
CHIAKI_LOGE(takion->log, "Takion packet MAC mismatch for packet type %#x with key_pos %#lx\n", base_type, key_pos);
CHIAKI_LOGE(takion->log, "Takion packet MAC mismatch for packet type %#x with key_pos %#lx", base_type, key_pos);
chiaki_log_hexdump(takion->log, CHIAKI_LOG_ERROR, buf, buf_size);
CHIAKI_LOGD(takion->log, "GMAC:\n");
CHIAKI_LOGD(takion->log, "GMAC:");
chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, mac, sizeof(mac));
CHIAKI_LOGD(takion->log, "GMAC expected:\n");
CHIAKI_LOGD(takion->log, "GMAC expected:");
chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, mac_expected, sizeof(mac_expected));
return CHIAKI_ERR_INVALID_MAC;
}
@ -751,11 +751,11 @@ static void takion_postpone_packet(ChiakiTakion *takion, uint8_t *buf, size_t bu
if(takion->postponed_packets_count >= takion->postponed_packets_size)
{
CHIAKI_LOGE(takion->log, "Should postpone a packet, but there is no space left\n");
CHIAKI_LOGE(takion->log, "Should postpone a packet, but there is no space left");
return;
}
CHIAKI_LOGI(takion->log, "Postpone packet of size %#llx\n", (unsigned long long)buf_size);
CHIAKI_LOGI(takion->log, "Postpone packet of size %#llx", (unsigned long long)buf_size);
ChiakiTakionPostponedPacket *packet = &takion->postponed_packets[takion->postponed_packets_count++];
packet->buf = buf;
packet->buf_size = buf_size;
@ -792,7 +792,7 @@ static void takion_handle_packet(ChiakiTakion *takion, uint8_t *buf, size_t buf_
}
break;
default:
CHIAKI_LOGW(takion->log, "Takion packet with unknown type %#x received\n", base_type);
CHIAKI_LOGW(takion->log, "Takion packet with unknown type %#x received", base_type);
free(buf);
//chiaki_log_hexdump(takion->log, CHIAKI_LOG_WARNING, buf, buf_size);
break;
@ -810,7 +810,7 @@ static void takion_handle_packet_message(ChiakiTakion *takion, uint8_t *buf, siz
return;
}
//CHIAKI_LOGD(takion->log, "Takion received message with tag %#x, key pos %#x, type (%#x, %#x), payload size %#x, payload:\n", msg.tag, msg.key_pos, msg.type_a, msg.type_b, msg.payload_size);
//CHIAKI_LOGD(takion->log, "Takion received message with tag %#x, key pos %#x, type (%#x, %#x), payload size %#x, payload:", msg.tag, msg.key_pos, msg.type_a, msg.type_b, msg.payload_size);
//chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, buf, buf_size);
switch(msg.chunk_type)
@ -823,7 +823,7 @@ static void takion_handle_packet_message(ChiakiTakion *takion, uint8_t *buf, siz
free(buf);
break;
default:
CHIAKI_LOGW(takion->log, "Takion received message with unknown chunk type = %#x\n", msg.chunk_type);
CHIAKI_LOGW(takion->log, "Takion received message with unknown chunk type = %#x", msg.chunk_type);
free(buf);
break;
}
@ -849,10 +849,10 @@ static void takion_flush_data_queue(ChiakiTakion *takion)
uint8_t data_type = entry->payload[8]; // & 0xf
if(zero_a != 0)
CHIAKI_LOGW(takion->log, "Takion received data with unexpected nonzero %#x at buf+6\n", zero_a);
CHIAKI_LOGW(takion->log, "Takion received data with unexpected nonzero %#x at buf+6", zero_a);
if(data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF && data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_9)
CHIAKI_LOGW(takion->log, "Takion received data with unexpected data type %#x\n", data_type);
CHIAKI_LOGW(takion->log, "Takion received data with unexpected data type %#x", data_type);
else if(takion->cb)
{
ChiakiTakionEvent event = { 0 };
@ -868,11 +868,11 @@ static void takion_flush_data_queue(ChiakiTakion *takion)
static void takion_handle_packet_message_data(ChiakiTakion *takion, uint8_t *packet_buf, size_t packet_buf_size, uint8_t type_b, uint8_t *payload, size_t payload_size)
{
if(type_b != 1)
CHIAKI_LOGW(takion->log, "Takion received data with type_b = %#x (was expecting %#x)\n", type_b, 1);
CHIAKI_LOGW(takion->log, "Takion received data with type_b = %#x (was expecting %#x)", type_b, 1);
if(payload_size < 9)
{
CHIAKI_LOGE(takion->log, "Takion received data with a size less than the header size\n");
CHIAKI_LOGE(takion->log, "Takion received data with a size less than the header size");
return;
}
@ -897,7 +897,7 @@ static void takion_handle_packet_message_data_ack(ChiakiTakion *takion, uint8_t
{
if(buf_size != 0xc)
{
CHIAKI_LOGE(takion->log, "Takion received data ack with size %#x != %#x\n", buf_size, 0xa);
CHIAKI_LOGE(takion->log, "Takion received data ack with size %#x != %#x", buf_size, 0xa);
return;
}
@ -910,14 +910,14 @@ static void takion_handle_packet_message_data_ack(ChiakiTakion *takion, uint8_t
// so I assume size_or_something may be the size of additional data coming after the data ack header.
if(buf_size != size_internal * 4 + 0xc)
{
CHIAKI_LOGW(takion->log, "Takion received data ack with invalid size_internal = %#x\n", size_internal);
CHIAKI_LOGW(takion->log, "Takion received data ack with invalid size_internal = %#x", size_internal);
return;
}
if(zero != 0)
CHIAKI_LOGW(takion->log, "Takion received data ack with nonzero %#x at buf+0xa\n", zero);
CHIAKI_LOGW(takion->log, "Takion received data ack with nonzero %#x at buf+0xa", zero);
//CHIAKI_LOGD(takion->log, "Takion received data ack with seq_num = %#x, something = %#x, size_or_something = %#x, zero = %#x\n", seq_num, something, size_internal, zero);
//CHIAKI_LOGD(takion->log, "Takion received data ack with seq_num = %#x, something = %#x, size_or_something = %#x, zero = %#x", seq_num, something, size_internal, zero);
chiaki_takion_send_buffer_ack(&takion->send_buffer, seq_num);
}
@ -942,7 +942,7 @@ static ChiakiErrorCode takion_parse_message(ChiakiTakion *takion, uint8_t *buf,
{
if(buf_size < TAKION_MESSAGE_HEADER_SIZE)
{
CHIAKI_LOGE(takion->log, "Takion message received that is too short\n");
CHIAKI_LOGE(takion->log, "Takion message received that is too short");
return CHIAKI_ERR_INVALID_DATA;
}
@ -954,13 +954,13 @@ static ChiakiErrorCode takion_parse_message(ChiakiTakion *takion, uint8_t *buf,
if(msg->tag != takion->tag_local)
{
CHIAKI_LOGE(takion->log, "Takion received message tag mismatch\n");
CHIAKI_LOGE(takion->log, "Takion received message tag mismatch");
return CHIAKI_ERR_INVALID_DATA;
}
if(buf_size != msg->payload_size + 0xc)
{
CHIAKI_LOGE(takion->log, "Takion received message payload size mismatch\n");
CHIAKI_LOGE(takion->log, "Takion received message payload size mismatch");
return CHIAKI_ERR_INVALID_DATA;
}
@ -1014,13 +1014,13 @@ static ChiakiErrorCode takion_recv_message_init_ack(ChiakiTakion *takion, Takion
if(received_size < sizeof(message))
{
CHIAKI_LOGE(takion->log, "Takion received packet of size %#x while expecting init ack packet of exactly %#x\n", received_size, sizeof(message));
CHIAKI_LOGE(takion->log, "Takion received packet of size %#x while expecting init ack packet of exactly %#x", received_size, sizeof(message));
return CHIAKI_ERR_INVALID_RESPONSE;
}
if(message[0] != TAKION_PACKET_TYPE_CONTROL)
{
CHIAKI_LOGE(takion->log, "Takion received packet of type %#x while expecting init ack message with type %#x\n", message[0], TAKION_PACKET_TYPE_CONTROL);
CHIAKI_LOGE(takion->log, "Takion received packet of type %#x while expecting init ack message with type %#x", message[0], TAKION_PACKET_TYPE_CONTROL);
return CHIAKI_ERR_INVALID_RESPONSE;
}
@ -1028,13 +1028,13 @@ static ChiakiErrorCode takion_recv_message_init_ack(ChiakiTakion *takion, Takion
err = takion_parse_message(takion, message + 1, received_size - 1, &msg);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Failed to parse message while expecting init ack\n");
CHIAKI_LOGE(takion->log, "Failed to parse message while expecting init ack");
return CHIAKI_ERR_INVALID_RESPONSE;
}
if(msg.chunk_type != TAKION_CHUNK_TYPE_INIT_ACK || msg.chunk_flags != 0x0)
{
CHIAKI_LOGE(takion->log, "Takion received unexpected message with type (%#x, %#x) while expecting init ack\n", msg.chunk_type, msg.chunk_flags);
CHIAKI_LOGE(takion->log, "Takion received unexpected message with type (%#x, %#x) while expecting init ack", msg.chunk_type, msg.chunk_flags);
return CHIAKI_ERR_INVALID_RESPONSE;
}
@ -1062,13 +1062,13 @@ static ChiakiErrorCode takion_recv_message_cookie_ack(ChiakiTakion *takion)
if(received_size < sizeof(message))
{
CHIAKI_LOGE(takion->log, "Takion received packet of size %#x while expecting cookie ack packet of exactly %#x\n", received_size, sizeof(message));
CHIAKI_LOGE(takion->log, "Takion received packet of size %#x while expecting cookie ack packet of exactly %#x", received_size, sizeof(message));
return CHIAKI_ERR_INVALID_RESPONSE;
}
if(message[0] != TAKION_PACKET_TYPE_CONTROL)
{
CHIAKI_LOGE(takion->log, "Takion received packet of type %#x while expecting cookie ack message with type %#x\n", message[0], TAKION_PACKET_TYPE_CONTROL);
CHIAKI_LOGE(takion->log, "Takion received packet of type %#x while expecting cookie ack message with type %#x", message[0], TAKION_PACKET_TYPE_CONTROL);
return CHIAKI_ERR_INVALID_RESPONSE;
}
@ -1076,13 +1076,13 @@ static ChiakiErrorCode takion_recv_message_cookie_ack(ChiakiTakion *takion)
err = takion_parse_message(takion, message + 1, received_size - 1, &msg);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(takion->log, "Failed to parse message while expecting cookie ack\n");
CHIAKI_LOGE(takion->log, "Failed to parse message while expecting cookie ack");
return CHIAKI_ERR_INVALID_RESPONSE;
}
if(msg.chunk_type != TAKION_CHUNK_TYPE_COOKIE_ACK || msg.chunk_flags != 0x0)
{
CHIAKI_LOGE(takion->log, "Takion received unexpected message with type (%#x, %#x) while expecting cookie ack\n", msg.chunk_type, msg.chunk_flags);
CHIAKI_LOGE(takion->log, "Takion received unexpected message with type (%#x, %#x) while expecting cookie ack", msg.chunk_type, msg.chunk_flags);
return CHIAKI_ERR_INVALID_RESPONSE;
}
@ -1103,7 +1103,7 @@ static void takion_handle_packet_av(ChiakiTakion *takion, uint8_t base_type, uin
if(err != CHIAKI_ERR_SUCCESS)
{
if(err == CHIAKI_ERR_BUF_TOO_SMALL)
CHIAKI_LOGE(takion->log, "Takion received AV packet that was too small\n");
CHIAKI_LOGE(takion->log, "Takion received AV packet that was too small");
return;
}

View file

@ -101,7 +101,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_push(ChiakiTakionSendBuf
if(send_buffer->packets_count >= send_buffer->packets_size)
{
CHIAKI_LOGE(send_buffer->log, "Takion Send Buffer overflow\n");
CHIAKI_LOGE(send_buffer->log, "Takion Send Buffer overflow");
err = CHIAKI_ERR_OVERFLOW;
goto beach;
}
@ -110,7 +110,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_push(ChiakiTakionSendBuf
{
if(send_buffer->packets[i].seq_num == seq_num)
{
CHIAKI_LOGE(send_buffer->log, "Tried to push duplicate seqnum into Takion Send Buffer\n");
CHIAKI_LOGE(send_buffer->log, "Tried to push duplicate seqnum into Takion Send Buffer");
err = CHIAKI_ERR_INVALID_DATA;
goto beach;
}
@ -123,7 +123,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_push(ChiakiTakionSendBuf
packet->buf = buf;
packet->buf_size = buf_size;
CHIAKI_LOGD(send_buffer->log, "Pushed seq num %#llx into Takion Send Buffer\n", (unsigned long long)seq_num);
CHIAKI_LOGD(send_buffer->log, "Pushed seq num %#llx into Takion Send Buffer", (unsigned long long)seq_num);
if(send_buffer->packets_count == 1)
{
@ -151,7 +151,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_ack(ChiakiTakionSendBuff
if(i == send_buffer->packets_count)
{
CHIAKI_LOGW(send_buffer->log, "Takion Send Buffer got ack for seqnum not in buffer\n");
CHIAKI_LOGW(send_buffer->log, "Takion Send Buffer got ack for seqnum not in buffer");
goto beach;
}
@ -162,7 +162,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_ack(ChiakiTakionSendBuff
send_buffer->packets_count--;
CHIAKI_LOGD(send_buffer->log, "Acked seq num %#llx from Takion Send Buffer\n", (unsigned long long)seq_num);
CHIAKI_LOGD(send_buffer->log, "Acked seq num %#llx from Takion Send Buffer", (unsigned long long)seq_num);
beach:
chiaki_mutex_unlock(&send_buffer->mutex);
@ -221,7 +221,7 @@ static void takion_send_buffer_resend(ChiakiTakionSendBuffer *send_buffer)
ChiakiTakionSendBufferPacket *packet = &send_buffer->packets[i];
if(now - packet->last_send_ms > TAKION_DATA_RESEND_TIMEOUT_MS)
{
CHIAKI_LOGI(send_buffer->log, "Takion Send Buffer re-sending packet with seqnum %#llx, tries: %llu\n", (unsigned long long)packet->seq_num, (unsigned long long)packet->tries);
CHIAKI_LOGI(send_buffer->log, "Takion Send Buffer re-sending packet with seqnum %#llx, tries: %llu", (unsigned long long)packet->seq_num, (unsigned long long)packet->tries);
packet->last_send_ms = now;
chiaki_takion_send_raw(send_buffer->takion, packet->buf, packet->buf_size);
packet->tries++;

View file

@ -45,18 +45,18 @@ CHIAKI_EXPORT void chiaki_video_receiver_stream_info(ChiakiVideoReceiver *video_
{
if(video_receiver->profiles_count > 0)
{
CHIAKI_LOGE(video_receiver->log, "Video Receiver profiles already set\n");
CHIAKI_LOGE(video_receiver->log, "Video Receiver profiles already set");
return;
}
memcpy(video_receiver->profiles, profiles, profiles_count * sizeof(ChiakiVideoProfile));
video_receiver->profiles_count = profiles_count;
CHIAKI_LOGI(video_receiver->log, "Video Profiles:\n");
CHIAKI_LOGI(video_receiver->log, "Video Profiles:");
for(size_t i=0; i<video_receiver->profiles_count; i++)
{
ChiakiVideoProfile *profile = &video_receiver->profiles[i];
CHIAKI_LOGI(video_receiver->log, " %zu: %ux%u\n", i, profile->width, profile->height);
CHIAKI_LOGI(video_receiver->log, " %zu: %ux%u", i, profile->width, profile->height);
//chiaki_log_hexdump(video_receiver->log, CHIAKI_LOG_DEBUG, profile->header, profile->header_sz);
}
}
@ -67,7 +67,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
if(video_receiver->frame_index_cur >= 0
&& chiaki_seq_num_16_lt(frame_index, (ChiakiSeqNum16)video_receiver->frame_index_cur))
{
CHIAKI_LOGW(video_receiver->log, "Video Receiver received old frame packet\n");
CHIAKI_LOGW(video_receiver->log, "Video Receiver received old frame packet");
return;
}
@ -75,7 +75,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
{
if(packet->adaptive_stream_index >= video_receiver->profiles_count)
{
CHIAKI_LOGE(video_receiver->log, "Packet has invalid adaptive stream index %lu >= %lu\n",
CHIAKI_LOGE(video_receiver->log, "Packet has invalid adaptive stream index %lu >= %lu",
(unsigned int)packet->adaptive_stream_index,
(unsigned int)video_receiver->profiles_count);
return;
@ -83,7 +83,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
video_receiver->profile_cur = packet->adaptive_stream_index;
ChiakiVideoProfile *profile = video_receiver->profiles + video_receiver->profile_cur;
CHIAKI_LOGI(video_receiver->log, "Switched to profile %d, resolution: %ux%u\n", video_receiver->profile_cur, profile->width, profile->height);
CHIAKI_LOGI(video_receiver->log, "Switched to profile %d, resolution: %ux%u", video_receiver->profile_cur, profile->width, profile->height);
if(video_receiver->session->video_sample_cb)
video_receiver->session->video_sample_cb(profile->header, profile->header_sz, video_receiver->session->video_sample_cb_user);
}
@ -97,7 +97,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
size_t frame_size;
if(chiaki_frame_processor_flush(&video_receiver->frame_processor, &frame, &frame_size) == CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_SUCCESS)
{
//CHIAKI_LOGD(video_receiver->log, "Decoded frame %d\n", (int)video_receiver->frame_index_cur);
//CHIAKI_LOGD(video_receiver->log, "Decoded frame %d", (int)video_receiver->frame_index_cur);
//chiaki_log_hexdump(video_receiver->log, CHIAKI_LOG_DEBUG, frame, frame_size);
if(video_receiver->session->video_sample_cb)
video_receiver->session->video_sample_cb(frame, frame_size, video_receiver->session->video_sample_cb_user);
@ -106,7 +106,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
else
{
// TODO: fake frame?
CHIAKI_LOGW(video_receiver->log, "Failed to complete frame %d\n", (int)video_receiver->frame_index_cur);
CHIAKI_LOGW(video_receiver->log, "Failed to complete frame %d", (int)video_receiver->frame_index_cur);
}
video_receiver->frame_index_prev = video_receiver->frame_index_cur;
@ -115,16 +115,16 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
if(chiaki_seq_num_16_gt(frame_index, (ChiakiSeqNum16)video_receiver->frame_index_cur + 1)
&& !(frame_index == 1 && video_receiver->frame_index_cur < 0)) // ok for frame 1
{
CHIAKI_LOGW(video_receiver->log, "Skipped from frame %d to %d\n", (int)video_receiver->frame_index_cur, (int)frame_index);
CHIAKI_LOGW(video_receiver->log, "Skipped from frame %d to %d", (int)video_receiver->frame_index_cur, (int)frame_index);
// TODO: fake frame?
}
video_receiver->frame_index_cur = frame_index;
//CHIAKI_LOGD(video_receiver->log, "Preparing slots for frame %d\n", (int)video_receiver->frame_index_cur);
//CHIAKI_LOGD(video_receiver->log, "Preparing slots for frame %d", (int)video_receiver->frame_index_cur);
chiaki_frame_processor_alloc_frame(&video_receiver->frame_processor, packet);
}
//CHIAKI_LOGD(video_receiver->log, "Putting unit %lu of frame %d in processor\n",
//CHIAKI_LOGD(video_receiver->log, "Putting unit %lu of frame %d in processor",
// (unsigned int)packet->unit_index, (int)video_receiver->frame_index_cur);
//chiaki_log_hexdump(video_receiver->log, CHIAKI_LOG_DEBUG, packet->data, packet->data_size);
chiaki_frame_processor_put_unit(&video_receiver->frame_processor, packet);