[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6962 - in GNUnet/src: applications/chat/lib applications/c
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6962 - in GNUnet/src: applications/chat/lib applications/chat/module applications/dht include |
Date: |
Sat, 31 May 2008 22:20:44 -0600 (MDT) |
Author: grothoff
Date: 2008-05-31 22:20:43 -0600 (Sat, 31 May 2008)
New Revision: 6962
Modified:
GNUnet/src/applications/chat/lib/check.conf
GNUnet/src/applications/chat/lib/loopback_test.c
GNUnet/src/applications/chat/lib/messaging.c
GNUnet/src/applications/chat/module/chat.c
GNUnet/src/applications/dht/Makefile.am
GNUnet/src/include/chat.h
Log:
fixes
Modified: GNUnet/src/applications/chat/lib/check.conf
===================================================================
--- GNUnet/src/applications/chat/lib/check.conf 2008-06-01 03:34:02 UTC (rev
6961)
+++ GNUnet/src/applications/chat/lib/check.conf 2008-06-01 04:20:43 UTC (rev
6962)
@@ -1,4 +1,7 @@
# General settings
+[PATHS]
+GNUNET_HOME = "/tmp/gnunet-chat-test/"
+
[GNUNET]
GNUNET_HOME = "/tmp/gnunet-chat-test/"
LOGLEVEL = "WARNING"
Modified: GNUnet/src/applications/chat/lib/loopback_test.c
===================================================================
--- GNUnet/src/applications/chat/lib/loopback_test.c 2008-06-01 03:34:02 UTC
(rev 6961)
+++ GNUnet/src/applications/chat/lib/loopback_test.c 2008-06-01 04:20:43 UTC
(rev 6962)
@@ -51,6 +51,8 @@
char * msg;
+ struct GNUNET_Semaphore * recv;
+
GNUNET_CHAT_MSG_OPTIONS opt;
};
@@ -64,15 +66,20 @@
GNUNET_CHAT_MSG_OPTIONS options)
{
struct Wanted * want = cls;
+
if (! ( (0 == strcmp(message, want->msg)) &&
( ( (sender == NULL) && (want->sender == NULL) ) ||
( (sender != NULL) &&
(want->sender != NULL) &&
(0 == memcmp(sender, want->sender, sizeof(GNUNET_HashCode))) ) )
&&
- (0 == GNUNET_ECRS_meta_data_test_equal(member_info,
- want->meta)) &&
+ (GNUNET_ECRS_meta_data_test_equal(member_info,
+ want->meta)) &&
(options == want->opt) ) )
- error++;
+ {
+ abort();
+ error++;
+ }
+ GNUNET_semaphore_up(want->recv);
return GNUNET_OK;
}
@@ -89,13 +96,34 @@
sizeof(GNUNET_RSA_PublicKey),
&sender);
if (! ( (0 == memcmp(&sender, want->sender, sizeof(GNUNET_HashCode))) &&
- (0 == GNUNET_ECRS_meta_data_test_equal(member_info,
+ (GNUNET_ECRS_meta_data_test_equal(member_info,
want->meta)) &&
(options == want->opt) ) )
- error++;
+ {
+ abort();
+ error++;
+ }
+ GNUNET_semaphore_up(want->recv);
return GNUNET_OK;
}
+static void
+check_down(struct Wanted * want)
+{
+ int tries;
+ tries = 10;
+ while (tries > 0)
+ {
+ if (GNUNET_OK ==
+ GNUNET_semaphore_down(want->recv,
+ GNUNET_YES))
+ break;
+ tries--;
+ }
+ if (tries == 0)
+ error++;
+}
+
/**
* Testcase to test chat.
* @return 0: ok, -1: error
@@ -144,11 +172,20 @@
GNUNET_ECRS_meta_data_insert(meta2,
EXTRACTOR_TITLE,
"Bob");
+
+ /* alice joining */
+ fprintf(stderr,
+ "Alice joining\n");
+ alice_wanted.recv = GNUNET_semaphore_create(0);
+ alice_wanted.meta = meta1;
+ alice_wanted.sender = &alice;
+ alice_wanted.msg = NULL;
+ alice_wanted.opt = -1;
r1 =
GNUNET_CHAT_join_room (NULL, cfg, "alice",
meta1, "test", -1,
&receive_callback, &alice_wanted,
- &member_list_callback, &bob_wanted,
+ &member_list_callback, &alice_wanted,
NULL, NULL,
&alice);
if (r1 == NULL)
@@ -156,11 +193,26 @@
ret = 1;
goto CLEANUP;
}
+ check_down(&alice_wanted);
+
+ /* bob joining */
+ fprintf(stderr,
+ "Bob joining\n");
+ alice_wanted.meta = meta2;
+ alice_wanted.sender = &bob;
+ alice_wanted.msg = NULL;
+ alice_wanted.opt = -1;
+
+ bob_wanted.recv = GNUNET_semaphore_create(0);
+ bob_wanted.meta = meta2;
+ bob_wanted.sender = &bob;
+ bob_wanted.msg = NULL;
+ bob_wanted.opt = -1;
r2 =
GNUNET_CHAT_join_room (NULL, cfg, "bob",
meta2, "test", -1,
&receive_callback, &bob_wanted,
- &member_list_callback, &alice_wanted,
+ &member_list_callback, &bob_wanted,
NULL, NULL,
&bob);
if (r2 == NULL)
@@ -168,14 +220,33 @@
ret = 1;
goto CLEANUP;
}
+ check_down(&alice_wanted);
+ check_down(&bob_wanted);
+ bob_wanted.meta = meta1;
+ bob_wanted.sender = &alice;
+ bob_wanted.msg = NULL;
+ bob_wanted.opt = -1;
+ check_down(&bob_wanted);
+ /* end of Bob joining */
+#if 0
+ /* alice to bob */
GNUNET_CHAT_send_message (r1, "test message 1",
GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq);
+ /* bob to alice */
GNUNET_CHAT_send_message (r2, "test message 2",
GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq);
+#endif
+ /* alice leaving */
+ GNUNET_CHAT_leave_room (r1);
+ r1 = NULL;
-CLEANUP:
+ /* bob leaving */
+ GNUNET_CHAT_leave_room (r2);
+ r2 = NULL;
+
+ CLEANUP:
if (r1 != NULL)
GNUNET_CHAT_leave_room (r1);
if (r2 != NULL)
Modified: GNUnet/src/applications/chat/lib/messaging.c
===================================================================
--- GNUnet/src/applications/chat/lib/messaging.c 2008-06-01 03:34:02 UTC
(rev 6961)
+++ GNUnet/src/applications/chat/lib/messaging.c 2008-06-01 04:20:43 UTC
(rev 6962)
@@ -106,16 +106,21 @@
GNUNET_ECRS_meta_data_get_serialized_size (chat_room->member_info,
GNUNET_YES);
room_len = strlen (chat_room->room_name);
- size_of_join = sizeof (CS_chat_MESSAGE_JoinRequest) + meta_len + room_len;
+ size_of_join = sizeof (CS_chat_MESSAGE_JoinRequest) + meta_len
+ + room_len + ntohs(chat_room->my_private_key->len) -
sizeof(GNUNET_RSA_PrivateKeyEncoded);
if (size_of_join >= GNUNET_MAX_BUFFER_SIZE - 8)
return GNUNET_SYSERR;
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_REQUEST);
join_msg->msg_options = htonl (chat_room->msg_options);
- join_msg->private_key = *chat_room->my_private_key;
join_msg->room_name_len = htons (room_len);
+ join_msg->reserved = htons (0);
+ memcpy(&join_msg->private_key,
+ chat_room->my_private_key,
+ ntohs(chat_room->my_private_key->len));
room = (char *) &join_msg[1];
+ room += ntohs(chat_room->my_private_key->len) -
sizeof(GNUNET_RSA_PrivateKeyEncoded);
memcpy (room, chat_room->room_name, room_len);
if (GNUNET_SYSERR ==
GNUNET_ECRS_meta_data_serialize (chat_room->ectx,
Modified: GNUnet/src/applications/chat/module/chat.c
===================================================================
--- GNUnet/src/applications/chat/module/chat.c 2008-06-01 03:34:02 UTC (rev
6961)
+++ GNUnet/src/applications/chat/module/chat.c 2008-06-01 04:20:43 UTC (rev
6962)
@@ -36,7 +36,7 @@
/**
* Linked list of our current clients.
*/
-struct GNUNET_CS_chat_client
+struct GNUNET_CS_chat_client
{
struct GNUNET_CS_chat_client *next;
@@ -46,6 +46,8 @@
char *room;
+ char *member_info;
+
/**
* Hash of the public key (for convenience).
*/
@@ -53,6 +55,11 @@
unsigned int msg_options;
+ /**
+ * Length of serialized metadata in member_info.
+ */
+ unsigned int meta_len;
+
};
static struct GNUNET_CS_chat_client *client_list_head;
@@ -164,6 +171,7 @@
struct GNUNET_CS_chat_client *entry;
GNUNET_RSA_PublicKey pkey;
CS_chat_MESSAGE_JoinNotification *nmsg;
+ CS_chat_MESSAGE_JoinNotification *emsg;
if (ntohs (message->size) < sizeof (CS_chat_MESSAGE_JoinRequest))
{
@@ -173,15 +181,17 @@
cmsg = (const CS_chat_MESSAGE_JoinRequest *) message;
header_size = ntohs (cmsg->header.size);
room_name_len = ntohs (cmsg->room_name_len);
- if (header_size - sizeof (CS_chat_MESSAGE_JoinRequest) <= room_name_len)
+ if (header_size - sizeof (CS_chat_MESSAGE_JoinRequest) +
sizeof(GNUNET_RSA_PrivateKeyEncoded)
+ <= room_name_len + ntohs(cmsg->private_key.len))
{
GNUNET_GE_BREAK (NULL, 0);
return GNUNET_SYSERR;
}
meta_len =
- header_size - sizeof (CS_chat_MESSAGE_JoinRequest) - room_name_len;
-
+ header_size - sizeof (CS_chat_MESSAGE_JoinRequest) - room_name_len
+ - ntohs(cmsg->private_key.len) + sizeof(GNUNET_RSA_PrivateKeyEncoded);
roomptr = (const char *) &cmsg[1];
+ roomptr += ntohs(cmsg->private_key.len) -
sizeof(GNUNET_RSA_PrivateKeyEncoded);
room_name = GNUNET_malloc (room_name_len + 1);
memcpy (room_name, roomptr, room_name_len);
room_name[room_name_len] = '\0';
@@ -191,9 +201,20 @@
entry->client = client;
entry->room = room_name;
entry->private_key = GNUNET_RSA_decode_key (&cmsg->private_key);
+ entry->meta_len = meta_len;
+ if (meta_len > 0)
+ {
+ entry->member_info = GNUNET_malloc(meta_len);
+ memcpy(entry->member_info,
+ &roomptr[room_name_len],
+ meta_len);
+ }
+ else
+ entry->member_info = NULL;
if (entry->private_key == NULL)
{
GNUNET_GE_BREAK (NULL, 0);
+ GNUNET_free_non_null (entry->member_info);
GNUNET_free (room_name);
GNUNET_free (entry);
return GNUNET_SYSERR;
@@ -201,8 +222,6 @@
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 =
@@ -216,7 +235,22 @@
while (entry != NULL)
{
if (0 == strcmp (room_name, entry->room))
- coreAPI->cs_send_message (entry->client, &nmsg->header, GNUNET_YES);
+ {
+ coreAPI->cs_send_message (entry->client, &nmsg->header, GNUNET_YES);
+ emsg = GNUNET_malloc(sizeof(CS_chat_MESSAGE_JoinNotification) +
+ entry->meta_len);
+ emsg->header.type = htons (GNUNET_CS_PROTO_CHAT_JOIN_NOTIFICATION);
+ emsg->header.size =
+ htons (sizeof (CS_chat_MESSAGE_JoinNotification) + entry->meta_len);
+ emsg->msg_options = entry->msg_options;
+ GNUNET_RSA_get_public_key (entry->private_key,
+ &emsg->public_key);
+ memcpy(&emsg[1],
+ entry->member_info,
+ entry->meta_len);
+ coreAPI->cs_send_message (client, &emsg->header, GNUNET_YES);
+ GNUNET_free(emsg);
+ }
entry = entry->next;
}
GNUNET_mutex_unlock (chatMutex);
@@ -263,6 +297,7 @@
GNUNET_mutex_unlock (chatMutex);
GNUNET_free (pos->room);
GNUNET_RSA_free_key (pos->private_key);
+ GNUNET_free_non_null (pos->member_info);
GNUNET_free (pos);
}
Modified: GNUnet/src/applications/dht/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/Makefile.am 2008-06-01 03:34:02 UTC (rev
6961)
+++ GNUnet/src/applications/dht/Makefile.am 2008-06-01 04:20:43 UTC (rev
6962)
@@ -1 +1 @@
-SUBDIRS = module tools
+SUBDIRS = module
Modified: GNUnet/src/include/chat.h
===================================================================
--- GNUnet/src/include/chat.h 2008-06-01 03:34:02 UTC (rev 6961)
+++ GNUnet/src/include/chat.h 2008-06-01 04:20:43 UTC (rev 6962)
@@ -137,14 +137,19 @@
unsigned int msg_options;
/**
- * Private key of the joining member.
+ * Length of the room name.
*/
- GNUNET_RSA_PrivateKeyEncoded private_key;
+ unsigned short room_name_len;
/**
- * Length of the room name.
+ * Reserved (should be zero).
+ */
+ unsigned short reserved;
+
+ /**
+ * Private key of the joining member.
*/
- unsigned short room_name_len;
+ GNUNET_RSA_PrivateKeyEncoded private_key;
} CS_chat_MESSAGE_JoinRequest;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6962 - in GNUnet/src: applications/chat/lib applications/chat/module applications/dht include,
gnunet <=