[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6164 - GNUnet/src/applications/chat
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6164 - GNUnet/src/applications/chat |
Date: |
Wed, 6 Feb 2008 00:22:40 -0700 (MST) |
Author: nevans
Date: 2008-02-06 00:22:39 -0700 (Wed, 06 Feb 2008)
New Revision: 6164
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:
a bit closer
Modified: GNUnet/src/applications/chat/Makefile.am
===================================================================
--- GNUnet/src/applications/chat/Makefile.am 2008-02-06 07:22:13 UTC (rev
6163)
+++ GNUnet/src/applications/chat/Makefile.am 2008-02-06 07:22:39 UTC (rev
6164)
@@ -1,32 +1,33 @@
INCLUDES = -I$(top_srcdir)/src/include
+LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la
+
plugindir = $(libdir)/GNUnet
-bin_PROGRAMS = \
- gnunet-chat
+plugin_LTLIBRARIES = \
+ libgnunetmodule_chat.la
lib_LTLIBRARIES = \
- libgnunetstats_api.la
+ libgnunetchat_api.la
-plugin_LTLIBRARIES = \
- libgnunetmodule_chat.la
+bin_PROGRAMS = \
+ gnunet-chat
gnunet_chat_SOURCES = \
- gnunet-chat.c
+ gnunet-chat.c
gnunet_chat_LDADD = \
- $(top_builddir)/src/applications/chat/libgnunetchat.so \
- $(top_builddir)/src/util/libgnunetutil.la
+ $(top_builddir)/src/applications/chat/libgnunetchat_api.la
libgnunetchat_api_la_SOURCES = \
clientapi.c
libgnunetchat_api_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la
+ $(top_builddir)/src/util/libgnunetutil.la
libgnunetmodule_chat_la_SOURCES = \
chat.c \
chat.h
+libgnunetmodule_chat_la_LIBADD = \
+ $(top_builddir)/src/util/libgnunetutil.la
libgnunetmodule_chat_la_LDFLAGS = \
- -export-dynamic -avoid-version -module
-libgnunetmodule_chat_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la
+ -export-dynamic -avoid-version -module
\ No newline at end of file
Modified: GNUnet/src/applications/chat/chat.c
===================================================================
--- GNUnet/src/applications/chat/chat.c 2008-02-06 07:22:13 UTC (rev 6163)
+++ GNUnet/src/applications/chat/chat.c 2008-02-06 07:22:39 UTC (rev 6164)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2005 Christian Grothoff (and other contributing authors)
+ (C) 2001, 2002, 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
@@ -28,18 +28,22 @@
#include "platform.h"
#include "gnunet_protocols.h"
+#include "gnunet_util.h"
+#include "gnunet_core.h"
#include "chat.h"
-static GNUNET_CoreAPIForPlugins *coreAPI = NULL;
+static GNUNET_CoreAPIForPlugins *coreAPI;
#define MAX_LAST_MESSAGES 12
#define MAX_CLIENTS 4
-static GNUNET_ClientHandle clients[MAX_CLIENTS];
+static struct GNUNET_ClientHandle **clients;
static int clientCount;
-static GNUNET_HashCode lastMsgs[MAX_LAST_MESSAGES];
+static struct GNUNET_HashCode **lastMsgs;
static int ringIndex;
-static Mutex chatMutex;
+static struct GNUNET_Mutex *chatMutex;
+static struct GNUNET_GE_Context *ectx;
+static struct GNUNET_GC_Configuration *cfg;
static void
markSeen (GNUNET_HashCode * hc)
@@ -97,7 +101,7 @@
/* check if we have seen this message already */
GNUNET_hash (pmsg, sizeof (P2P_chat_MESSAGE), &hc);
j = -1;
- GNUNET_mutex_lock (&chatMutex);
+ GNUNET_mutex_lock (chatMutex);
for (i = 0; i < MAX_LAST_MESSAGES; i++)
if (0 == memcmp (&hc, &lastMsgs[i], sizeof (GNUNET_HashCode)))
j = i;
@@ -109,7 +113,7 @@
broadcastToConnected (message, 5, 1);
cmsg->header.type = htons (GNUNET_CS_PROTO_CHAT_MSG);
for (j = 0; j < clientCount; j++)
- coreAPI->cs_send_to_client (clients[j], &cmsg->header);
+ 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';
/*
@@ -119,13 +123,13 @@
&pmsg->message[0]);
*/
}
- GNUNET_mutex_unlock (&chatMutex);
+ GNUNET_mutex_unlock (chatMutex);
return GNUNET_OK;
}
static int
-csHandleChatRequest (GNUNET_ClientHandle client,
- const CS_MESSAGE_HEADER * message)
+csHandleChatRequest (struct GNUNET_ClientHandle *client,
+ const GNUNET_MessageHeader * message)
{
int i;
int j;
@@ -143,7 +147,7 @@
pmsg = (P2P_chat_MESSAGE *) message;
cmsg = (CS_chat_MESSAGE *) message;
GNUNET_hash (pmsg, sizeof (P2P_chat_MESSAGE), &hc);
- GNUNET_mutex_lock (&chatMutex);
+ GNUNET_mutex_lock (chatMutex);
markSeen (&hc);
/* forward to all other TCP chat clients */
@@ -152,7 +156,7 @@
if (clients[i] == client)
j = i;
else
- coreAPI->cs_send_to_client (clients[i], message);
+ coreAPI->cs_send_to_client (clients[i], message,GNUNET_YES);
if (j == -1)
{
if (clientCount == MAX_CLIENTS)
@@ -171,15 +175,15 @@
/* forward to all other nodes in the network */
pmsg->header.type = htons (GNUNET_P2P_PROTO_CHAT_MSG);
broadcastToConnected (&pmsg->header, 5, 1);
- GNUNET_mutex_unlock (&chatMutex);
+ GNUNET_mutex_unlock (chatMutex);
return GNUNET_OK;
}
static void
-chatClientExitHandler (GNUNET_ClientHandle client)
+chatClientExitHandler (struct GNUNET_ClientHandle *client)
{
int i;
- GNUNET_mutex_lock (&chatMutex);
+ GNUNET_mutex_lock (chatMutex);
for (i = 0; i < clientCount; i++)
if (clients[i] == client)
{
@@ -189,14 +193,10 @@
clients[i] = clients[--clientCount];
break;
}
- GNUNET_mutex_unlock (&chatMutex);
+ GNUNET_mutex_unlock (chatMutex);
}
-/**
- * Initialize the AFS module. This method name must match
- * the library name (libgnunet_XXX => initialize_XXX).
- * @return GNUNET_SYSERR on errors
- */
+
int
initialize_module_chat (GNUNET_CoreAPIForPlugins * capi)
{
@@ -204,7 +204,7 @@
GNUNET_GE_ASSERT (ectx,
sizeof (P2P_chat_MESSAGE) == sizeof (CS_chat_MESSAGE));
- GNUNET_mutex_create (&chatMutex);
+ chatMutex = GNUNET_mutex_create (GNUNET_NO);
clientCount = 0;
coreAPI = capi;
GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
@@ -215,7 +215,7 @@
capi->registerHandler (GNUNET_P2P_PROTO_CHAT_MSG, &handleChatMSG))
ok = GNUNET_SYSERR;
if (GNUNET_SYSERR ==
- capi->cs_register_exit_handler (&chatClientExitHandler))
+ capi->cs_exit_handler_register (&chatClientExitHandler))
ok = GNUNET_SYSERR;
if (GNUNET_SYSERR == capi->registerClientHandler (GNUNET_CS_PROTO_CHAT_MSG,
&csHandleChatRequest))
@@ -238,8 +238,8 @@
coreAPI->cs_exit_handler_unregister (&chatClientExitHandler);
coreAPI->unregisterClientHandler (GNUNET_CS_PROTO_CHAT_MSG,
&csHandleChatRequest);
- GNUNET_mutex_destroy (&chatMutex);
+ GNUNET_mutex_destroy (chatMutex);
coreAPI = NULL;
}
-/* end of afs.c */
+/* end of chat.c */
Modified: GNUnet/src/applications/chat/chat.h
===================================================================
--- GNUnet/src/applications/chat/chat.h 2008-02-06 07:22:13 UTC (rev 6163)
+++ GNUnet/src/applications/chat/chat.h 2008-02-06 07:22:39 UTC (rev 6164)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002 Christian Grothoff (and other contributing authors)
+ (C) 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
@@ -20,6 +20,7 @@
/**
* @author Christian Grothoff
+ * @author Nathan Evans
* @file applications/chat/chat.h
**/
#ifndef CHAT_CHAT_H
@@ -39,7 +40,7 @@
typedef struct
{
- CS_MESSAGE_HEADER header;
+ GNUNET_MessageHeader header;
char nick[CHAT_NICK_LENGTH];
char message[CHAT_MSG_LENGTH];
} CS_chat_MESSAGE;
@@ -47,3 +48,5 @@
#endif
+
+/* end of chat.h */
Modified: GNUnet/src/applications/chat/clientapi.c
===================================================================
--- GNUnet/src/applications/chat/clientapi.c 2008-02-06 07:22:13 UTC (rev
6163)
+++ GNUnet/src/applications/chat/clientapi.c 2008-02-06 07:22:39 UTC (rev
6164)
@@ -95,14 +95,56 @@
const char *memberInfo,
GNUNET_CHAT_MessageCallback callback, void *cls)
{
+ 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"));
+ ret = GNUNET_SYSERR;
+ }
+
+ if (GNUNET_SYSERR == GNUNET_client_connection_write (sock, &csHdr))
+ {
+ fprintf (stderr, _("Error writing to socket.\n"));
+ ret = GNUNET_SYSERR;
+ }
+
+ chat_msg = GNUNET_malloc (sizeof (CS_chat_MESSAGE));
+
// 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->my_public_key = me;
+ chat_room->my_private_key = key;
+ chat_room->callback = callback;
+ chat_room->callback_cls = cls;
+ chat_room->ectx = ectx;
+ chat_room->cfg = cfg;
+ chat_room->memberInfo = GNUNET_malloc(sizeof(memberInfo));
+ strncpy(chat_room->memberInfo,memberInfo,sizeof(memberInfo));
+ chat_room->sock = sock;
// create pthread
// return room struct
- return NULL;
+ if (ret != GNUNET_OK)
+ return NULL;
+
+ return chat_room;
}
/**
Modified: GNUnet/src/applications/chat/gnunet-chat.c
===================================================================
--- GNUnet/src/applications/chat/gnunet-chat.c 2008-02-06 07:22:13 UTC (rev
6163)
+++ GNUnet/src/applications/chat/gnunet-chat.c 2008-02-06 07:22:39 UTC (rev
6164)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2007 Christian Grothoff (and other contributing authors)
+ (C) 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
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_protocols.h"
+#include "gnunet_directories.h"
#include "gnunet_chat_lib.h"
static struct GNUNET_GC_Configuration *cfg;
@@ -42,7 +43,7 @@
* All gnunet-chat command line options
*/
static struct GNUNET_CommandLineOption gnunetchatOptions[] = {
- COMMAND_LINE_OPTION_HELP (gettext_noop ("Join a chat on GNUnet.")), /* -h
*/
+ GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Join a chat on GNUnet.")),
/* -h */
GNUNET_COMMAND_LINE_OPTION_HOSTNAME, /* -H */
GNUNET_COMMAND_LINE_OPTION_LOGGING, /* -L */
{'n', "nick", "NAME",
@@ -51,7 +52,7 @@
{'r', "room", "NAME",
gettext_noop ("set the chat room to join (requred)"),
1, &GNUNET_getopt_configure_set_string, &roomname},
- COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
+ GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
GNUNET_COMMAND_LINE_OPTION_VERBOSE,
GNUNET_COMMAND_LINE_OPTION_END,
};
@@ -119,21 +120,23 @@
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[1024];
+ int ret = GNUNET_OK;
if (GNUNET_SYSERR == GNUNET_init (argc,
argv,
"gnunet-chat [OPTIONS]",
&cfgFilename, gnunetchatOptions, &ectx,
&cfg))
- return 1; /* parse error, --help, etc. */
+ ret = GNUNET_SYSERR; /* parse error, --help, etc. */
if (nickname == NULL)
{
fprintf (stderr, _("You must specify a nickname\n"));
- return 1;
+ ret = GNUNET_SYSERR;
}
/* FIXME: load/generate private key! */
room = GNUNET_CHAT_join_room (ectx,
@@ -143,11 +146,11 @@
if (room == NULL)
{
fprintf (stderr, _("Failed to join the room\n"));
- return 1;
+ ret = GNUNET_SYSERR;
}
/* read messages from command line and send */
- while (1)
+ while (ret == GNUNET_OK)
{
memset (message, 0, 1024);
if (NULL == fgets (message, 1023, stdin))
@@ -164,7 +167,7 @@
}
GNUNET_CHAT_leave_room (room);
GNUNET_fini (ectx, cfg);
- return 0;
+ return GNUNET_OK;
}
/* end of gnunet-chat.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6164 - GNUnet/src/applications/chat,
gnunet <=