|
13 | 13 |
|
14 | 14 | #include "valent-certificate.h" |
15 | 15 | #include "valent-packet.h" |
| 16 | +#include "valent-packet-input-stream.h" |
16 | 17 |
|
17 | 18 | #include "valent-channel.h" |
18 | 19 |
|
@@ -55,7 +56,7 @@ typedef struct |
55 | 56 | JsonNode *peer_identity; |
56 | 57 |
|
57 | 58 | /* Packet Buffer */ |
58 | | - GDataInputStream *input_buffer; |
| 59 | + ValentPacketInputStream *input_buffer; |
59 | 60 | GMainLoop *output_buffer; |
60 | 61 | } ValentChannelPrivate; |
61 | 62 |
|
@@ -278,10 +279,13 @@ valent_channel_set_base_stream (ValentChannel *self, |
278 | 279 | g_autoptr (GThread) thread = NULL; |
279 | 280 | g_autoptr (GError) error = NULL; |
280 | 281 |
|
| 282 | + // FIXME: associate the device paired state with the channel trust |
281 | 283 | input_stream = g_io_stream_get_input_stream (base_stream); |
282 | | - priv->input_buffer = g_object_new (G_TYPE_DATA_INPUT_STREAM, |
| 284 | + priv->input_buffer = g_object_new (VALENT_TYPE_PACKET_INPUT_STREAM, |
283 | 285 | "base-stream", input_stream, |
| 286 | + "buffer-size", VALENT_PACKET_DEFAULT_BUFFER_SIZE, |
284 | 287 | "close-base-stream", FALSE, |
| 288 | + "trusted", TRUE, |
285 | 289 | NULL); |
286 | 290 |
|
287 | 291 | context = g_main_context_new (); |
@@ -761,34 +765,15 @@ valent_channel_close_finish (ValentChannel *channel, |
761 | 765 | } |
762 | 766 |
|
763 | 767 | static void |
764 | | -valent_channel_read_packet_cb (GObject *object, |
765 | | - GAsyncResult *result, |
766 | | - gpointer user_data) |
| 768 | +valent_channel_read_packet_cb (ValentPacketInputStream *stream, |
| 769 | + GAsyncResult *result, |
| 770 | + gpointer user_data) |
767 | 771 | { |
768 | 772 | g_autoptr (GTask) task = G_TASK (g_steal_pointer (&user_data)); |
769 | | - g_autofree char *line = NULL; |
770 | 773 | JsonNode *packet = NULL; |
771 | 774 | GError *error = NULL; |
772 | 775 |
|
773 | | - line = g_data_input_stream_read_line_finish_utf8 (G_DATA_INPUT_STREAM (object), |
774 | | - result, |
775 | | - NULL, |
776 | | - &error); |
777 | | - if (error != NULL) |
778 | | - { |
779 | | - g_task_return_error (task, g_steal_pointer (&error)); |
780 | | - return; |
781 | | - } |
782 | | - else if (line == NULL) |
783 | | - { |
784 | | - g_task_return_new_error (task, |
785 | | - G_IO_ERROR, |
786 | | - G_IO_ERROR_CONNECTION_CLOSED, |
787 | | - "Channel is closed"); |
788 | | - return; |
789 | | - } |
790 | | - |
791 | | - packet = valent_packet_deserialize (line, &error); |
| 776 | + packet = valent_packet_input_stream_read_packet_finish (stream, result, &error); |
792 | 777 | if (packet == NULL) |
793 | 778 | { |
794 | 779 | g_task_return_error (task, g_steal_pointer (&error)); |
@@ -832,11 +817,10 @@ valent_channel_read_packet (ValentChannel *channel, |
832 | 817 |
|
833 | 818 | if (!valent_channel_return_error_if_closed (channel, task)) |
834 | 819 | { |
835 | | - g_data_input_stream_read_line_async (priv->input_buffer, |
836 | | - G_PRIORITY_DEFAULT, |
837 | | - cancellable, |
838 | | - valent_channel_read_packet_cb, |
839 | | - g_object_ref (task)); |
| 820 | + valent_packet_input_stream_read_packet_async (priv->input_buffer, |
| 821 | + cancellable, |
| 822 | + (GAsyncReadyCallback)valent_channel_read_packet_cb, |
| 823 | + g_object_ref (task)); |
840 | 824 | valent_object_unlock (VALENT_OBJECT (channel)); |
841 | 825 | } |
842 | 826 |
|
|
0 commit comments