Ping a friend when we get it from the cache
[cascardo/f2fchat.git] / message.c
index 7c73006..8e3202d 100644 (file)
--- a/message.c
+++ b/message.c
@@ -52,15 +52,24 @@ gboolean message_incoming(GIOChannel *channel, GIOCondition cond, gpointer data)
        iaddress = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address));
        if (g_inet_address_get_is_loopback(iaddress)) {
                command(buffer, len);
+       } else {
+               struct friend *friend;
+               friend = friend_get_by_address(iaddress);
+               if (friend) {
+                       printf("got message from %s\n", friend_get_name(friend));
+                       g_source_remove_by_user_data(friend);
+               } else {
+                       printf("could not find friend from address %s\n", g_inet_address_to_string(iaddress));
+               }
        }
        g_object_unref(address);
        g_free(buffer);
        return TRUE;
 }
 
-int message_init(int sock)
+int message_init(GSocket *sock)
 {
-       uchannel = g_io_channel_unix_new(sock);
+       uchannel = g_io_channel_unix_new(g_socket_get_fd(sock));
        g_io_add_watch(uchannel, G_IO_IN, message_incoming, NULL);
        return 0;
 }