[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6192 - GNUnet/src/applications/chat
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6192 - GNUnet/src/applications/chat |
Date: |
Thu, 7 Feb 2008 19:18:56 -0700 (MST) |
Author: nevans
Date: 2008-02-07 19:18:55 -0700 (Thu, 07 Feb 2008)
New Revision: 6192
Modified:
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:
Modified: GNUnet/src/applications/chat/chat.c
===================================================================
--- GNUnet/src/applications/chat/chat.c 2008-02-07 07:58:25 UTC (rev 6191)
+++ GNUnet/src/applications/chat/chat.c 2008-02-08 02:18:55 UTC (rev 6192)
@@ -87,19 +87,28 @@
CS_chat_MESSAGE *cmsg;
P2P_chat_MESSAGE *pmsg;
GNUNET_HashCode hc;
+ char *nick;
+ char *message_content;
- if (ntohs (message->size) != sizeof (P2P_chat_MESSAGE))
- {
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
- _("Message received from peer is invalid.\n"));
- return GNUNET_SYSERR;
- }
pmsg = (P2P_chat_MESSAGE *) message;
cmsg = (CS_chat_MESSAGE *) message;
+ cmsg->header.size = ntohs(cmsg->header.size);
+ cmsg->nick_len = ntohl(cmsg->nick_len);
+ cmsg->msg_len = ntohl(cmsg->msg_len);
+
+ nick = GNUNET_malloc(cmsg->nick_len + 1);
+ message_content = GNUNET_malloc(cmsg->msg_len + 1);
+ bzero(nick,sizeof(nick));
+ bzero(message_content,sizeof(message_content));
+
+ memcpy(nick,&cmsg->nick[0],cmsg->nick_len);
+ memcpy(message_content,&cmsg->nick[sizeof(nick)],cmsg->msg_len);
+
+
+ GNUNET_hash (pmsg, cmsg->header.size, &hc);
/* check if we have seen this message already */
- GNUNET_hash (pmsg, sizeof (P2P_chat_MESSAGE), &hc);
+
j = -1;
GNUNET_mutex_lock (chatMutex);
for (i = 0; i < MAX_LAST_MESSAGES; i++)
@@ -114,8 +123,9 @@
cmsg->header.type = htons (GNUNET_CS_PROTO_CHAT_MSG);
for (j = 0; j < clientCount; j++)
coreAPI->cs_send_to_client (clients[j], &cmsg->header,GNUNET_YES);
- pmsg->nick[CHAT_NICK_LENGTH - 1] = '\0';
- pmsg->message[CHAT_MSG_LENGTH - 1] = '\0';
+ /*pmsg->nick[CHAT_NICK_LENGTH - 1] = '\0';
+ pmsg->message[CHAT_MSG_LENGTH - 1] = '\0';*/
+
/*
GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
GNUNET_GE_USER,
" CHAT: received new message from %s: %s\n",
@@ -136,17 +146,36 @@
CS_chat_MESSAGE *cmsg;
P2P_chat_MESSAGE *pmsg;
GNUNET_HashCode hc;
+ char *nick;
+ char *message_content;
- if (ntohs (message->size) != sizeof (CS_chat_MESSAGE))
+ /*if (ntohs (message->size) != sizeof (CS_chat_MESSAGE))
{
GNUNET_GE_LOG (ectx,
GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
_("Message received from client is invalid\n"));
- return GNUNET_SYSERR; /* invalid message */
+ return GNUNET_SYSERR; */ /* invalid message */
+ /*
}
+ */
+
pmsg = (P2P_chat_MESSAGE *) message;
cmsg = (CS_chat_MESSAGE *) message;
- GNUNET_hash (pmsg, sizeof (P2P_chat_MESSAGE), &hc);
+
+ cmsg->header.size = ntohs(cmsg->header.size);
+ cmsg->nick_len = ntohl(cmsg->nick_len);
+ cmsg->msg_len = ntohl(cmsg->msg_len);
+
+ nick = GNUNET_malloc(cmsg->nick_len + 1);
+ message_content = GNUNET_malloc(cmsg->msg_len + 1);
+ bzero(nick,sizeof(nick));
+ bzero(message_content,sizeof(message_content));
+
+ memcpy(nick,&cmsg->nick[0],cmsg->nick_len);
+ memcpy(message_content,&cmsg->nick[sizeof(nick)],cmsg->msg_len);
+
+
+ GNUNET_hash (pmsg, cmsg->header.size, &hc);
GNUNET_mutex_lock (chatMutex);
markSeen (&hc);
Modified: GNUnet/src/applications/chat/chat.h
===================================================================
--- GNUnet/src/applications/chat/chat.h 2008-02-07 07:58:25 UTC (rev 6191)
+++ GNUnet/src/applications/chat/chat.h 2008-02-08 02:18:55 UTC (rev 6192)
@@ -28,21 +28,24 @@
#include "gnunet_core.h"
-#define CHAT_NICK_LENGTH 32
-#define CHAT_MSG_LENGTH 1024
-
typedef struct
{
GNUNET_MessageHeader header;
- char nick[CHAT_NICK_LENGTH];
- char message[CHAT_MSG_LENGTH];
+ unsigned long nick_len;
+ unsigned long msg_len;
+ char nick[1];
+ char message[1];
} P2P_chat_MESSAGE;
typedef struct
{
GNUNET_MessageHeader header;
- char nick[CHAT_NICK_LENGTH];
- char message[CHAT_MSG_LENGTH];
+ unsigned long nick_len;
+ unsigned long msg_len;
+ unsigned long room_name_len;
+ char nick[1];
+ char message[1];
+ char room_name[1];
} CS_chat_MESSAGE;
Modified: GNUnet/src/applications/chat/clientapi.c
===================================================================
--- GNUnet/src/applications/chat/clientapi.c 2008-02-07 07:58:25 UTC (rev
6191)
+++ GNUnet/src/applications/chat/clientapi.c 2008-02-08 02:18:55 UTC (rev
6192)
@@ -44,6 +44,8 @@
struct GNUNET_GC_Configuration *cfg;
char *nickname;
+
+ char *room_name;
const GNUNET_RSA_PublicKey *my_public_key;
@@ -90,24 +92,25 @@
GNUNET_CHAT_join_room (struct GNUNET_GE_Context *ectx,
struct GNUNET_GC_Configuration *cfg,
const char *nickname,
+ const char *room_name,
const GNUNET_RSA_PublicKey * me,
const struct GNUNET_RSA_PrivateKey *key,
const char *memberInfo,
GNUNET_CHAT_MessageCallback callback, void *cls)
{
- CS_chat_MESSAGE *chat_msg;
+ CS_chat_MESSAGE *chat_msg;
GNUNET_MessageHeader csHdr;
struct GNUNET_CHAT_Room *chat_room;
struct GNUNET_ClientServerConnection *sock;
-
+
int ret;
ret = GNUNET_OK;
csHdr.size = htons (sizeof (GNUNET_MessageHeader));
csHdr.type = htons (GNUNET_CS_PROTO_CHAT_MSG);
-
+
sock = GNUNET_client_connection_create(ectx,cfg);
-
+
if (sock == NULL)
{
fprintf (stderr, _("Error establishing connection with gnunetd.\n"));
@@ -119,20 +122,18 @@
fprintf (stderr, _("Error writing to socket.\n"));
ret = GNUNET_SYSERR;
}
-
+
chat_msg = GNUNET_malloc (sizeof (CS_chat_MESSAGE));
-<<<<<<< .mine
GNUNET_free(chat_msg);
-=======
-
->>>>>>> .r6183
// connect
// allocate & init room struct
chat_room = GNUNET_malloc(sizeof(struct GNUNET_CHAT_Room));
chat_room->nickname = GNUNET_malloc(sizeof(nickname));
strncpy(chat_room->nickname,nickname,sizeof(nickname));
+ chat_room->room_name = GNUNET_malloc(sizeof(room_name));
+ strncpy(chat_room->room_name,room_name,sizeof(room_name));
chat_room->my_public_key = me;
chat_room->my_private_key = key;
chat_room->callback = callback;
@@ -186,19 +187,30 @@
GNUNET_MessageHeader cs_msg_hdr;
CS_chat_MESSAGE *msg_to_send;
- msg_to_send = GNUNET_malloc(sizeof(CS_chat_MESSAGE));
- cs_msg_hdr.size = htons (sizeof (GNUNET_MessageHeader));
+
+ cs_msg_hdr.size = htons (sizeof (GNUNET_MessageHeader) +
sizeof(CS_chat_MESSAGE) + sizeof(room->nickname) + sizeof(message) +
sizeof(room->room_name));
cs_msg_hdr.type = htons (GNUNET_CS_PROTO_CHAT_MSG);
+
+ msg_to_send = GNUNET_malloc(ntohl(cs_msg_hdr.size));
+
+ msg_to_send->nick_len = htonl(sizeof(room->nickname));
+ msg_to_send->msg_len = htonl(sizeof(message));
+ msg_to_send->room_name_len = htonl(sizeof(room->room_name));
+
+ memcpy(&msg_to_send->nick[0],room->nickname,sizeof(room->nickname));
+ memcpy(&msg_to_send->nick[sizeof(room->nickname)],message,sizeof(message));
+ memcpy(&msg_to_send->nick[sizeof(room->nickname) +
sizeof(message)],room->room_name,sizeof(room->room_name));
+ /*msg_to_send->message = message;
+ msg_to_send->nick = room->nickname;*/
msg_to_send->header = cs_msg_hdr;
- if (GNUNET_SYSERR == GNUNET_client_connection_write (room->sock,
(GNUNET_MessageHeader *)&msg_to_send))
+ if (GNUNET_SYSERR == GNUNET_client_connection_write
(room->sock,&msg_to_send->header))
{
fprintf (stderr, _("Error writing to socket.\n"));
ret = GNUNET_SYSERR;
}
-
-
+
return ret;
}
Modified: GNUnet/src/applications/chat/gnunet-chat.c
===================================================================
--- GNUnet/src/applications/chat/gnunet-chat.c 2008-02-07 07:58:25 UTC (rev
6191)
+++ GNUnet/src/applications/chat/gnunet-chat.c 2008-02-08 02:18:55 UTC (rev
6192)
@@ -38,7 +38,7 @@
static char *nickname;
-static char *roomname = "gnunet";
+static char *room_name = "gnunet";
static char *quit = "quit";
@@ -54,7 +54,7 @@
1, &GNUNET_getopt_configure_set_string, &nickname},
{'r', "room", "NAME",
gettext_noop ("set the chat room to join (requred)"),
- 1, &GNUNET_getopt_configure_set_string, &roomname},
+ 1, &GNUNET_getopt_configure_set_string, &room_name},
GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
GNUNET_COMMAND_LINE_OPTION_VERBOSE,
GNUNET_COMMAND_LINE_OPTION_END,
@@ -123,17 +123,16 @@
int
main (int argc, char **argv)
{
- struct GNUNET_ClientServerConnection *sock;
struct GNUNET_CHAT_Room *room;
GNUNET_RSA_PublicKey *my_pub;
struct GNUNET_RSA_PrivateKey *my_priv;
char *message;
- /*char *quit;
- quit = GNUNET_malloc(sizeof("quit")+1);
- quit = strdup("quit");*/
+ my_pub = NULL;
+ my_priv = GNUNET_RSA_create_key();
+ GNUNET_RSA_get_public_key(my_priv,my_pub);
+
message = GNUNET_malloc(MAX_MESSAGE_LENGTH+1);
-
int ret = GNUNET_OK;
if (GNUNET_SYSERR == GNUNET_init (argc,
@@ -147,10 +146,10 @@
fprintf (stderr, _("You must specify a nickname\n"));
ret = GNUNET_SYSERR;
}
- /* FIXME: load/generate private key! */
+
room = GNUNET_CHAT_join_room (ectx,
cfg,
- nickname,
+ nickname,room_name,
my_pub, my_priv, "", &receive_callback, NULL);
if (room == NULL)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6192 - GNUnet/src/applications/chat,
gnunet <=