64150c107793aa84ec6a62c778bc39c6990ad9ac
[oweals/gnunet.git] / test_chat_private.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file chat/test_chat_private.c
23  * @brief testcase for private chatting
24  * @author Vitaly Minko
25  */
26
27 #include "platform.h"
28 #include "gnunet_crypto_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_arm_service.h"
31 #include "gnunet_chat_service.h"
32
33 #define VERBOSE GNUNET_NO
34
35 #define START_ARM GNUNET_YES
36
37 /**
38  * How long until we give up on passing the test?
39  */
40 #define KILL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
41
42 /**
43  * How long until we give up on receiving somebody else's private message?
44  */
45 #define PM_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
46
47 struct PeerContext
48 {
49   struct GNUNET_CONFIGURATION_Handle *cfg;
50 #if START_ARM
51   struct GNUNET_OS_Process *arm_proc;
52 #endif
53 };
54
55 struct Wanted
56 {
57   struct GNUNET_CONTAINER_MetaData *meta;
58
59   struct GNUNET_HashCode *sender;
60
61   /**
62    * Alternative meta/sender is used when we expect join/leave notification
63    * from two peers and don't know which one will come first.
64    */
65   struct GNUNET_CONTAINER_MetaData *meta2;
66
67   struct GNUNET_HashCode *sender2;
68
69   char *msg;
70
71   const char *me;
72
73   enum GNUNET_CHAT_MsgOptions opt;
74
75   struct GNUNET_TIME_Absolute timestamp;
76
77   GNUNET_SCHEDULER_Task next_task;
78
79   void *next_task_cls;
80
81 };
82
83 static struct PeerContext p1;
84
85 static struct PeerContext p2;
86
87 static struct PeerContext p3;
88
89 static struct GNUNET_HashCode alice;
90
91 static struct GNUNET_HashCode bob;
92
93 static struct GNUNET_HashCode carol;
94
95 static struct GNUNET_CHAT_Room *alice_room;
96
97 static struct GNUNET_CHAT_Room *bob_room;
98
99 static struct GNUNET_CHAT_Room *carol_room;
100
101 static struct GNUNET_CONTAINER_MetaData *alice_meta;
102
103 static struct GNUNET_CONTAINER_MetaData *bob_meta;
104
105 static struct GNUNET_CONTAINER_MetaData *carol_meta;
106
107 static struct Wanted alice_wanted;
108
109 static struct Wanted bob_wanted;
110
111 static struct Wanted carol_wanted;
112
113 static GNUNET_SCHEDULER_TaskIdentifier kill_task;
114
115 static GNUNET_SCHEDULER_TaskIdentifier finish_task;
116
117 static GNUNET_SCHEDULER_TaskIdentifier wait_task;
118
119 static int err;
120
121 static int alice_ready;
122
123 static int bob_ready;
124
125 static int is_p2p;
126
127 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *bob_public_key;
128
129
130 static void
131 setup_peer (struct PeerContext *p, const char *cfgname)
132 {
133   char *binary;
134
135   binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
136   p->cfg = GNUNET_CONFIGURATION_create ();
137 #if START_ARM
138   p->arm_proc =
139     GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary,
140                                "gnunet-service-arm",
141                                "-c", cfgname, NULL);
142 #endif
143   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
144   GNUNET_free (binary);
145 }
146
147
148 static void
149 stop_arm (struct PeerContext *p)
150 {
151 #if START_ARM
152   if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
153     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
154   if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
155     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
156   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
157               GNUNET_OS_process_get_pid (p->arm_proc));
158   GNUNET_OS_process_destroy (p->arm_proc);
159   p->arm_proc = NULL;
160 #endif
161   GNUNET_CONFIGURATION_destroy (p->cfg);
162 }
163
164
165 static void
166 abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
167 {
168   if (alice_room != NULL)
169   {
170     GNUNET_CHAT_leave_room (alice_room);
171     alice_room = NULL;
172   }
173   if (bob_room != NULL)
174   {
175     GNUNET_CHAT_leave_room (bob_room);
176     bob_room = NULL;
177   }
178   if (carol_room != NULL)
179   {
180     GNUNET_CHAT_leave_room (carol_room);
181     carol_room = NULL;
182   }
183   err = 1;
184 }
185
186
187 static void
188 timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 {
190 #if VERBOSE
191   printf ("Timed out, stopping the test.\n");
192 #endif
193   kill_task = GNUNET_SCHEDULER_NO_TASK;
194   if (wait_task != GNUNET_SCHEDULER_NO_TASK)
195   {
196     GNUNET_SCHEDULER_cancel (wait_task);
197     wait_task = GNUNET_SCHEDULER_NO_TASK;
198   }
199   GNUNET_SCHEDULER_add_continuation (&abort_test, NULL,
200                                      GNUNET_SCHEDULER_REASON_PREREQ_DONE);
201 }
202
203
204 static int
205 join_cb (void *cls)
206 {
207   struct Wanted *want = cls;
208
209 #if VERBOSE
210   printf ("%s has joined\n", want->me);
211 #endif
212   if (NULL != want->next_task)
213     GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
214   return GNUNET_OK;
215 }
216
217
218 static int
219 member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info,
220                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
221                 enum GNUNET_CHAT_MsgOptions options)
222 {
223   struct Wanted *want = cls;
224   struct GNUNET_HashCode sender;
225
226 #if VERBOSE
227   printf ("%s - told that %s has %s\n", want->me,
228           member_info ==
229           NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
230                                                                 EXTRACTOR_METATYPE_TITLE),
231           member_info == NULL ? "left" : "joined");
232 #endif
233   GNUNET_CRYPTO_hash (member_id,
234                       sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
235                       &sender);
236   /* entertain both primary and an alternative sender/meta */
237   if (((0 == memcmp (&sender, want->sender, sizeof (struct GNUNET_HashCode))) ||
238        ((want->sender2 != NULL) &&
239         (0 == memcmp (&sender, want->sender2, sizeof (struct GNUNET_HashCode))))) &&
240       (((member_info == NULL) && (want->meta == NULL)) ||
241        ((member_info != NULL) &&
242         (((want->meta != NULL) &&
243           GNUNET_CONTAINER_meta_data_test_equal (member_info, want->meta)) ||
244          ((want->meta2 != NULL) &&
245           GNUNET_CONTAINER_meta_data_test_equal (member_info, want->meta2)))))
246       && (options == want->opt))
247   {
248     /* remember Bob's public key, we need it to send private message */
249     if (NULL == bob_public_key &&
250         (0 == memcmp (&bob, want->sender, sizeof (struct GNUNET_HashCode))))
251       bob_public_key =
252           GNUNET_memdup (member_id,
253                          sizeof (struct
254                                  GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
255     if (want->sender2 != NULL)
256     {
257       /* flush alternative sender */
258       if (0 == memcmp (&sender, want->sender, sizeof (struct GNUNET_HashCode)))
259       {
260         want->sender = want->sender2;
261         want->meta = want->meta2;
262       }
263       want->sender2 = NULL;
264       want->meta2 = NULL;
265     }
266     else if (NULL != want->next_task)
267       GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
268   }
269   else
270   {
271     GNUNET_SCHEDULER_cancel (kill_task);
272     kill_task = GNUNET_SCHEDULER_NO_TASK;
273     GNUNET_SCHEDULER_add_now (&abort_test, NULL);
274   }
275   return GNUNET_OK;
276 }
277
278
279 static int
280 receive_cb (void *cls, struct GNUNET_CHAT_Room *room,
281             const struct GNUNET_HashCode * sender,
282             const struct GNUNET_CONTAINER_MetaData *meta, const char *message,
283             struct GNUNET_TIME_Absolute timestamp,
284             enum GNUNET_CHAT_MsgOptions options)
285 {
286   struct Wanted *want = cls;
287
288 #if VERBOSE
289   printf ("%s - told that %s said '%s'\n", want->me,
290           meta == NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (meta,
291                                                                         EXTRACTOR_METATYPE_TITLE),
292           message);
293 #endif
294
295   if ((want->msg != NULL) && (0 == strcmp (message, want->msg)) &&
296       (((sender == NULL) && (want->sender == NULL)) ||
297        ((sender != NULL) && (want->sender != NULL) &&
298         (0 == memcmp (sender, want->sender, sizeof (struct GNUNET_HashCode))))) &&
299       (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) &&
300       (options == want->opt) &&
301       /* Not == since the library sets the actual timestamp, so it may be
302        * slightly greater
303        */
304       (timestamp.abs_value >= want->timestamp.abs_value))
305   {
306     if (NULL != want->next_task)
307       GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
308   }
309   else
310   {
311     GNUNET_SCHEDULER_cancel (kill_task);
312     kill_task = GNUNET_SCHEDULER_NO_TASK;
313     GNUNET_SCHEDULER_cancel (finish_task);
314     finish_task = GNUNET_SCHEDULER_NO_TASK;
315     GNUNET_SCHEDULER_add_now (&abort_test, NULL);
316   }
317   return GNUNET_OK;
318 }
319
320
321 static void
322 wait_until_all_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
323 {
324   GNUNET_SCHEDULER_Task task = cls;
325
326 #if VERBOSE
327   printf ("Waiting...\n");
328 #endif
329   if (alice_ready && bob_ready)
330   {
331     wait_task = GNUNET_SCHEDULER_NO_TASK;
332     GNUNET_SCHEDULER_add_now (task, NULL);
333   }
334   else
335     wait_task =
336         GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
337                                       (GNUNET_TIME_UNIT_MILLISECONDS, 5000),
338                                       &wait_until_all_ready, task);
339 }
340
341
342 static void
343 set_alice_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
344 {
345   alice_ready = GNUNET_YES;
346 }
347
348
349 static void
350 set_bob_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
351 {
352   bob_ready = GNUNET_YES;
353 }
354
355
356 static void
357 disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
358 {
359 #if VERBOSE
360   printf ("Alice is leaving.\n");
361 #endif
362   if (is_p2p)
363     stop_arm (&p2);
364   GNUNET_CHAT_leave_room (alice_room);
365   alice_room = NULL;
366   GNUNET_SCHEDULER_cancel (kill_task);
367   kill_task = GNUNET_SCHEDULER_NO_TASK;
368 }
369
370
371 static void
372 disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
373 {
374 #if VERBOSE
375   printf ("Bod is leaving.\n");
376 #endif
377   if (is_p2p)
378     stop_arm (&p3);
379   alice_wanted.meta = NULL;
380   alice_wanted.sender = &bob;
381   alice_wanted.msg = NULL;
382   alice_wanted.opt = 0;
383   alice_wanted.next_task = &disconnect_alice;
384   alice_wanted.next_task_cls = NULL;
385   GNUNET_CHAT_leave_room (bob_room);
386   bob_room = NULL;
387 }
388
389
390 static void
391 disconnect_carol (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
392 {
393 #if VERBOSE
394   printf ("Carol is leaving.\n");
395 #endif
396   alice_wanted.meta = NULL;
397   alice_wanted.sender = &carol;
398   alice_wanted.msg = NULL;
399   alice_wanted.opt = 0;
400   alice_wanted.next_task = &set_alice_ready;
401   alice_wanted.next_task_cls = NULL;
402   alice_ready = GNUNET_NO;
403   bob_wanted.meta = NULL;
404   bob_wanted.sender = &carol;
405   bob_wanted.msg = NULL;
406   bob_wanted.opt = 0;
407   bob_wanted.next_task = &wait_until_all_ready;
408   bob_wanted.next_task_cls = &disconnect_bob;
409   bob_ready = GNUNET_YES;
410   GNUNET_CHAT_leave_room (carol_room);
411   carol_room = NULL;
412 }
413
414
415 static void
416 send_from_alice_to_bob (void *cls,
417                         const struct GNUNET_SCHEDULER_TaskContext *tc)
418 {
419   uint32_t seq;
420
421 #if VERBOSE
422   printf ("Alice says 'Hi!' to Bob\n");
423 #endif
424   alice_ready = GNUNET_YES;
425   bob_ready = GNUNET_NO;
426   bob_wanted.meta = alice_meta;
427   bob_wanted.sender = &alice;
428   bob_wanted.msg = "Hi Bob!";
429   bob_wanted.opt = GNUNET_CHAT_MSG_PRIVATE;
430   bob_wanted.next_task = &set_bob_ready;
431   bob_wanted.next_task_cls = NULL;
432   /* Carol should not receive this message */
433   carol_wanted.meta = NULL;
434   carol_wanted.sender = NULL;
435   carol_wanted.msg = NULL;
436   carol_wanted.opt = 0;
437   carol_wanted.next_task = NULL;
438   carol_wanted.next_task_cls = NULL;
439   GNUNET_CHAT_send_message (alice_room, "Hi Bob!", GNUNET_CHAT_MSG_PRIVATE,
440                             bob_public_key, &seq);
441   finish_task =
442       GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT, &wait_until_all_ready,
443                                     &disconnect_carol);
444 }
445
446
447 static void
448 prepare_bob_for_alice_task (void *cls,
449                             const struct GNUNET_SCHEDULER_TaskContext *tc)
450 {
451   bob_wanted.meta = alice_meta;
452   bob_wanted.sender = &alice;
453   bob_wanted.msg = NULL;
454   bob_wanted.opt = -1;
455   bob_wanted.next_task = &set_bob_ready;
456   bob_wanted.next_task_cls = NULL;
457 }
458
459
460 static void
461 prepare_carol_for_alice_and_bob_task (void *cls,
462                                       const struct GNUNET_SCHEDULER_TaskContext
463                                       *tc)
464 {
465   carol_wanted.meta = alice_meta;
466   carol_wanted.sender = &alice;
467   /* set alternative meta/sender since we don't know from which peer
468    * notification will come first */
469   carol_wanted.meta2 = bob_meta;
470   carol_wanted.sender2 = &bob;
471   carol_wanted.msg = NULL;
472   carol_wanted.opt = -1;
473   carol_wanted.next_task = &wait_until_all_ready;
474   carol_wanted.next_task_cls = &send_from_alice_to_bob;
475 }
476
477
478 static void
479 join_carol_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
480 {
481 #if VERBOSE
482   printf ("Carol joining\n");
483 #endif
484   alice_wanted.meta = carol_meta;
485   alice_wanted.sender = &carol;
486   alice_wanted.msg = NULL;
487   alice_wanted.opt = -1;
488   alice_wanted.next_task = &set_alice_ready;
489   alice_wanted.next_task_cls = NULL;
490   alice_ready = GNUNET_NO;
491   bob_wanted.meta = carol_meta;
492   bob_wanted.sender = &carol;
493   bob_wanted.msg = NULL;
494   bob_wanted.opt = -1;
495   bob_wanted.next_task = &set_bob_ready;
496   bob_wanted.next_task_cls = NULL;
497   bob_ready = GNUNET_NO;
498   carol_wanted.next_task = &prepare_carol_for_alice_and_bob_task;
499   carol_wanted.next_task_cls = NULL;
500   carol_room =
501       GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta,
502                              "test", -1, &join_cb, &carol_wanted, &receive_cb,
503                              &carol_wanted, &member_list_cb, &carol_wanted,
504                              NULL, NULL, &carol);
505   if (NULL == carol_room)
506   {
507     GNUNET_SCHEDULER_cancel (kill_task);
508     kill_task = GNUNET_SCHEDULER_NO_TASK;
509     GNUNET_CHAT_leave_room (alice_room);
510     alice_room = NULL;
511     GNUNET_CHAT_leave_room (bob_room);
512     bob_room = NULL;
513     err = 1;
514   }
515 }
516
517
518 static void
519 join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
520 {
521 #if VERBOSE
522   printf ("Bob joining\n");
523 #endif
524   alice_wanted.meta = bob_meta;
525   alice_wanted.sender = &bob;
526   alice_wanted.msg = NULL;
527   alice_wanted.opt = -1;
528   alice_wanted.next_task = &wait_until_all_ready;
529   alice_wanted.next_task_cls = &join_carol_task;
530   alice_ready = GNUNET_YES;
531   bob_wanted.next_task = &prepare_bob_for_alice_task;
532   bob_wanted.next_task_cls = NULL;
533   bob_ready = GNUNET_NO;
534   bob_room =
535       GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, "test",
536                              -1, &join_cb, &bob_wanted, &receive_cb,
537                              &bob_wanted, &member_list_cb, &bob_wanted, NULL,
538                              NULL, &bob);
539   if (NULL == bob_room)
540   {
541     GNUNET_SCHEDULER_cancel (kill_task);
542     kill_task = GNUNET_SCHEDULER_NO_TASK;
543     GNUNET_CHAT_leave_room (alice_room);
544     alice_room = NULL;
545     err = 1;
546   }
547 }
548
549
550 static void
551 join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
552 {
553 #if VERBOSE
554   printf ("Alice joining\n");
555 #endif
556   alice_wanted.next_task = &join_bob_task;
557   alice_wanted.next_task_cls = NULL;
558   alice_room =
559       GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, "test", -1, &join_cb,
560                              &alice_wanted, &receive_cb, &alice_wanted,
561                              &member_list_cb, &alice_wanted, NULL, NULL,
562                              &alice);
563   if (NULL == alice_room)
564   {
565     GNUNET_SCHEDULER_cancel (kill_task);
566     kill_task = GNUNET_SCHEDULER_NO_TASK;
567     err = 1;
568   }
569 }
570
571
572 static void
573 run (void *cls, char *const *args, const char *cfgfile,
574      const struct GNUNET_CONFIGURATION_Handle *cfg)
575 {
576   if (is_p2p)
577   {
578     setup_peer (&p1, "test_chat_peer1.conf");
579     setup_peer (&p2, "test_chat_peer2.conf");
580     setup_peer (&p3, "test_chat_peer3.conf");
581   }
582   else
583     setup_peer (&p1, "test_chat_data.conf");
584
585   memset (&alice_wanted, 0, sizeof (struct Wanted));
586   memset (&bob_wanted, 0, sizeof (struct Wanted));
587   memset (&carol_wanted, 0, sizeof (struct Wanted));
588   alice_wanted.me = "Alice";
589   bob_wanted.me = "Bob";
590   carol_wanted.me = "Carol";
591   alice_meta = GNUNET_CONTAINER_meta_data_create ();
592   GNUNET_CONTAINER_meta_data_insert (alice_meta, "<gnunet>",
593                                      EXTRACTOR_METATYPE_TITLE,
594                                      EXTRACTOR_METAFORMAT_UTF8, "text/plain",
595                                      "Alice", strlen ("Alice") + 1);
596   bob_meta = GNUNET_CONTAINER_meta_data_create ();
597   GNUNET_CONTAINER_meta_data_insert (bob_meta, "<gnunet>",
598                                      EXTRACTOR_METATYPE_TITLE,
599                                      EXTRACTOR_METAFORMAT_UTF8, "text/plain",
600                                      "Bob", strlen ("Bob") + 1);
601   carol_meta = GNUNET_CONTAINER_meta_data_create ();
602   GNUNET_CONTAINER_meta_data_insert (carol_meta, "<gnunet>",
603                                      EXTRACTOR_METATYPE_TITLE,
604                                      EXTRACTOR_METAFORMAT_UTF8, "text/plain",
605                                      "Carol", strlen ("Carol") + 1);
606   kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL);
607   GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
608 }
609
610
611 int
612 main (int argc, char *argv[])
613 {
614   char *const argvx[] = {
615     "test-chat",
616     "-c",
617     "test_chat_data.conf",
618     NULL
619   };
620   struct GNUNET_GETOPT_CommandLineOption options[] = {
621     GNUNET_GETOPT_OPTION_END
622   };
623
624   GNUNET_log_setup ("test_chat",
625                     "WARNING",
626                     NULL);
627   if (strstr (argv[0], "p2p") != NULL)
628   {
629     is_p2p = GNUNET_YES;
630   }
631   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
632                       "test-chat", "nohelp", options, &run, NULL);
633   stop_arm (&p1);
634   GNUNET_CONTAINER_meta_data_destroy (alice_meta);
635   GNUNET_CONTAINER_meta_data_destroy (bob_meta);
636   GNUNET_CONTAINER_meta_data_destroy (carol_meta);
637   if (is_p2p)
638   {
639     GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
640     GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
641     GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/");
642   }
643   else
644     GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/");
645   return err;
646 }
647
648 /* end of test_chat_private.c */