gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r6929 - in GNUnet: . src/applications/chat


From: gnunet
Subject: [GNUnet-SVN] r6929 - in GNUnet: . src/applications/chat
Date: Thu, 29 May 2008 23:09:20 -0600 (MDT)

Author: grothoff
Date: 2008-05-29 23:09:18 -0600 (Thu, 29 May 2008)
New Revision: 6929

Modified:
   GNUnet/src/applications/chat/chat.c
   GNUnet/todo
Log:
chat module now compiles again

Modified: GNUnet/src/applications/chat/chat.c
===================================================================
--- GNUnet/src/applications/chat/chat.c 2008-05-30 04:36:48 UTC (rev 6928)
+++ GNUnet/src/applications/chat/chat.c 2008-05-30 05:09:18 UTC (rev 6929)
@@ -42,9 +42,17 @@
 
   struct GNUNET_ClientHandle *client;
 
-  char *nick;
+  struct GNUNET_RSA_PrivateKey * private_key;
 
   char *room;
+
+  /**
+   * Hash of the public key (for convenience).
+   */
+  GNUNET_HashCode id;
+
+  unsigned int msg_options;
+
 };
 
 static struct GNUNET_CS_chat_client *client_list_head;
@@ -53,69 +61,29 @@
 
 static struct GNUNET_Mutex *chatMutex;
 
-/**
- * Tell clients about change in chat room members
- * 
- * @param has_joined GNUNET_YES if the member joined,
- *                   GNUNET_NO if the member left
- */
-static void
-update_client_members (const char * room_name,
-                      const char * nick,
-                      int has_joined)
-{
-  struct GNUNET_CS_chat_client *pos;
-  struct GNUNET_CS_chat_client *compare_pos;
-  CS_chat_ROOM_MEMBER_MESSAGE *message;
-  unsigned int message_size;
-
-  message_size =
-    sizeof (CS_chat_ROOM_MEMBER_MESSAGE) +
-    strlen (nick);
-  message = GNUNET_malloc (message_size);
-  message->header.size = htons (message_size);
-  message->header.type =
-    htons (GNUNET_CS_PROTO_CHAT_ROOM_MEMBER_MESSAGE);
-  message->nick_len = htons (strlen (nick));
-  memcpy (&message[1],
-         nick,
-         strlen (nick));
-  GNUNET_mutex_lock (chatMutex);
-  pos = client_list_head;
-  while (pos != NULL)
-    {
-      if (0 != strcmp(pos->room,
-                     room_name))
-       {
-         pos = pos->next;
-         continue;
-       }
-      coreAPI->cs_send_message (pos->client, &message->header,
-                               GNUNET_YES);      
-      pos = pos->next;
-    }
-  GNUNET_mutex_unlock (chatMutex);
-  GNUNET_free(message);  
-}
-
-
 static int
-csHandleChatMSG (struct GNUNET_ClientHandle *client,
-                 const GNUNET_MessageHeader * message)
+csHandleTransmitRequest (struct GNUNET_ClientHandle *client,
+                        const GNUNET_MessageHeader * message)
 {
-  const CS_chat_MESSAGE *cmsg;
+  const CS_chat_MESSAGE_TransmitRequest *cmsg;
+  CS_chat_MESSAGE_ReceiveNotification *rmsg;
   struct GNUNET_CS_chat_client *pos;
-  const char *nick;
   const char *room;
-  unsigned short header_size;
-  unsigned long msg_len;
+  unsigned int msg_len;
 
-  if (ntohs (message->size) < sizeof (CS_chat_MESSAGE))
+  if (ntohs (message->size) < sizeof (CS_chat_MESSAGE_TransmitRequest))
     {
       GNUNET_GE_BREAK (NULL, 0);
       return GNUNET_SYSERR;     /* invalid message */
     }
-  cmsg = (const CS_chat_MESSAGE *) message;
+  cmsg = (const CS_chat_MESSAGE_TransmitRequest *) message;
+  msg_len = ntohs(message->size) - sizeof(CS_chat_MESSAGE_TransmitRequest);
+  rmsg = GNUNET_malloc(sizeof(CS_chat_MESSAGE_ReceiveNotification) + 
+                      msg_len);
+  rmsg->header.size = htons(sizeof(CS_chat_MESSAGE_ReceiveNotification) + 
+                           msg_len);
+  rmsg->header.type = htons(GNUNET_CS_PROTO_CHAT_MESSAGE_NOTIFICATION);
+  rmsg->msg_options = cmsg->msg_options;
   GNUNET_mutex_lock (chatMutex);
 
   pos = client_list_head;
@@ -125,22 +93,30 @@
     {
       GNUNET_mutex_unlock (chatMutex);
       GNUNET_GE_BREAK (NULL, 0);
+      GNUNET_free(rmsg);
       return GNUNET_SYSERR;     /* not member of chat room! */
     }
-  room = pos->room;
-  nick = pos->nick;
+  room = pos->room;  
+  if ((ntohl(cmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS) == 0)
+    rmsg->sender = pos->id;
+  else
+    memset(&rmsg->sender, 0, sizeof(GNUNET_HashCode));
   pos = client_list_head;
   while (pos != NULL) 
     {
       if (0 == strcmp(room,
                      pos->room))
        {
-         /* fixme: private / anonymous delivery options! */
-         coreAPI->cs_send_message (pos->client, message, GNUNET_YES);
+         /* FIXME: private msg delivery, blocking options,
+            confirmation */
+         coreAPI->cs_send_message (pos->client,
+                                   &rmsg->header,
+                                   GNUNET_YES);
        }
       pos = pos->next;
     }
   GNUNET_mutex_unlock (chatMutex);
+  GNUNET_free(rmsg);
   return GNUNET_OK;
 }
 
@@ -148,58 +124,88 @@
 csHandleChatJoinRequest (struct GNUNET_ClientHandle *client,
                          const GNUNET_MessageHeader * message)
 {
-  const CS_chat_JOIN_MESSAGE *cmsg;
-  char *nick;
+  const CS_chat_MESSAGE_JoinRequest *cmsg;
   char *room_name;
-  int header_size;
-  int nick_len;
-  int room_name_len;
+  const char * roomptr;
+  unsigned int header_size;
+  unsigned int meta_len;
+  unsigned int room_name_len;
   struct GNUNET_CS_chat_client *entry;
+  GNUNET_RSA_PublicKey pkey;
+  CS_chat_MESSAGE_JoinNotification * nmsg;
 
-  if (ntohs (message.size) < sizeof (CS_chat_JOIN_MESSAGE))
+  if (ntohs (message->size) < sizeof (CS_chat_MESSAGE_JoinRequest))
     {
       GNUNET_GE_BREAK (NULL, 0);
       return GNUNET_SYSERR;     /* invalid message */
     }
-  cmsg = (const CS_chat_JOIN_MESSAGE *) message;
+  cmsg = (const CS_chat_MESSAGE_JoinRequest *) message;
   header_size = ntohs (cmsg->header.size);
-  nick_len = ntohs (cmsg->nick_len);
-  if (header_size - sizeof (CS_chat_JOIN_MESSAGE) <= nick_len)
+  room_name_len = ntohs (cmsg->room_name_len);  
+  if (header_size - sizeof (CS_chat_MESSAGE_JoinRequest) <= room_name_len)
     {
       GNUNET_GE_BREAK (NULL, 0);
       return GNUNET_SYSERR;
     }
-  room_name_len = header_size - sizeof (CS_chat_JOIN_MESSAGE) - nick_len;
-  nick = GNUNET_malloc (nick_len + 1);
-  memcpy (nick, &cmsg->nick[0], nick_len);
-  nick[nick_len] = '\0';
+  meta_len = header_size - sizeof (CS_chat_MESSAGE_JoinRequest) - 
room_name_len;  
+
+  roomptr = (const char*) &cmsg[1];
   room_name = GNUNET_malloc (room_name_len + 1);
-  memcpy (room_name, &cmsg->nick[nick_len], room_name_len);
+  memcpy (room_name, roomptr, room_name_len);
   room_name[room_name_len] = '\0';
+  
   entry = GNUNET_malloc (sizeof (struct GNUNET_CS_chat_client));
   memset (entry, 0, sizeof (struct GNUNET_CS_chat_client));
   entry->client = client;
-  entry->nick = nick;
   entry->room = room_name; 
+  entry->private_key = GNUNET_RSA_decode_key(&cmsg->private_key);
+  if (entry->private_key == NULL)
+    {
+      GNUNET_GE_BREAK(NULL, 0);
+      GNUNET_free(room_name);
+      GNUNET_free(entry);
+      return GNUNET_SYSERR;
+    }
+  GNUNET_RSA_get_public_key(entry->private_key,
+                           &pkey);
+  GNUNET_hash(&pkey,
+             sizeof(GNUNET_RSA_PublicKey),
+             &entry->id);
+  entry->msg_options = ntohl(cmsg->msg_options);
+
+
+  nmsg = GNUNET_malloc(sizeof(CS_chat_MESSAGE_JoinNotification) + meta_len);
+  nmsg->header.type = htons(GNUNET_CS_PROTO_CHAT_JOIN_NOTIFICATION);
+  nmsg->header.size = htons(sizeof(CS_chat_MESSAGE_JoinNotification) + 
meta_len);
+  nmsg->msg_options = cmsg->msg_options;
+  nmsg->public_key = pkey;
+  memcpy(&nmsg[1],
+        &roomptr[room_name_len],
+        meta_len);
   GNUNET_mutex_lock (chatMutex);
   entry->next = client_list_head;
   client_list_head = entry;
+  while (entry != NULL)
+    {
+      if (0 == strcmp(room_name,
+                     entry->room))     
+       coreAPI->cs_send_message (entry->client,
+                                 &nmsg->header,
+                                 GNUNET_YES);  
+      entry = entry->next;
+    }
   GNUNET_mutex_unlock (chatMutex);
-  update_client_members (room_name, nick, GNUNET_YES);
+  GNUNET_free(nmsg);
   return GNUNET_OK;
 }
 
-
 static void
 chatClientExitHandler (struct GNUNET_ClientHandle *client)
 {
-  int tempCount;
-  int message_size;
   struct GNUNET_CS_chat_client *entry;
   struct GNUNET_CS_chat_client *pos;
   struct GNUNET_CS_chat_client *prev;
-  char *nick_to_remove;
-  CS_chat_ROOM_MEMBER_MESSAGE *message;
+  CS_chat_MESSAGE_LeaveNotification lmsg;
 
   GNUNET_mutex_lock (chatMutex);
   pos = client_list_head;
@@ -218,12 +224,24 @@
     client_list_head = pos->next;
   else
     prev->next = pos->next;
+  entry = client_list_head;
+  lmsg.header.size = htons(sizeof(CS_chat_MESSAGE_LeaveNotification));
+  lmsg.header.type = htons(GNUNET_CS_PROTO_CHAT_LEAVE_NOTIFICATION);
+  lmsg.reserved = htonl(0);
+  GNUNET_RSA_get_public_key(pos->private_key,
+                           &lmsg.user);
+  while (entry != NULL) 
+    {
+      if (0 == strcmp(entry->room,
+                     pos->room))
+       coreAPI->cs_send_message (entry->client,
+                                 &lmsg.header,
+                                 GNUNET_YES);  
+      entry = entry->next;
+    }
   GNUNET_mutex_unlock (chatMutex);
-  update_client_members(pos->room,
-                       pos->nick,
-                       GNUNET_NO);
   GNUNET_free (pos->room);
-  GNUNET_free (pos->nick);
+  GNUNET_RSA_free_key (pos->private_key);
   GNUNET_free (pos);
 }
 
@@ -237,19 +255,19 @@
                 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
                  _("`%s' registering CS handlers %d and %d\n"),
                  "chat", 
-                GNUNET_CS_PROTO_CHAT_JOIN_MSG, GNUNET_CS_PROTO_CHAT_MSG);
+                GNUNET_CS_PROTO_CHAT_JOIN_REQUEST, 
GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST);
 
   if (GNUNET_SYSERR ==
       capi->cs_disconnect_handler_register (&chatClientExitHandler))
     ok = GNUNET_SYSERR;  
   if (GNUNET_SYSERR ==
-      capi->cs_handler_register (GNUNET_CS_PROTO_CHAT_JOIN_MSG,
+      capi->cs_handler_register (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
                                  &csHandleChatJoinRequest))
     ok = GNUNET_SYSERR;
-  if (GNUNET_SYSERR == capi->cs_handler_register (GNUNET_CS_PROTO_CHAT_MSG,
-                                                  &csHandleChatMSG))
+  if (GNUNET_SYSERR == capi->cs_handler_register 
(GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST,
+                                                  &csHandleTransmitRequest))
     ok = GNUNET_SYSERR;
-  GNUNET_GE_ASSERT (capi->coreAPI->ectx,
+  GNUNET_GE_ASSERT (capi->ectx,
                     0 == GNUNET_GC_set_configuration_value_string (capi->cfg,
                                                                    capi->ectx,
                                                                    "ABOUT",
@@ -264,8 +282,8 @@
 done_module_chat ()
 {
   coreAPI->cs_disconnect_handler_unregister (&chatClientExitHandler);
-  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_MSG, &csHandleChatMSG);
-  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_JOIN_MSG,
+  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST, 
&csHandleTransmitRequest);
+  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
                                   &csHandleChatJoinRequest);
   GNUNET_mutex_destroy (chatMutex);
   coreAPI = NULL;

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2008-05-30 04:36:48 UTC (rev 6928)
+++ GNUnet/todo 2008-05-30 05:09:18 UTC (rev 6929)
@@ -14,8 +14,8 @@
   + tools: compile errors!
 - chat:  [RC]
   + adapt gnunet-chat for new client api
-  + adapt clientapi.c for new API and message format
-  + adapt chat.c for new message format and requirements
+  + support private message delivery, confirmations and
+    blocking options in chat.c
 - Windows: gnunet-auto-share
 - document gnunet-auto-share on webpage [RC]
 





reply via email to

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