[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6963 - in GNUnet/src/applications/chat: lib module
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6963 - in GNUnet/src/applications/chat: lib module |
Date: |
Sun, 1 Jun 2008 00:36:07 -0600 (MDT) |
Author: grothoff
Date: 2008-06-01 00:36:06 -0600 (Sun, 01 Jun 2008)
New Revision: 6963
Modified:
GNUnet/src/applications/chat/lib/loopback_test.c
GNUnet/src/applications/chat/lib/messaging.c
GNUnet/src/applications/chat/module/chat.c
Log:
fixing chat
Modified: GNUnet/src/applications/chat/lib/loopback_test.c
===================================================================
--- GNUnet/src/applications/chat/lib/loopback_test.c 2008-06-01 04:20:43 UTC
(rev 6962)
+++ GNUnet/src/applications/chat/lib/loopback_test.c 2008-06-01 06:36:06 UTC
(rev 6963)
@@ -50,9 +50,13 @@
GNUNET_HashCode * sender;
char * msg;
+
+ const char * me;
struct GNUNET_Semaphore * recv;
+ struct GNUNET_Semaphore * pre;
+
GNUNET_CHAT_MSG_OPTIONS opt;
};
@@ -67,6 +71,12 @@
{
struct Wanted * want = cls;
+ fprintf(stderr, "%s - told that %s says %s\n",
+ want->me,
+ member_info == NULL ? NULL
+ : GNUNET_ECRS_meta_data_get_by_type(member_info, EXTRACTOR_TITLE),
+ message);
+ GNUNET_semaphore_down(want->pre, GNUNET_YES);
if (! ( (0 == strcmp(message, want->msg)) &&
( ( (sender == NULL) && (want->sender == NULL) ) ||
( (sender != NULL) &&
@@ -92,12 +102,21 @@
struct Wanted * want = cls;
GNUNET_HashCode sender;
+ fprintf(stderr, "%s - told that %s joins\n",
+ want->me,
+ member_info == NULL ? NULL
+ : GNUNET_ECRS_meta_data_get_by_type(member_info, EXTRACTOR_TITLE));
+ GNUNET_semaphore_down(want->pre, GNUNET_YES);
GNUNET_hash(member_id,
sizeof(GNUNET_RSA_PublicKey),
&sender);
if (! ( (0 == memcmp(&sender, want->sender, sizeof(GNUNET_HashCode))) &&
- (GNUNET_ECRS_meta_data_test_equal(member_info,
- want->meta)) &&
+ ( ( (member_info == NULL) &&
+ (want->meta == NULL) ) ||
+ ( (member_info != NULL) &&
+ (want->meta != NULL) &&
+ (GNUNET_ECRS_meta_data_test_equal(member_info,
+ want->meta)) ) ) &&
(options == want->opt) ) )
{
abort();
@@ -114,10 +133,11 @@
tries = 10;
while (tries > 0)
{
- if (GNUNET_OK ==
+ if (GNUNET_SYSERR !=
GNUNET_semaphore_down(want->recv,
GNUNET_YES))
break;
+ GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS);
tries--;
}
if (tries == 0)
@@ -144,6 +164,10 @@
struct Wanted alice_wanted;
struct Wanted bob_wanted;
+ memset(&alice_wanted, 0, sizeof(struct Wanted));
+ memset(&bob_wanted, 0, sizeof(struct Wanted));
+ alice_wanted.me = "Alice";
+ bob_wanted.me = "Bob";
ret = 0;
cfg = GNUNET_GC_create ();
if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
@@ -177,6 +201,7 @@
fprintf(stderr,
"Alice joining\n");
alice_wanted.recv = GNUNET_semaphore_create(0);
+ alice_wanted.pre = GNUNET_semaphore_create(1);
alice_wanted.meta = meta1;
alice_wanted.sender = &alice;
alice_wanted.msg = NULL;
@@ -202,8 +227,10 @@
alice_wanted.sender = &bob;
alice_wanted.msg = NULL;
alice_wanted.opt = -1;
+ GNUNET_semaphore_up(alice_wanted.pre);
bob_wanted.recv = GNUNET_semaphore_create(0);
+ bob_wanted.pre = GNUNET_semaphore_create(1);
bob_wanted.meta = meta2;
bob_wanted.sender = &bob;
bob_wanted.msg = NULL;
@@ -211,7 +238,7 @@
r2 =
GNUNET_CHAT_join_room (NULL, cfg, "bob",
meta2, "test", -1,
- &receive_callback, &bob_wanted,
+ &receive_callback, &bob_wanted,
&member_list_callback, &bob_wanted,
NULL, NULL,
&bob);
@@ -226,21 +253,43 @@
bob_wanted.sender = &alice;
bob_wanted.msg = NULL;
bob_wanted.opt = -1;
+ GNUNET_semaphore_up(bob_wanted.pre);
check_down(&bob_wanted);
/* end of Bob joining */
-#if 0
/* alice to bob */
- GNUNET_CHAT_send_message (r1, "test message 1",
+ fprintf(stderr,
+ "Alice says 'Hi!'\n");
+ GNUNET_CHAT_send_message (r1, "Hi!",
GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq);
+ alice_wanted.meta = meta1;
+ alice_wanted.sender = &alice;
+ alice_wanted.msg = "Hi!";
+ alice_wanted.opt = 0;
+ GNUNET_semaphore_up(alice_wanted.pre);
+ bob_wanted.meta = meta1;
+ bob_wanted.sender = &alice;
+ bob_wanted.msg = "Hi!";
+ bob_wanted.opt = 0;
+ GNUNET_semaphore_up(bob_wanted.pre);
+ check_down(&alice_wanted);
+ check_down(&bob_wanted);
+
+#if 0
/* bob to alice */
- GNUNET_CHAT_send_message (r2, "test message 2",
+ GNUNET_CHAT_send_message (r2, "Rehi!",
GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq);
#endif
/* alice leaving */
GNUNET_CHAT_leave_room (r1);
r1 = NULL;
+ bob_wanted.meta = NULL;
+ bob_wanted.sender = &alice;
+ bob_wanted.msg = NULL;
+ bob_wanted.opt = 0;
+ GNUNET_semaphore_up(bob_wanted.pre);
+ check_down(&bob_wanted);
/* bob leaving */
GNUNET_CHAT_leave_room (r2);
@@ -251,11 +300,21 @@
GNUNET_CHAT_leave_room (r1);
if (r2 != NULL)
GNUNET_CHAT_leave_room (r2);
+ if (bob_wanted.pre != NULL)
+ GNUNET_semaphore_destroy(bob_wanted.pre);
+ if (bob_wanted.recv != NULL)
+ GNUNET_semaphore_destroy(bob_wanted.recv);
+ if (alice_wanted.pre != NULL)
+ GNUNET_semaphore_destroy(alice_wanted.pre);
+ if (alice_wanted.recv != NULL)
+ GNUNET_semaphore_destroy(alice_wanted.recv);
#if START_PEERS
GNUNET_TESTING_stop_daemons (peers);
#endif
GNUNET_GC_free (cfg);
+ if (error != 0)
+ ret = 1;
return ret;
}
Modified: GNUnet/src/applications/chat/lib/messaging.c
===================================================================
--- GNUnet/src/applications/chat/lib/messaging.c 2008-06-01 04:20:43 UTC
(rev 6962)
+++ GNUnet/src/applications/chat/lib/messaging.c 2008-06-01 06:36:06 UTC
(rev 6963)
@@ -155,6 +155,7 @@
CS_chat_MESSAGE_LeaveNotification *leave_msg;
CS_chat_MESSAGE_JoinNotification *join_msg;
CS_chat_MESSAGE_ReceiveNotification *received_msg;
+ GNUNET_HashCode id;
struct GNUNET_ECRS_MetaData *meta;
struct MemberList *members;
struct MemberList *pos;
@@ -246,11 +247,14 @@
room->member_list_callback (room->member_list_callback_cls,
NULL, &leave_msg->user,
GNUNET_CHAT_MSG_OPTION_NONE);
+ GNUNET_hash(&leave_msg->user,
+ sizeof(GNUNET_RSA_PublicKey),
+ &id);
prev = NULL;
pos = members;
while ((pos != NULL) &&
(0 != memcmp (&pos->id,
- &leave_msg->user, sizeof (GNUNET_HashCode))))
+ &id, sizeof (GNUNET_HashCode))))
{
prev = pos;
pos = pos->next;
Modified: GNUnet/src/applications/chat/module/chat.c
===================================================================
--- GNUnet/src/applications/chat/module/chat.c 2008-06-01 04:20:43 UTC (rev
6962)
+++ GNUnet/src/applications/chat/module/chat.c 2008-06-01 06:36:06 UTC (rev
6963)
@@ -111,7 +111,7 @@
rmsg->sender = pos->id;
else
memset (&rmsg->sender, 0, sizeof (GNUNET_HashCode));
- priv_msg = (0 == memcmp (&all_zeros,
+ priv_msg = (0 != memcmp (&all_zeros,
&cmsg->target, sizeof (GNUNET_HashCode)));
memcpy (&rmsg[1], &cmsg[1], msg_len);
pos = client_list_head;
@@ -123,7 +123,7 @@
(0 == memcmp (&cmsg->target,
&pos->id,
sizeof (GNUNET_HashCode)))) &&
- ((0 == ntohl (cmsg->msg_options)) & (~pos->msg_options)))
+ ((0 == (ntohl (cmsg->msg_options) & (~pos->msg_options)))))
{
coreAPI->cs_send_message (pos->client, &rmsg->header,
GNUNET_YES);
@@ -237,19 +237,22 @@
if (0 == strcmp (room_name, entry->room))
{
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);
+ if (entry->client != client)
+ {
+ 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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6963 - in GNUnet/src/applications/chat: lib module,
gnunet <=