[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6639 - GNUnet/src/applications/chat
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6639 - GNUnet/src/applications/chat |
Date: |
Fri, 28 Mar 2008 13:47:05 -0600 (MDT) |
Author: nevans
Date: 2008-03-28 13:47:04 -0600 (Fri, 28 Mar 2008)
New Revision: 6639
Modified:
GNUnet/src/applications/chat/chat.c
GNUnet/src/applications/chat/chat.h
GNUnet/src/applications/chat/clientapi.c
Log:
Modified: GNUnet/src/applications/chat/chat.c
===================================================================
--- GNUnet/src/applications/chat/chat.c 2008-03-28 18:37:57 UTC (rev 6638)
+++ GNUnet/src/applications/chat/chat.c 2008-03-28 19:47:04 UTC (rev 6639)
@@ -56,7 +56,7 @@
/* Thread that tells clients about chat room members
*/
static void
-update_client_thread (void *cls)
+update_client_members (void *cls)
{
struct GNUNET_CS_chat_client *pos;
struct GNUNET_CS_chat_client *compare_pos;
@@ -200,13 +200,12 @@
GNUNET_HashCode room_name_hash;
char *nick;
- GNUNET_RSA_PublicKey *client_key;
+ GNUNET_RSA_PublicKey client_key;
char *room_name;
int header_size;
int tempCount;
int nick_len;
- int pubkey_len;
int room_name_len;
struct GNUNET_CS_chat_client *tempClient;
@@ -221,30 +220,27 @@
header_size = ntohs (cmsg->header.size);
nick_len = ntohs (cmsg->nick_len);
- pubkey_len = ntohs (cmsg->pubkey_len);
room_name_len =
- header_size - sizeof (CS_chat_JOIN_MESSAGE) - nick_len - pubkey_len;
+ header_size - sizeof (CS_chat_JOIN_MESSAGE) - nick_len;
fprintf (stderr,
- "JOIN_MESSAGE size : %d\nheader_size : %d\nnick_len :
%d\npubkey_len : %d\nroom_name_len : %d\n",
- sizeof (CS_chat_JOIN_MESSAGE), header_size, nick_len, pubkey_len,
- room_name_len);
+ "JOIN_MESSAGE size : %d\nheader_size : %d\nnick_len :
%d\nroom_name_len : %d\n",
+ sizeof (CS_chat_JOIN_MESSAGE), header_size, nick_len,
room_name_len);
fprintf (stderr, "According to my addition, header_size should be %d\n",
- nick_len + pubkey_len + room_name_len +
+ nick_len + room_name_len +
sizeof (CS_chat_JOIN_MESSAGE));
- if (header_size < (nick_len + pubkey_len + room_name_len))
+ if (header_size < (nick_len + room_name_len))
{
GNUNET_GE_BREAK (NULL, 0);
return GNUNET_SYSERR; /* invalid message */
}
nick = GNUNET_malloc (nick_len + 1);
- client_key = GNUNET_malloc (sizeof (GNUNET_RSA_PublicKey));
+ client_key = cmsg->pkey;
room_name = GNUNET_malloc (room_name_len + 1);
memcpy (nick, &cmsg->nick[0], nick_len);
- memcpy (client_key, &cmsg->nick[nick_len], pubkey_len);
- memcpy (room_name, &cmsg->nick[nick_len + pubkey_len], room_name_len);
+ memcpy (room_name, &cmsg->nick[nick_len], room_name_len);
GNUNET_GE_LOG (ectx,
GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_DEVELOPER,
@@ -296,11 +292,11 @@
GNUNET_free (nick);
- GNUNET_free (client_key);
GNUNET_free (room_name);
GNUNET_mutex_unlock (chatMutex);
- fprintf (stderr, "End of handleChatRequest\n");
+ fprintf (stderr, "End of handleChatJoinRequest\n");
+ update_client_members(NULL);
return GNUNET_OK;
}
@@ -395,11 +391,7 @@
chatMutex = GNUNET_mutex_create (GNUNET_NO);
coreAPI = capi;
- 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,10 +425,6 @@
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-28 18:37:57 UTC (rev 6638)
+++ GNUnet/src/applications/chat/chat.h 2008-03-28 19:47:04 UTC (rev 6639)
@@ -32,8 +32,8 @@
typedef struct
{
GNUNET_MessageHeader header;
- int nick_len;
- int msg_len;
+ unsigned short nick_len;
+ unsigned short msg_len;
/*int room_name_len; */
char nick[1];
@@ -42,17 +42,15 @@
typedef struct
{
GNUNET_MessageHeader header;
- /* GNUNET_RSA_PublicKey pkey; */
- int nick_len;
- int pubkey_len;
- /*int room_name_len; */
+ GNUNET_RSA_PublicKey pkey;
+ unsigned short nick_len;
char nick[1];
} CS_chat_JOIN_MESSAGE;
typedef struct
{
GNUNET_MessageHeader header;
- int nick_len;
+ unsigned short nick_len;
char nick[1];
} CS_chat_ROOM_MEMBER_MESSAGE;
@@ -73,8 +71,6 @@
char *room_name;
- GNUNET_HashCode room_name_hash;
-
const GNUNET_RSA_PublicKey *my_public_key;
GNUNET_HashCode my_public_key_hash;
Modified: GNUnet/src/applications/chat/clientapi.c
===================================================================
--- GNUnet/src/applications/chat/clientapi.c 2008-03-28 18:37:57 UTC (rev
6638)
+++ GNUnet/src/applications/chat/clientapi.c 2008-03-28 19:47:04 UTC (rev
6639)
@@ -31,8 +31,6 @@
#include "gnunet_chat_lib.h"
#include "chat.h"
-static struct GNUNET_Mutex *chatMutex;
-
/**
* Listen for incoming messages on this chat room. When received,
* call the proper client callback. Also, support servers going away/coming
@@ -100,7 +98,7 @@
received_room_member_msg = (CS_chat_ROOM_MEMBER_MESSAGE *) reply;
nick_len = ntohs (received_room_member_msg->nick_len);
- if (size < nick_len)
+ if (size - sizeof(GNUNET_MessageHeader) < nick_len)
{
GNUNET_GE_BREAK (NULL, 0);
GNUNET_client_connection_close_temporarily (room->sock);
@@ -133,7 +131,7 @@
/* NO NEED TO SEND ROOM! */
room_name_len =
size - nick_len - msg_len - sizeof (CS_chat_MESSAGE);
- if (size < (nick_len + msg_len + room_name_len))
+ if (size - sizeof(GNUNET_MessageHeader) < (nick_len + msg_len +
room_name_len))
{
GNUNET_GE_BREAK (NULL, 0);
GNUNET_client_connection_close_temporarily (room->sock);
@@ -204,11 +202,9 @@
{
CS_chat_JOIN_MESSAGE *join_msg;
GNUNET_HashCode hash_of_me;
- GNUNET_HashCode hash_of_room_name;
struct GNUNET_CHAT_Room *chat_room;
struct GNUNET_ClientServerConnection *sock;
int size_of_join;
- chatMutex = GNUNET_mutex_create (GNUNET_NO);
sock = GNUNET_client_connection_create (ectx, cfg);
if (sock == NULL)
@@ -218,19 +214,18 @@
}
GNUNET_hash (me, sizeof (GNUNET_RSA_PublicKey), &hash_of_me);
- GNUNET_hash (room_name, strlen (room_name), &hash_of_room_name);
size_of_join =
- sizeof (CS_chat_JOIN_MESSAGE) + strlen (nickname) +
- sizeof (GNUNET_RSA_PublicKey) + strlen (room_name);
+ sizeof (CS_chat_JOIN_MESSAGE) + strlen (nickname) + strlen (room_name);
join_msg = GNUNET_malloc (size_of_join);
join_msg->header.size = htons (size_of_join);
join_msg->header.type = htons (GNUNET_CS_PROTO_CHAT_JOIN_MSG);
join_msg->nick_len = htons (strlen (nickname));
- join_msg->pubkey_len = htons (sizeof (GNUNET_RSA_PublicKey));
+ memcpy(&join_msg->pkey,me,sizeof(GNUNET_RSA_PublicKey));
+ //join_msg->pubkey_len = htons (sizeof (GNUNET_RSA_PublicKey));
memcpy (&join_msg->nick[0], nickname, strlen (nickname));
- memcpy (&join_msg->nick[strlen (nickname)], me,
- sizeof (GNUNET_RSA_PublicKey));
- memcpy (&join_msg->nick[strlen (nickname) + sizeof (GNUNET_RSA_PublicKey)],
+ //memcpy (&join_msg->nick[strlen (nickname)], me,
+ // sizeof (GNUNET_RSA_PublicKey));
+ memcpy (&join_msg->nick[strlen (nickname)],
room_name, strlen (room_name));
if (GNUNET_SYSERR ==
GNUNET_client_connection_write (sock, &join_msg->header))
@@ -245,7 +240,6 @@
chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room));
chat_room->nickname = GNUNET_strdup (nickname);
chat_room->room_name = GNUNET_strdup (room_name);
- chat_room->room_name_hash = hash_of_room_name;
chat_room->my_public_key = me;
chat_room->my_public_key_hash = hash_of_me;
chat_room->my_private_key = key;
@@ -279,26 +273,21 @@
GNUNET_hash (chat_room->room_name, strlen (chat_room->room_name),
&hash_of_room_name);
size_of_join =
- sizeof (CS_chat_JOIN_MESSAGE) + strlen (chat_room->nickname) +
- sizeof (GNUNET_RSA_PublicKey) + strlen (chat_room->room_name);
+ sizeof (CS_chat_JOIN_MESSAGE) + strlen (chat_room->nickname) + strlen
(chat_room->room_name);
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));
+
memcpy(&join_msg->pkey,chat_room->my_public_key,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)],
- chat_room->my_public_key, sizeof (GNUNET_RSA_PublicKey));
memcpy (&join_msg->
- nick[strlen (chat_room->nickname) + sizeof (GNUNET_RSA_PublicKey)],
+ nick[strlen (chat_room->nickname)],
chat_room->room_name, strlen (chat_room->room_name));
join_msg->header = csHdr;
join_msg->header.size = htons (size_of_join);
@@ -319,7 +308,7 @@
void
GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room)
{
- GNUNET_mutex_lock (chatMutex);
+
void *unused;
chat_room->shutdown_flag = GNUNET_YES;
GNUNET_client_connection_close_forever (chat_room->sock);
@@ -330,7 +319,7 @@
GNUNET_free (chat_room->memberInfo);
GNUNET_client_connection_destroy (chat_room->sock);
GNUNET_free (chat_room);
- GNUNET_mutex_unlock (chatMutex);
+
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6639 - GNUnet/src/applications/chat,
gnunet <=