gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6637 - GNUnet/src/applications/chat


From: gnunet
Subject: [GNUnet-SVN] r6637 - GNUnet/src/applications/chat
Date: Thu, 27 Mar 2008 15:03:38 -0600 (MDT)

Author: grothoff
Date: 2008-03-27 15:03:38 -0600 (Thu, 27 Mar 2008)
New Revision: 6637

Added:
   GNUnet/src/applications/chat/chattest.c
Modified:
   GNUnet/src/applications/chat/Makefile.am
   GNUnet/src/applications/chat/chat.c
   GNUnet/src/applications/chat/chat.h
   GNUnet/src/applications/chat/clientapi.c
   GNUnet/src/applications/chat/gnunet-chat.c
Log:
stuff

Modified: GNUnet/src/applications/chat/Makefile.am
===================================================================
--- GNUnet/src/applications/chat/Makefile.am    2008-03-27 02:00:40 UTC (rev 
6636)
+++ GNUnet/src/applications/chat/Makefile.am    2008-03-27 21:03:38 UTC (rev 
6637)
@@ -30,4 +30,19 @@
 libgnunetmodule_chat_la_LIBADD = \
   $(top_builddir)/src/util/libgnunetutil.la
 libgnunetmodule_chat_la_LDFLAGS = \
-  -export-dynamic -avoid-version -module
\ No newline at end of file
+  -export-dynamic -avoid-version -module
+
+
+
+check_PROGRAMS = \
+  chattest
+
+TESTS = $(check_PROGRAMS)
+
+chattest_SOURCES = \
+  chattest.c 
+chattest_LDADD = \
+  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
+  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
+  $(top_builddir)/src/applications/chat/libgnunetchat_api.la \
+  $(top_builddir)/src/util/libgnunetutil.la 

Modified: GNUnet/src/applications/chat/chat.c
===================================================================
--- GNUnet/src/applications/chat/chat.c 2008-03-27 02:00:40 UTC (rev 6636)
+++ GNUnet/src/applications/chat/chat.c 2008-03-27 21:03:38 UTC (rev 6637)
@@ -55,7 +55,7 @@
 
 /* Thread that tells clients about chat room members
  */
-static void *
+static void 
 update_client_thread (void *cls)
 {
   struct GNUNET_CS_chat_client *pos;
@@ -63,11 +63,9 @@
   CS_chat_ROOM_MEMBER_MESSAGE *message;
   int message_size;
 
-  while (shutdown_flag != GNUNET_YES)
-    {
       fprintf (stderr, "Checking room members\n");
+      GNUNET_mutex_lock (chatMutex);
       pos = client_list_head;
-      GNUNET_mutex_lock (chatMutex);
       while (pos != NULL)
         {
           compare_pos = client_list_head;
@@ -100,12 +98,10 @@
           pos = pos->next;
         }
       GNUNET_mutex_unlock (chatMutex);
-      if (shutdown_flag == GNUNET_NO)
-        GNUNET_thread_sleep (30 * GNUNET_CRON_SECONDS);
-    }
-  return NULL;
 }
 
+
+
 static int
 csHandleChatMSG (struct GNUNET_ClientHandle *client,
                  const GNUNET_MessageHeader * message)
@@ -399,7 +395,11 @@
   chatMutex = GNUNET_mutex_create (GNUNET_NO);
 
   coreAPI = capi;
-  GNUNET_thread_create (&update_client_thread, NULL, 1024 * 128);       /* 
What's a good stack size? */
+  GNUNET_cron_add_job(coreAPI->cron,
+                     &update_client_thread,
+                     30 * GNUNET_CRON_SECONDS,
+                     30 * GNUNET_CRON_SECONDS,
+                     NULL);
   GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
                  _("`%s' registering handlers %d and %d\n"),
                  "chat", GNUNET_P2P_PROTO_CHAT_MSG, GNUNET_CS_PROTO_CHAT_MSG);
@@ -433,6 +433,10 @@
 void
 done_module_chat ()
 {
+  GNUNET_cron_del_job(coreAPI->cron,
+                     &update_client_thread,
+                     30 * GNUNET_CRON_SECONDS,
+                     NULL);
   shutdown_flag = GNUNET_YES;
   /*coreAPI->p2p_ciphertext_handler_unregister (GNUNET_P2P_PROTO_CHAT_MSG, 
&handleChatMSG); */
   coreAPI->cs_disconnect_handler_unregister (&chatClientExitHandler);

Modified: GNUnet/src/applications/chat/chat.h
===================================================================
--- GNUnet/src/applications/chat/chat.h 2008-03-27 02:00:40 UTC (rev 6636)
+++ GNUnet/src/applications/chat/chat.h 2008-03-27 21:03:38 UTC (rev 6637)
@@ -42,11 +42,11 @@
 typedef struct
 {
   GNUNET_MessageHeader header;
+  /*  GNUNET_RSA_PublicKey pkey; */
   int nick_len;
   int pubkey_len;
   /*int room_name_len; */
   char nick[1];
-
 } CS_chat_JOIN_MESSAGE;
 
 typedef struct

Added: GNUnet/src/applications/chat/chattest.c
===================================================================
--- GNUnet/src/applications/chat/chattest.c                             (rev 0)
+++ GNUnet/src/applications/chat/chattest.c     2008-03-27 21:03:38 UTC (rev 
6637)
@@ -0,0 +1,89 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005, 2006, 2007, 2008 Christian Grothoff (and other contributing 
authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file applications/chat/chattest.c
+ * @brief chat testcase, loopback only
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_chat_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_stats_lib.h"
+#include "gnunet_util.h"
+
+#define START_PEERS 1
+
+static struct GNUNET_GE_Context *ectx;
+
+static struct GNUNET_GC_Configuration *cfg;
+
+static struct GNUNET_ClientServerConnection *sock;
+
+
+
+/**
+ * Testcase to test chat.
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, char **argv)
+{
+  struct GNUNET_TESTING_DaemonContext *peers;
+  int ret;
+  struct GNUNET_CHAT_Room * r1;
+  struct GNUNET_CHAT_Room * r2;
+
+  ret = 0;
+  cfg = GNUNET_GC_create ();
+  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+#if START_PEERS
+  peers = GNUNET_TESTING_start_daemons ("",
+                                        "chat stats",
+                                        "/tmp/gnunet-chat-test",
+                                        2087, 10, 1);
+  if (peers == NULL)
+    {
+      fprintf (stderr, "Failed to start the gnunetd daemon!\n");
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+#endif
+  r1 = GNUNET_CHAT_join_room(...);
+
+  GNUNET_CHAT_leave_room(r1);  
+
+  GNUNET_shutdown_wait_for ();
+
+#if START_PEERS
+  GNUNET_TESTING_stop_daemons (peers);
+#endif
+
+  GNUNET_GC_free (cfg);
+  return 0;
+}
+
+/* end of chattest.c */

Modified: GNUnet/src/applications/chat/clientapi.c
===================================================================
--- GNUnet/src/applications/chat/clientapi.c    2008-03-27 02:00:40 UTC (rev 
6636)
+++ GNUnet/src/applications/chat/clientapi.c    2008-03-27 21:03:38 UTC (rev 
6637)
@@ -92,7 +92,9 @@
           disconnected = GNUNET_YES;
           continue;
         }
-      if (reply->type == ntohs (GNUNET_CS_PROTO_CHAT_ROOM_MEMBER_MESSAGE))
+      switch (ntohs(reply->type)) {
+      case GNUNET_CS_PROTO_CHAT_ROOM_MEMBER_MESSAGE:
+      case GNUNET_CS_PROTO_CHAT_ROOM_MEMBER_LEAVE_MESSAGE:
         {
           size = ntohs (reply->size);
           received_room_member_msg = (CS_chat_ROOM_MEMBER_MESSAGE *) reply;
@@ -111,16 +113,18 @@
 
           if (GNUNET_OK !=
               room->member_list_callback (room->member_list_callback_cls,
-                                          nick, GNUNET_YES,
+                                          nick, ntohs(reply->type) == 
GNUNET_CS_PROTO_CHAT_ROOM_MEMBER_MESSAGE,
                                           GNUNET_get_time ()))
             {
               GNUNET_GE_BREAK (NULL, 0);
               GNUNET_client_connection_close_temporarily (room->sock);
               disconnected = GNUNET_YES;
               continue;
-            }
+            }   
         }
-      else
+       GNUNET_free (nick);
+       break;
+      case GNUNET_CS_PROTO_CHAT_MSG:
         {
           size = ntohs (reply->size);
           received_msg = (CS_chat_MESSAGE *) reply;
@@ -153,7 +157,12 @@
             }
           GNUNET_free (message_content);
         }
-      GNUNET_free (nick);
+       GNUNET_free (nick);
+       break;
+      default:
+       GNUNET_GE_BREAK(NULL, 0);
+       break;
+      }
     }
   return NULL;
 }
@@ -275,6 +284,15 @@
   join_msg = GNUNET_malloc (size_of_join);
   join_msg->nick_len = htons (strlen (chat_room->nickname));
   join_msg->pubkey_len = htons (sizeof (GNUNET_RSA_PublicKey));
+
+#if FIXED
+  char * nick = (char*) &join_msg[1];
+  memcpy (nick, chat_room->nickname,
+          strlen (chat_room->nickname));
+  memcpy (&nick[strlen (chat_room->nickname)],
+          chat_room->my_public_key, sizeof (GNUNET_RSA_PublicKey));
+#endif
+
   memcpy (&join_msg->nick[0], chat_room->nickname,
           strlen (chat_room->nickname));
   memcpy (&join_msg->nick[strlen (chat_room->nickname)],

Modified: GNUnet/src/applications/chat/gnunet-chat.c
===================================================================
--- GNUnet/src/applications/chat/gnunet-chat.c  2008-03-27 02:00:40 UTC (rev 
6636)
+++ GNUnet/src/applications/chat/gnunet-chat.c  2008-03-27 21:03:38 UTC (rev 
6637)
@@ -92,6 +92,10 @@
 member_list_callback (void *cls, const char *senderNick,
                       int is_joining, GNUNET_CronTime timestamp)
 {
+  fprintf (stdout, is_joining 
+          ? _("`%s' entered the room\n") 
+          : _("`%s' left the room\n"),
+          senderNick);
   return GNUNET_OK;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]