diff options
author | Gabor X Toth <*@tg-x.net> | 2014-05-27 11:10:35 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-05-27 11:10:35 +0000 |
commit | cfeccc1b56def35ac586ac2c09ac70b523b59ef5 (patch) | |
tree | e0cb2abc1ce4c11514c29eb5c0c067443b3a6fbd /src | |
parent | 10f2f102658f935148475d5aa2b29afd8a4e85c2 (diff) | |
download | gnunet-cfeccc1b56def35ac586ac2c09ac70b523b59ef5.tar.gz gnunet-cfeccc1b56def35ac586ac2c09ac70b523b59ef5.zip |
add social service
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/include/gnunet_env_lib.h | 3 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 40 | ||||
-rw-r--r-- | src/include/gnunet_social_service.h | 27 | ||||
-rw-r--r-- | src/multicast/multicast.conf.in | 11 | ||||
-rw-r--r-- | src/psyc/gnunet-service-psyc.c | 4 | ||||
-rw-r--r-- | src/psyc/psyc.conf.in | 8 | ||||
-rw-r--r-- | src/psyc/test_psyc.conf | 2 | ||||
-rw-r--r-- | src/psycstore/psycstore.conf.in | 11 | ||||
-rw-r--r-- | src/social/Makefile.am | 78 | ||||
-rw-r--r-- | src/social/gnunet-service-social.c | 461 | ||||
-rw-r--r-- | src/social/social.conf.in | 12 | ||||
-rw-r--r-- | src/social/social.h | 46 | ||||
-rw-r--r-- | src/social/social_api.c | 627 | ||||
-rw-r--r-- | src/social/test_social.c | 158 | ||||
-rw-r--r-- | src/social/test_social.conf | 2 |
16 files changed, 1461 insertions, 30 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8aef2f38f..e339abf6d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -20,6 +20,7 @@ if HAVE_EXPERIMENTAL | |||
20 | env \ | 20 | env \ |
21 | psycstore \ | 21 | psycstore \ |
22 | psyc \ | 22 | psyc \ |
23 | social \ | ||
23 | $(CONSENSUS) \ | 24 | $(CONSENSUS) \ |
24 | $(SECRETSHARING) \ | 25 | $(SECRETSHARING) \ |
25 | $(SCALARPRODUCT) \ | 26 | $(SCALARPRODUCT) \ |
diff --git a/src/include/gnunet_env_lib.h b/src/include/gnunet_env_lib.h index 8ff37b7a7..5d1d013a3 100644 --- a/src/include/gnunet_env_lib.h +++ b/src/include/gnunet_env_lib.h | |||
@@ -93,7 +93,8 @@ enum GNUNET_ENV_Type | |||
93 | /** | 93 | /** |
94 | * PSYC state modifier. | 94 | * PSYC state modifier. |
95 | */ | 95 | */ |
96 | struct GNUNET_ENV_Modifier { | 96 | struct GNUNET_ENV_Modifier |
97 | { | ||
97 | /** | 98 | /** |
98 | * State operation. | 99 | * State operation. |
99 | */ | 100 | */ |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index fba99ff43..855ee0703 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -2171,13 +2171,13 @@ extern "C" | |||
2171 | /** S->C: result of an operation */ | 2171 | /** S->C: result of an operation */ |
2172 | #define GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE 680 | 2172 | #define GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE 680 |
2173 | 2173 | ||
2174 | /** C->S: request to start a master */ | 2174 | /** C->S: request to start a channel as a master */ |
2175 | #define GNUNET_MESSAGE_TYPE_PSYC_MASTER_START 681 | 2175 | #define GNUNET_MESSAGE_TYPE_PSYC_MASTER_START 681 |
2176 | 2176 | ||
2177 | /** S->C: master start acknowledgement */ | 2177 | /** S->C: master start acknowledgement */ |
2178 | #define GNUNET_MESSAGE_TYPE_PSYC_MASTER_START_ACK 682 | 2178 | #define GNUNET_MESSAGE_TYPE_PSYC_MASTER_START_ACK 682 |
2179 | 2179 | ||
2180 | /** C->S: request to start a master */ | 2180 | /** C->S: request to join a channel as a slave */ |
2181 | #define GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN 683 | 2181 | #define GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN 683 |
2182 | 2182 | ||
2183 | /** S->C: slave join acknowledgement */ | 2183 | /** S->C: slave join acknowledgement */ |
@@ -2489,14 +2489,42 @@ extern "C" | |||
2489 | #define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 825 | 2489 | #define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 825 |
2490 | 2490 | ||
2491 | 2491 | ||
2492 | /** | ||
2493 | * Next available: 840 | ||
2494 | */ | ||
2495 | |||
2496 | /******************************************************************************* | 2492 | /******************************************************************************* |
2497 | * SOCIAL message types | 2493 | * SOCIAL message types |
2498 | ******************************************************************************/ | 2494 | ******************************************************************************/ |
2499 | 2495 | ||
2496 | /** | ||
2497 | * C: client | ||
2498 | * S: service | ||
2499 | * P: PSYC | ||
2500 | */ | ||
2501 | |||
2502 | /** S->C: result of an operation */ | ||
2503 | #define GNUNET_MESSAGE_TYPE_SOCIAL_RESULT_CODE 840 | ||
2504 | |||
2505 | /** C->S: request to enter a home as the host */ | ||
2506 | #define GNUNET_MESSAGE_TYPE_SOCIAL_HOME_ENTER 841 | ||
2507 | |||
2508 | /** S->C: home enter acknowledgement */ | ||
2509 | #define GNUNET_MESSAGE_TYPE_SOCIAL_HOME_ENTER_ACK 842 | ||
2510 | |||
2511 | /** C->S: request to enter a place as a guest */ | ||
2512 | #define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_ENTER 843 | ||
2513 | |||
2514 | /** S->C: guest join acknowledgement */ | ||
2515 | #define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_ENTER_ACK 844 | ||
2516 | |||
2517 | /** P->S->C: incoming join request from PSYC */ | ||
2518 | #define GNUNET_MESSAGE_TYPE_SOCIAL_JOIN_REQUEST 847 | ||
2519 | |||
2520 | /** C->S->P: decision about a join request */ | ||
2521 | #define GNUNET_MESSAGE_TYPE_SOCIAL_JOIN_DECISION 848 | ||
2522 | |||
2523 | |||
2524 | /** | ||
2525 | * Next available: 880 | ||
2526 | */ | ||
2527 | |||
2500 | 2528 | ||
2501 | /** | 2529 | /** |
2502 | * Type used to match 'all' message types. | 2530 | * Type used to match 'all' message types. |
diff --git a/src/include/gnunet_social_service.h b/src/include/gnunet_social_service.h index 98ad88346..ba698aee6 100644 --- a/src/include/gnunet_social_service.h +++ b/src/include/gnunet_social_service.h | |||
@@ -36,9 +36,9 @@ extern "C" | |||
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include "gnunet_util_lib.h" | 38 | #include "gnunet_util_lib.h" |
39 | #include "gnunet_psyc_lib.h" | 39 | #include "gnunet_env_lib.h" |
40 | #include "gnunet_identity_service.h" | ||
40 | #include "gnunet_psyc_service.h" | 41 | #include "gnunet_psyc_service.h" |
41 | #include "gnunet_multicast_service.h" | ||
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
@@ -94,7 +94,7 @@ typedef int | |||
94 | const char *full_method_name, | 94 | const char *full_method_name, |
95 | uint64_t message_id, | 95 | uint64_t message_id, |
96 | size_t modifier_count, | 96 | size_t modifier_count, |
97 | GNUNET_PSYC_Modifier *modifiers, | 97 | struct GNUNET_ENV_Modifier *modifiers, |
98 | uint64_t data_offset, | 98 | uint64_t data_offset, |
99 | const void *data, | 99 | const void *data, |
100 | size_t data_size, | 100 | size_t data_size, |
@@ -173,7 +173,7 @@ typedef void | |||
173 | struct GNUNET_SOCIAL_Nym *nym, | 173 | struct GNUNET_SOCIAL_Nym *nym, |
174 | size_t variable_count, | 174 | size_t variable_count, |
175 | const char *method_name, | 175 | const char *method_name, |
176 | GNUNET_PSYC_Modifier *variables, | 176 | struct GNUNET_ENV_Modifier *variables, |
177 | const void *data, | 177 | const void *data, |
178 | size_t data_size); | 178 | size_t data_size); |
179 | 179 | ||
@@ -193,7 +193,7 @@ typedef void | |||
193 | (*GNUNET_SOCIAL_FarewellCallback) (void *cls, | 193 | (*GNUNET_SOCIAL_FarewellCallback) (void *cls, |
194 | struct GNUNET_SOCIAL_Nym *nym, | 194 | struct GNUNET_SOCIAL_Nym *nym, |
195 | size_t variable_count, | 195 | size_t variable_count, |
196 | GNUNET_PSYC_Modifier *variables); | 196 | struct GNUNET_ENV_Modifier *variables); |
197 | 197 | ||
198 | 198 | ||
199 | /** | 199 | /** |
@@ -313,22 +313,24 @@ GNUNET_SOCIAL_home_advertise (struct GNUNET_SOCIAL_Home *home, | |||
313 | const char *name, | 313 | const char *name, |
314 | size_t peer_count, | 314 | size_t peer_count, |
315 | const struct GNUNET_PeerIdentity *peers, | 315 | const struct GNUNET_PeerIdentity *peers, |
316 | GNUNET_TIME_Relative expiration_time, | 316 | struct GNUNET_TIME_Relative expiration_time, |
317 | const char *password); | 317 | const char *password); |
318 | 318 | ||
319 | 319 | ||
320 | /** | 320 | /** |
321 | * Flags for announcements in a home. | 321 | * Flags for announcements in a home. |
322 | */ | 322 | */ |
323 | enum GNUNET_PSYC_AnnouncementFlags | 323 | enum GNUNET_SOCIAL_AnnounceFlags |
324 | { | 324 | { |
325 | GNUNET_SOCIAL_ANNOUNCE_NONE = 0, | ||
326 | |||
325 | /** | 327 | /** |
326 | * Whether this announcement removes all objects from the home. | 328 | * Whether this announcement removes all objects from the home. |
327 | * | 329 | * |
328 | * New objects can be still added to the now empty home using the @e env | 330 | * New objects can be still added to the now empty home using the @e env |
329 | * parameter of the same announcement. | 331 | * parameter of the same announcement. |
330 | */ | 332 | */ |
331 | GNUNET_SOCIAL_ANNOUNCEMENT_CLEAR_OBJECTS = 1 << 0 | 333 | GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0 |
332 | }; | 334 | }; |
333 | 335 | ||
334 | 336 | ||
@@ -359,7 +361,7 @@ GNUNET_SOCIAL_home_announce (struct GNUNET_SOCIAL_Home *home, | |||
359 | const struct GNUNET_ENV_Environment *env, | 361 | const struct GNUNET_ENV_Environment *env, |
360 | GNUNET_CONNECTION_TransmitReadyNotify notify, | 362 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
361 | void *notify_cls, | 363 | void *notify_cls, |
362 | GNUNET_SOCIAL_AnnouncementFlags flags); | 364 | enum GNUNET_SOCIAL_AnnounceFlags flags); |
363 | 365 | ||
364 | 366 | ||
365 | /** | 367 | /** |
@@ -529,7 +531,10 @@ GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place, | |||
529 | /** | 531 | /** |
530 | * Flags for talking to the host of a place. | 532 | * Flags for talking to the host of a place. |
531 | */ | 533 | */ |
532 | enum GNUNET_SOCIAL_TalkFlags; | 534 | enum GNUNET_SOCIAL_TalkFlags |
535 | { | ||
536 | GNUNET_SOCIAL_TALK_NONE = 0 | ||
537 | }; | ||
533 | 538 | ||
534 | 539 | ||
535 | /** | 540 | /** |
@@ -555,7 +560,7 @@ GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place, | |||
555 | const struct GNUNET_ENV_Environment *env, | 560 | const struct GNUNET_ENV_Environment *env, |
556 | GNUNET_CONNECTION_TransmitReadyNotify notify, | 561 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
557 | void *notify_cls, | 562 | void *notify_cls, |
558 | GNUNET_SOCIAL_TalkFlags flags); | 563 | enum GNUNET_SOCIAL_TalkFlags flags); |
559 | 564 | ||
560 | 565 | ||
561 | /** | 566 | /** |
diff --git a/src/multicast/multicast.conf.in b/src/multicast/multicast.conf.in index dab90c7eb..f4a6daa1e 100644 --- a/src/multicast/multicast.conf.in +++ b/src/multicast/multicast.conf.in | |||
@@ -1,13 +1,16 @@ | |||
1 | [multicast] | 1 | [multicast] |
2 | AUTOSTART = @AUTOSTART@ | 2 | AUTOSTART = @AUTOSTART@ |
3 | PORT = 2109 | ||
4 | HOSTNAME = localhost | ||
5 | BINARY = gnunet-service-multicast | 3 | BINARY = gnunet-service-multicast |
6 | ACCEPT_FROM = 127.0.0.1; | 4 | |
7 | ACCEPT_FROM6 = ::1; | ||
8 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-multicast.sock | 5 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-multicast.sock |
9 | UNIX_MATCH_UID = YES | 6 | UNIX_MATCH_UID = YES |
10 | UNIX_MATCH_GID = YES | 7 | UNIX_MATCH_GID = YES |
8 | |||
9 | @UNIXONLY@PORT = 2109 | ||
10 | HOSTNAME = localhost | ||
11 | ACCEPT_FROM = 127.0.0.1; | ||
12 | ACCEPT_FROM6 = ::1; | ||
13 | |||
11 | # DISABLE_SOCKET_FORWARDING = NO | 14 | # DISABLE_SOCKET_FORWARDING = NO |
12 | # USERNAME = | 15 | # USERNAME = |
13 | # MAXBUF = | 16 | # MAXBUF = |
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c index cef89b828..13f908b6c 100644 --- a/src/psyc/gnunet-service-psyc.c +++ b/src/psyc/gnunet-service-psyc.c | |||
@@ -327,7 +327,7 @@ struct Master | |||
327 | /** | 327 | /** |
328 | * @see enum GNUNET_PSYC_Policy | 328 | * @see enum GNUNET_PSYC_Policy |
329 | */ | 329 | */ |
330 | uint32_t policy; | 330 | enum GNUNET_PSYC_Policy policy; |
331 | }; | 331 | }; |
332 | 332 | ||
333 | 333 | ||
@@ -2062,4 +2062,4 @@ main (int argc, char *const *argv) | |||
2062 | &run, NULL)) ? 0 : 1; | 2062 | &run, NULL)) ? 0 : 1; |
2063 | } | 2063 | } |
2064 | 2064 | ||
2065 | /* end of gnunet-service-psycstore.c */ | 2065 | /* end of gnunet-service-psyc.c */ |
diff --git a/src/psyc/psyc.conf.in b/src/psyc/psyc.conf.in index 461552698..4a4a96954 100644 --- a/src/psyc/psyc.conf.in +++ b/src/psyc/psyc.conf.in | |||
@@ -1,8 +1,12 @@ | |||
1 | [psyc] | 1 | [psyc] |
2 | AUTOSTART = @AUTOSTART@ | 2 | AUTOSTART = @AUTOSTART@ |
3 | BINARY = gnunet-service-psyc | 3 | BINARY = gnunet-service-psyc |
4 | |||
4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-psyc.sock | 5 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-psyc.sock |
5 | UNIX_MATCH_UID = NO | 6 | UNIX_MATCH_UID = YES |
6 | UNIX_MATCH_GID = YES | 7 | UNIX_MATCH_GID = YES |
8 | |||
7 | @UNIXONLY@PORT = 2115 | 9 | @UNIXONLY@PORT = 2115 |
8 | HOSTNAME = localhost \ No newline at end of file | 10 | HOSTNAME = localhost |
11 | ACCEPT_FROM = 127.0.0.1; | ||
12 | ACCEPT_FROM6 = ::1; | ||
diff --git a/src/psyc/test_psyc.conf b/src/psyc/test_psyc.conf index 70a408ae3..8eb0019a9 100644 --- a/src/psyc/test_psyc.conf +++ b/src/psyc/test_psyc.conf | |||
@@ -1,2 +1,2 @@ | |||
1 | [arm] | 1 | [arm] |
2 | DEFAULTSERVICES = psyc psycstore multicast | 2 | DEFAULTSERVICES = multicast psycstore psyc |
diff --git a/src/psycstore/psycstore.conf.in b/src/psycstore/psycstore.conf.in index 18c2d1adf..ba8b21753 100644 --- a/src/psycstore/psycstore.conf.in +++ b/src/psycstore/psycstore.conf.in | |||
@@ -1,11 +1,16 @@ | |||
1 | [psycstore] | 1 | [psycstore] |
2 | AUTOSTART = @AUTOSTART@ | 2 | AUTOSTART = @AUTOSTART@ |
3 | BINARY = gnunet-service-psycstore | 3 | BINARY = gnunet-service-psycstore |
4 | |||
4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-psycstore.sock | 5 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-psycstore.sock |
5 | HOSTNAME = localhost | 6 | UNIX_MATCH_UID = YES |
6 | @UNIXONLY@PORT = 2111 | ||
7 | UNIX_MATCH_UID = NO | ||
8 | UNIX_MATCH_GID = YES | 7 | UNIX_MATCH_GID = YES |
8 | |||
9 | @UNIXONLY@PORT = 2111 | ||
10 | HOSTNAME = localhost | ||
11 | ACCEPT_FROM = 127.0.0.1; | ||
12 | ACCEPT_FROM6 = ::1; | ||
13 | |||
9 | DATABASE = sqlite | 14 | DATABASE = sqlite |
10 | 15 | ||
11 | [psycstore-sqlite] | 16 | [psycstore-sqlite] |
diff --git a/src/social/Makefile.am b/src/social/Makefile.am new file mode 100644 index 000000000..04184dbc6 --- /dev/null +++ b/src/social/Makefile.am | |||
@@ -0,0 +1,78 @@ | |||
1 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | ||
2 | |||
3 | pkgcfgdir= $(pkgdatadir)/config.d/ | ||
4 | |||
5 | libexecdir= $(pkglibdir)/libexec/ | ||
6 | |||
7 | pkgcfg_DATA = \ | ||
8 | social.conf | ||
9 | |||
10 | |||
11 | if MINGW | ||
12 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | ||
13 | endif | ||
14 | |||
15 | if USE_COVERAGE | ||
16 | AM_CFLAGS = --coverage -O0 | ||
17 | XLIB = -lgcov | ||
18 | endif | ||
19 | |||
20 | lib_LTLIBRARIES = libgnunetsocial.la | ||
21 | |||
22 | libgnunetsocial_la_SOURCES = \ | ||
23 | social_api.c social.h | ||
24 | libgnunetsocial_la_LIBADD = \ | ||
25 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
26 | $(top_builddir)/src/env/libgnunetenv.la \ | ||
27 | $(GN_LIBINTL) $(XLIB) | ||
28 | libgnunetsocial_la_LDFLAGS = \ | ||
29 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | ||
30 | -version-info 0:0:0 | ||
31 | libgnunetsocial_la_DEPENDENCIES = \ | ||
32 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
33 | $(top_builddir)/src/env/libgnunetenv.la | ||
34 | |||
35 | bin_PROGRAMS = | ||
36 | |||
37 | libexec_PROGRAMS = \ | ||
38 | gnunet-service-social | ||
39 | |||
40 | gnunet_service_social_SOURCES = \ | ||
41 | gnunet-service-social.c | ||
42 | gnunet_service_social_LDADD = \ | ||
43 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
44 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
45 | $(top_builddir)/src/psyc/libgnunetpsyc.la \ | ||
46 | $(GN_LIBINTL) | ||
47 | gnunet_service_social_DEPENDENCIES = \ | ||
48 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
49 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
50 | $(top_builddir)/src/psyc/libgnunetpsyc.la | ||
51 | gnunet_service_social_CFLAGS = $(AM_CFLAGS) | ||
52 | |||
53 | |||
54 | if HAVE_TESTING | ||
55 | check_PROGRAMS = \ | ||
56 | test_social | ||
57 | endif | ||
58 | |||
59 | if ENABLE_TEST_RUN | ||
60 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | ||
61 | TESTS = $(check_PROGRAMS) | ||
62 | endif | ||
63 | |||
64 | test_social_SOURCES = \ | ||
65 | test_social.c | ||
66 | test_social_LDADD = \ | ||
67 | libgnunetsocial.la \ | ||
68 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
69 | $(top_builddir)/src/env/libgnunetenv.la \ | ||
70 | $(top_builddir)/src/util/libgnunetutil.la | ||
71 | test_social_DEPENDENCIES = \ | ||
72 | libgnunetsocial.la \ | ||
73 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
74 | $(top_builddir)/src/env/libgnunetenv.la \ | ||
75 | $(top_builddir)/src/util/libgnunetutil.la | ||
76 | |||
77 | EXTRA_DIST = \ | ||
78 | test_social.conf | ||
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c new file mode 100644 index 000000000..db704898b --- /dev/null +++ b/src/social/gnunet-service-social.c | |||
@@ -0,0 +1,461 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet | ||
3 | * (C) 2013 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 psyc/gnunet-service-social.c | ||
23 | * @brief Social service | ||
24 | * @author Gabor X Toth | ||
25 | */ | ||
26 | |||
27 | #include <inttypes.h> | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_constants.h" | ||
32 | #include "gnunet_protocols.h" | ||
33 | #include "gnunet_statistics_service.h" | ||
34 | #include "gnunet_psyc_service.h" | ||
35 | #include "gnunet_social_service.h" | ||
36 | #include "social.h" | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Handle to our current configuration. | ||
41 | */ | ||
42 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
43 | |||
44 | /** | ||
45 | * Handle to the statistics service. | ||
46 | */ | ||
47 | static struct GNUNET_STATISTICS_Handle *stats; | ||
48 | |||
49 | /** | ||
50 | * Notification context, simplifies client broadcasts. | ||
51 | */ | ||
52 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
53 | |||
54 | /** | ||
55 | * All connected hosts. | ||
56 | * Place's pub_key_hash -> struct Host | ||
57 | */ | ||
58 | static struct GNUNET_CONTAINER_MultiHashMap *hosts; | ||
59 | |||
60 | /** | ||
61 | * All connected guests. | ||
62 | * Place's pub_key_hash -> struct Guest | ||
63 | */ | ||
64 | static struct GNUNET_CONTAINER_MultiHashMap *guests; | ||
65 | |||
66 | /** | ||
67 | * Connected guests per place. | ||
68 | * Place's pub_key_hash -> Guest's pub_key -> struct Guest | ||
69 | */ | ||
70 | static struct GNUNET_CONTAINER_MultiHashMap *place_guests; | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Message in the transmission queue. | ||
75 | */ | ||
76 | struct TransmitMessage | ||
77 | { | ||
78 | struct TransmitMessage *prev; | ||
79 | struct TransmitMessage *next; | ||
80 | |||
81 | struct GNUNET_SERVER_Client *client; | ||
82 | |||
83 | /** | ||
84 | * ID assigned to the message. | ||
85 | */ | ||
86 | uint64_t id; | ||
87 | |||
88 | /** | ||
89 | * Size of @a buf | ||
90 | */ | ||
91 | uint16_t size; | ||
92 | |||
93 | /** | ||
94 | * @see enum MessageState | ||
95 | */ | ||
96 | uint8_t state; | ||
97 | |||
98 | /* Followed by message */ | ||
99 | }; | ||
100 | |||
101 | |||
102 | /** | ||
103 | * List of connected clients. | ||
104 | */ | ||
105 | struct ClientList | ||
106 | { | ||
107 | struct ClientList *prev; | ||
108 | struct ClientList *next; | ||
109 | struct GNUNET_SERVER_Client *client; | ||
110 | }; | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Common part of the client context for both a host and guest. | ||
115 | */ | ||
116 | struct Place | ||
117 | { | ||
118 | struct ClientList *clients_head; | ||
119 | struct ClientList *clients_tail; | ||
120 | |||
121 | struct TransmitMessage *tmit_head; | ||
122 | struct TransmitMessage *tmit_tail; | ||
123 | |||
124 | /** | ||
125 | * Public key of the channel. | ||
126 | */ | ||
127 | struct GNUNET_CRYPTO_EddsaPublicKey pub_key; | ||
128 | |||
129 | /** | ||
130 | * Hash of @a pub_key. | ||
131 | */ | ||
132 | struct GNUNET_HashCode pub_key_hash; | ||
133 | |||
134 | /** | ||
135 | * Is this a host (#GNUNET_YES), or guest (#GNUNET_NO)? | ||
136 | */ | ||
137 | uint8_t is_host; | ||
138 | }; | ||
139 | |||
140 | |||
141 | /** | ||
142 | * Client context for a host. | ||
143 | */ | ||
144 | struct Host | ||
145 | { | ||
146 | /** | ||
147 | * Place struct common for Host and Guest | ||
148 | */ | ||
149 | struct Place pl; | ||
150 | |||
151 | /** | ||
152 | * Private key of the channel. | ||
153 | */ | ||
154 | struct GNUNET_CRYPTO_EddsaPrivateKey priv_key; | ||
155 | |||
156 | /** | ||
157 | * Handle for the multicast origin. | ||
158 | */ | ||
159 | struct GNUNET_PSYC_Master *master; | ||
160 | |||
161 | /** | ||
162 | * Transmit handle for multicast. | ||
163 | */ | ||
164 | struct GNUNET_PSYC_MasterTransmitHandle *tmit_handle; | ||
165 | |||
166 | /** | ||
167 | * Incoming join requests. | ||
168 | * guest_key -> struct GNUNET_PSYC_JoinHandle * | ||
169 | */ | ||
170 | struct GNUNET_CONTAINER_MultiHashMap *join_reqs; | ||
171 | |||
172 | /** | ||
173 | * @see enum GNUNET_PSYC_Policy | ||
174 | */ | ||
175 | enum GNUNET_PSYC_Policy policy; | ||
176 | }; | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Client context for a guest. | ||
181 | */ | ||
182 | struct Guest | ||
183 | { | ||
184 | /** | ||
185 | * Place struct common for Host and Guest. | ||
186 | */ | ||
187 | struct Place pl; | ||
188 | |||
189 | /** | ||
190 | * Private key of the slave. | ||
191 | */ | ||
192 | struct GNUNET_CRYPTO_EddsaPrivateKey priv_key; | ||
193 | |||
194 | /** | ||
195 | * Public key of the slave. | ||
196 | */ | ||
197 | struct GNUNET_CRYPTO_EddsaPublicKey pub_key; | ||
198 | |||
199 | /** | ||
200 | * Hash of @a pub_key. | ||
201 | */ | ||
202 | struct GNUNET_HashCode pub_key_hash; | ||
203 | |||
204 | /** | ||
205 | * Handle for the PSYC slave. | ||
206 | */ | ||
207 | struct GNUNET_PSYC_Slave *slave; | ||
208 | |||
209 | /** | ||
210 | * Transmit handle for multicast. | ||
211 | */ | ||
212 | struct GNUNET_PSYC_SlaveTransmitHandle *tmit_handle; | ||
213 | |||
214 | /** | ||
215 | * Peer identity of the origin. | ||
216 | */ | ||
217 | struct GNUNET_PeerIdentity origin; | ||
218 | |||
219 | /** | ||
220 | * Number of items in @a relays. | ||
221 | */ | ||
222 | uint32_t relay_count; | ||
223 | |||
224 | /** | ||
225 | * Relays that multicast can use to connect. | ||
226 | */ | ||
227 | struct GNUNET_PeerIdentity *relays; | ||
228 | |||
229 | /** | ||
230 | * Join request to be transmitted to the master on join. | ||
231 | */ | ||
232 | struct GNUNET_MessageHeader *join_req; | ||
233 | }; | ||
234 | |||
235 | |||
236 | static inline void | ||
237 | transmit_message (struct Place *pl); | ||
238 | |||
239 | |||
240 | /** | ||
241 | * Task run during shutdown. | ||
242 | * | ||
243 | * @param cls unused | ||
244 | * @param tc unused | ||
245 | */ | ||
246 | static void | ||
247 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
248 | { | ||
249 | if (NULL != nc) | ||
250 | { | ||
251 | GNUNET_SERVER_notification_context_destroy (nc); | ||
252 | nc = NULL; | ||
253 | } | ||
254 | if (NULL != stats) | ||
255 | { | ||
256 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); | ||
257 | stats = NULL; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | |||
262 | /** | ||
263 | * Clean up host data structures after a client disconnected. | ||
264 | */ | ||
265 | static void | ||
266 | cleanup_host (struct Host *hst) | ||
267 | { | ||
268 | struct Place *pl = &hst->pl; | ||
269 | |||
270 | if (NULL != hst->master) | ||
271 | GNUNET_PSYC_master_stop (hst->master); | ||
272 | GNUNET_CONTAINER_multihashmap_destroy (hst->join_reqs); | ||
273 | GNUNET_CONTAINER_multihashmap_remove (hosts, &pl->pub_key_hash, pl); | ||
274 | } | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Clean up guest data structures after a client disconnected. | ||
279 | */ | ||
280 | static void | ||
281 | cleanup_guest (struct Guest *gst) | ||
282 | { | ||
283 | struct Place *pl = &gst->pl; | ||
284 | struct GNUNET_CONTAINER_MultiHashMap * | ||
285 | pl_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, | ||
286 | &pl->pub_key_hash); | ||
287 | GNUNET_assert (NULL != pl_gst); | ||
288 | GNUNET_CONTAINER_multihashmap_remove (pl_gst, &gst->pub_key_hash, gst); | ||
289 | |||
290 | if (0 == GNUNET_CONTAINER_multihashmap_size (pl_gst)) | ||
291 | { | ||
292 | GNUNET_CONTAINER_multihashmap_remove (place_guests, &pl->pub_key_hash, | ||
293 | pl_gst); | ||
294 | GNUNET_CONTAINER_multihashmap_destroy (pl_gst); | ||
295 | } | ||
296 | GNUNET_CONTAINER_multihashmap_remove (guests, &pl->pub_key_hash, gst); | ||
297 | |||
298 | if (NULL != gst->join_req) | ||
299 | GNUNET_free (gst->join_req); | ||
300 | if (NULL != gst->relays) | ||
301 | GNUNET_free (gst->relays); | ||
302 | if (NULL != gst->slave) | ||
303 | GNUNET_PSYC_slave_part (gst->slave); | ||
304 | GNUNET_CONTAINER_multihashmap_remove (guests, &pl->pub_key_hash, pl); | ||
305 | } | ||
306 | |||
307 | |||
308 | /** | ||
309 | * Clean up place data structures after a client disconnected. | ||
310 | */ | ||
311 | static void | ||
312 | cleanup_place (struct Place *pl) | ||
313 | { | ||
314 | (GNUNET_YES == pl->is_host) | ||
315 | ? cleanup_host ((struct Host *) pl) | ||
316 | : cleanup_guest ((struct Guest *) pl); | ||
317 | GNUNET_free (pl); | ||
318 | } | ||
319 | |||
320 | |||
321 | /** | ||
322 | * Called whenever a client is disconnected. | ||
323 | * Frees our resources associated with that client. | ||
324 | * | ||
325 | * @param cls Closure. | ||
326 | * @param client Identification of the client. | ||
327 | */ | ||
328 | static void | ||
329 | client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | ||
330 | { | ||
331 | if (NULL == client) | ||
332 | return; | ||
333 | |||
334 | struct Place * | ||
335 | pl = GNUNET_SERVER_client_get_user_context (client, struct Place); | ||
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
337 | "%p Client (%s) disconnected from place %s\n", | ||
338 | pl, (GNUNET_YES == pl->is_host) ? "host" : "guest", | ||
339 | GNUNET_h2s (&pl->pub_key_hash)); | ||
340 | |||
341 | if (NULL == pl) | ||
342 | { | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
344 | "%p User context is NULL in client_disconnect()\n", pl); | ||
345 | GNUNET_break (0); | ||
346 | return; | ||
347 | } | ||
348 | |||
349 | struct ClientList *cl = pl->clients_head; | ||
350 | while (NULL != cl) | ||
351 | { | ||
352 | if (cl->client == client) | ||
353 | { | ||
354 | GNUNET_CONTAINER_DLL_remove (pl->clients_head, pl->clients_tail, cl); | ||
355 | GNUNET_free (cl); | ||
356 | break; | ||
357 | } | ||
358 | cl = cl->next; | ||
359 | } | ||
360 | |||
361 | if (NULL == pl->clients_head) | ||
362 | { /* Last client disconnected. */ | ||
363 | if (NULL != pl->tmit_head) | ||
364 | { /* Send pending messages to PSYC before cleanup. */ | ||
365 | //FIXME: transmit_message (pl); | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | cleanup_place (pl); | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | |||
374 | |||
375 | static void | ||
376 | client_home_enter (void *cls, struct GNUNET_SERVER_Client *client, | ||
377 | const struct GNUNET_MessageHeader *msg) | ||
378 | { | ||
379 | |||
380 | } | ||
381 | |||
382 | |||
383 | static void | ||
384 | client_place_enter (void *cls, struct GNUNET_SERVER_Client *client, | ||
385 | const struct GNUNET_MessageHeader *msg) | ||
386 | { | ||
387 | |||
388 | } | ||
389 | |||
390 | |||
391 | static void | ||
392 | client_join_decision (void *cls, struct GNUNET_SERVER_Client *client, | ||
393 | const struct GNUNET_MessageHeader *msg) | ||
394 | { | ||
395 | |||
396 | } | ||
397 | |||
398 | |||
399 | static void | ||
400 | client_psyc_message (void *cls, struct GNUNET_SERVER_Client *client, | ||
401 | const struct GNUNET_MessageHeader *msg) | ||
402 | { | ||
403 | |||
404 | } | ||
405 | |||
406 | |||
407 | /** | ||
408 | * Initialize the PSYC service. | ||
409 | * | ||
410 | * @param cls Closure. | ||
411 | * @param server The initialized server. | ||
412 | * @param c Configuration to use. | ||
413 | */ | ||
414 | static void | ||
415 | run (void *cls, struct GNUNET_SERVER_Handle *server, | ||
416 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
417 | { | ||
418 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
419 | { &client_home_enter, NULL, | ||
420 | GNUNET_MESSAGE_TYPE_SOCIAL_HOME_ENTER, 0 }, | ||
421 | |||
422 | { &client_place_enter, NULL, | ||
423 | GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_ENTER, 0 }, | ||
424 | |||
425 | { &client_join_decision, NULL, | ||
426 | GNUNET_MESSAGE_TYPE_SOCIAL_JOIN_DECISION, 0 }, | ||
427 | |||
428 | { &client_psyc_message, NULL, | ||
429 | GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 0 } | ||
430 | }; | ||
431 | |||
432 | cfg = c; | ||
433 | stats = GNUNET_STATISTICS_create ("social", cfg); | ||
434 | hosts = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); | ||
435 | guests = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); | ||
436 | place_guests = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | ||
437 | nc = GNUNET_SERVER_notification_context_create (server, 1); | ||
438 | GNUNET_SERVER_add_handlers (server, handlers); | ||
439 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); | ||
440 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
441 | &shutdown_task, NULL); | ||
442 | } | ||
443 | |||
444 | |||
445 | /** | ||
446 | * The main function for the service. | ||
447 | * | ||
448 | * @param argc number of arguments from the command line | ||
449 | * @param argv command line arguments | ||
450 | * @return 0 ok, 1 on error | ||
451 | */ | ||
452 | int | ||
453 | main (int argc, char *const *argv) | ||
454 | { | ||
455 | return (GNUNET_OK == | ||
456 | GNUNET_SERVICE_run (argc, argv, "social", | ||
457 | GNUNET_SERVICE_OPTION_NONE, | ||
458 | &run, NULL)) ? 0 : 1; | ||
459 | } | ||
460 | |||
461 | /* end of gnunet-service-social.c */ | ||
diff --git a/src/social/social.conf.in b/src/social/social.conf.in new file mode 100644 index 000000000..e52318bc3 --- /dev/null +++ b/src/social/social.conf.in | |||
@@ -0,0 +1,12 @@ | |||
1 | [social] | ||
2 | AUTOSTART = @AUTOSTART@ | ||
3 | BINARY = gnunet-service-social | ||
4 | |||
5 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-social.sock | ||
6 | UNIX_MATCH_UID = YES | ||
7 | UNIX_MATCH_GID = YES | ||
8 | |||
9 | @UNIXONLY@PORT = 2116 | ||
10 | HOSTNAME = localhost | ||
11 | ACCEPT_FROM = 127.0.0.1; | ||
12 | ACCEPT_FROM6 = ::1; | ||
diff --git a/src/social/social.h b/src/social/social.h new file mode 100644 index 000000000..7f854eed8 --- /dev/null +++ b/src/social/social.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet | ||
3 | * (C) 2013 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 psyc/psyc.h | ||
23 | * @brief Common type definitions for the Social service and API. | ||
24 | * @author Gabor X Toth | ||
25 | */ | ||
26 | |||
27 | #ifndef SOCIAL_H | ||
28 | #define SOCIAL_H | ||
29 | |||
30 | #include "platform.h" | ||
31 | #include "gnunet_social_service.h" | ||
32 | |||
33 | |||
34 | GNUNET_NETWORK_STRUCT_BEGIN | ||
35 | |||
36 | /**** library -> service ****/ | ||
37 | |||
38 | |||
39 | |||
40 | /**** service -> library ****/ | ||
41 | |||
42 | |||
43 | |||
44 | GNUNET_NETWORK_STRUCT_END | ||
45 | |||
46 | #endif | ||
diff --git a/src/social/social_api.c b/src/social/social_api.c new file mode 100644 index 000000000..fd6e8f04a --- /dev/null +++ b/src/social/social_api.c | |||
@@ -0,0 +1,627 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet | ||
3 | * (C) 2013 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 social/social_api.c | ||
23 | * @brief Social service; implements social functionality using the PSYC service. | ||
24 | * @author Gabor X Toth | ||
25 | */ | ||
26 | |||
27 | #include <inttypes.h> | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_env_lib.h" | ||
32 | #include "gnunet_psyc_service.h" | ||
33 | #include "gnunet_social_service.h" | ||
34 | #include "social.h" | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Handle for another user (who is likely pseudonymous) in the network. | ||
39 | */ | ||
40 | struct GNUNET_SOCIAL_Nym | ||
41 | { | ||
42 | |||
43 | }; | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Handle for a place where social interactions happen. | ||
48 | */ | ||
49 | struct GNUNET_SOCIAL_Place | ||
50 | { | ||
51 | |||
52 | }; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Handle for a place that one of our egos hosts. | ||
57 | */ | ||
58 | struct GNUNET_SOCIAL_Home | ||
59 | { | ||
60 | |||
61 | }; | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Handle to an implementation of try-and-slice. | ||
66 | */ | ||
67 | struct GNUNET_SOCIAL_Slicer | ||
68 | { | ||
69 | |||
70 | }; | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Handle for an announcement request. | ||
75 | */ | ||
76 | struct GNUNET_SOCIAL_Announcement | ||
77 | { | ||
78 | |||
79 | }; | ||
80 | |||
81 | |||
82 | struct GNUNET_SOCIAL_WatchHandle | ||
83 | { | ||
84 | |||
85 | }; | ||
86 | |||
87 | |||
88 | struct GNUNET_SOCIAL_LookHandle | ||
89 | { | ||
90 | |||
91 | }; | ||
92 | |||
93 | |||
94 | /** | ||
95 | * A talk request. | ||
96 | */ | ||
97 | struct GNUNET_SOCIAL_TalkRequest | ||
98 | { | ||
99 | |||
100 | }; | ||
101 | |||
102 | |||
103 | /** | ||
104 | * A history lesson. | ||
105 | */ | ||
106 | struct GNUNET_SOCIAL_HistoryLesson | ||
107 | { | ||
108 | |||
109 | }; | ||
110 | |||
111 | |||
112 | /** | ||
113 | * Create a try-and-slice instance. | ||
114 | * | ||
115 | * @return A new try-and-slice construct. | ||
116 | */ | ||
117 | struct GNUNET_SOCIAL_Slicer * | ||
118 | GNUNET_SOCIAL_slicer_create (void) | ||
119 | { | ||
120 | return NULL; | ||
121 | } | ||
122 | |||
123 | |||
124 | /** | ||
125 | * Add a method to the try-and-slice instance. | ||
126 | * | ||
127 | * A slicer processes messages and calls methods that match a message. A match | ||
128 | * happens whenever the method name of a message starts with the method_name | ||
129 | * parameter given here. | ||
130 | * | ||
131 | * @param slicer The try-and-slice instance to extend. | ||
132 | * @param method_name Name of the given method, use empty string for default. | ||
133 | * @param method Method to invoke. | ||
134 | * @param method_cls Closure for method. | ||
135 | */ | ||
136 | void | ||
137 | GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer, | ||
138 | const char *method_name, | ||
139 | GNUNET_SOCIAL_Method method, | ||
140 | void *method_cls) | ||
141 | { | ||
142 | |||
143 | } | ||
144 | |||
145 | |||
146 | /** | ||
147 | * Remove a registered method from the try-and-slice instance. | ||
148 | * | ||
149 | * @param slicer The try-and-slice instance. | ||
150 | * @param method_name Name of the method to remove. | ||
151 | * @param method Method handler. | ||
152 | */ | ||
153 | void | ||
154 | GNUNET_SOCIAL_slicer_remove (struct GNUNET_SOCIAL_Slicer *slicer, | ||
155 | const char *method_name, | ||
156 | GNUNET_SOCIAL_Method method) | ||
157 | { | ||
158 | |||
159 | } | ||
160 | |||
161 | |||
162 | /** | ||
163 | * Destroy a given try-and-slice instance. | ||
164 | * | ||
165 | * @param slicer slicer to destroy | ||
166 | */ | ||
167 | void | ||
168 | GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer) | ||
169 | { | ||
170 | |||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * Enter a home where guests (nyms) can be hosted. | ||
176 | * | ||
177 | * A home is created upon first entering, and exists until | ||
178 | * GNUNET_SOCIAL_home_destroy() is called. It can also be left temporarily using | ||
179 | * GNUNET_SOCIAL_home_leave(). | ||
180 | * | ||
181 | * @param cfg Configuration to contact the social service. | ||
182 | * @param home_keyfile File with the private-public key pair of the home, | ||
183 | * created if the file does not exist; pass NULL for ephemeral homes. | ||
184 | * @param policy Policy specifying entry and history restrictions of the home. | ||
185 | * @param ego Owner of the home (host). | ||
186 | * @param slicer Slicer to handle guests talking. | ||
187 | * @param listener_cb Function to handle new nyms that want to enter. | ||
188 | * @param farewell_cb Function to handle departing nyms. | ||
189 | * @param cls Closure for @a listener_cb and @a farewell_cb. | ||
190 | * @return Handle for a new home. | ||
191 | */ | ||
192 | struct GNUNET_SOCIAL_Home * | ||
193 | GNUNET_SOCIAL_home_enter (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
194 | const char *home_keyfile, | ||
195 | enum GNUNET_PSYC_Policy policy, | ||
196 | struct GNUNET_IDENTITY_Ego *ego, | ||
197 | struct GNUNET_SOCIAL_Slicer *slicer, | ||
198 | GNUNET_SOCIAL_AnswerDoorCallback listener_cb, | ||
199 | GNUNET_SOCIAL_FarewellCallback farewell_cb, | ||
200 | void *cls) | ||
201 | { | ||
202 | return NULL; | ||
203 | } | ||
204 | |||
205 | |||
206 | /** | ||
207 | * Admit @a nym to the @a home. | ||
208 | * | ||
209 | * The @a nym reference will remain valid until either the home is destroyed or | ||
210 | * @a nym leaves. | ||
211 | * | ||
212 | * @param home Home to allow @a nym to enter. | ||
213 | * @param nym Handle for the entity that wants to enter. | ||
214 | */ | ||
215 | void | ||
216 | GNUNET_SOCIAL_home_admit (struct GNUNET_SOCIAL_Home *home, | ||
217 | struct GNUNET_SOCIAL_Nym *nym) | ||
218 | { | ||
219 | |||
220 | } | ||
221 | |||
222 | |||
223 | /** | ||
224 | * Throw @a nym out of the @a home. | ||
225 | * | ||
226 | * The @a nym reference will remain valid until the | ||
227 | * #GNUNET_SOCIAL_FarewellCallback is invoked, | ||
228 | * which should be very soon after this call. | ||
229 | * | ||
230 | * @param home Home to eject @a nym from. | ||
231 | * @param nym Handle for the entity to be ejected. | ||
232 | */ | ||
233 | void | ||
234 | GNUNET_SOCIAL_home_eject (struct GNUNET_SOCIAL_Home *home, | ||
235 | struct GNUNET_SOCIAL_Nym *nym) | ||
236 | { | ||
237 | |||
238 | } | ||
239 | |||
240 | |||
241 | /** | ||
242 | * Refuse @a nym entry into the @a home. | ||
243 | * | ||
244 | * @param home Home to disallow @a nym to enter. | ||
245 | * @param nym Handle for the entity that wanted to enter. | ||
246 | * @param method_name Method name for the rejection message. | ||
247 | * @param env Environment containing variables for the message, or NULL. | ||
248 | * @param data Data for the rejection message to send back. | ||
249 | * @param data_size Number of bytes in @a data for method. | ||
250 | */ | ||
251 | void | ||
252 | GNUNET_SOCIAL_home_reject_entry (struct GNUNET_SOCIAL_Home *home, | ||
253 | struct GNUNET_SOCIAL_Nym *nym, | ||
254 | const char *method_name, | ||
255 | const struct GNUNET_ENV_Environment *env, | ||
256 | const void *data, | ||
257 | size_t data_size) | ||
258 | { | ||
259 | |||
260 | } | ||
261 | |||
262 | |||
263 | /** | ||
264 | * Get the public key of a nym. | ||
265 | * | ||
266 | * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name(). | ||
267 | * | ||
268 | * @param nym Pseudonym to map to a cryptographic identifier. | ||
269 | * @param[out] nym_key Set to the public key of the nym. | ||
270 | */ | ||
271 | void | ||
272 | GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym, | ||
273 | struct GNUNET_CRYPTO_EddsaPublicKey *nym_key) | ||
274 | { | ||
275 | |||
276 | } | ||
277 | |||
278 | |||
279 | /** | ||
280 | * Obtain the private-public key pair of the home. | ||
281 | * | ||
282 | * @param home Home to get the key of. | ||
283 | * @param[out] home_key Set to the private-public key pair of the home. The public part is suitable for storing in GNS within a "PLACE" record, along with peer IDs to join at. | ||
284 | */ | ||
285 | void | ||
286 | GNUNET_SOCIAL_home_get_key (struct GNUNET_SOCIAL_Home *home, | ||
287 | struct GNUNET_CRYPTO_EddsaPrivateKey *home_key) | ||
288 | { | ||
289 | |||
290 | } | ||
291 | |||
292 | |||
293 | /** | ||
294 | * Advertise @a home under @a name in the GNS zone of the @e ego. | ||
295 | * | ||
296 | * @param home The home to advertise. | ||
297 | * @param name The name for the PLACE record to put in the zone. | ||
298 | * @param peer_count Number of elements in the @a peers array. | ||
299 | * @param peers List of peers in the PLACE record that can be used to send join | ||
300 | * requests to. | ||
301 | * @param expiration_time Expiration time of the record, use 0 to remove the record. | ||
302 | * @param password Password used to encrypt the record. | ||
303 | */ | ||
304 | void | ||
305 | GNUNET_SOCIAL_home_advertise (struct GNUNET_SOCIAL_Home *home, | ||
306 | const char *name, | ||
307 | size_t peer_count, | ||
308 | const struct GNUNET_PeerIdentity *peers, | ||
309 | struct GNUNET_TIME_Relative expiration_time, | ||
310 | const char *password) | ||
311 | { | ||
312 | |||
313 | } | ||
314 | |||
315 | |||
316 | /** | ||
317 | * Send a message to all nyms that are present in the home. | ||
318 | * | ||
319 | * This function is restricted to the home owner. Nyms can only send requests | ||
320 | * to the home owner who can decide to relay it to other guests. | ||
321 | * | ||
322 | * @param home Home to address the announcement to. | ||
323 | * @param method_name Method to use for the announcement. | ||
324 | * @param env Environment containing variables for the message and operations on | ||
325 | * objects of the home, or NULL. | ||
326 | * @param notify Function to call to get the payload of the announcement. | ||
327 | * @param notify_cls Closure for @a notify. | ||
328 | * @param flags Flags for this announcement. | ||
329 | * @return NULL on error (announcement already in progress?). | ||
330 | */ | ||
331 | struct GNUNET_SOCIAL_Announcement * | ||
332 | GNUNET_SOCIAL_home_announce (struct GNUNET_SOCIAL_Home *home, | ||
333 | const char *method_name, | ||
334 | const struct GNUNET_ENV_Environment *env, | ||
335 | GNUNET_CONNECTION_TransmitReadyNotify notify, | ||
336 | void *notify_cls, | ||
337 | enum GNUNET_SOCIAL_AnnounceFlags flags) | ||
338 | { | ||
339 | return NULL; | ||
340 | } | ||
341 | |||
342 | |||
343 | /** | ||
344 | * Cancel announcement. | ||
345 | * | ||
346 | * @param a The announcement to cancel. | ||
347 | */ | ||
348 | void | ||
349 | GNUNET_SOCIAL_home_announce_cancel (struct GNUNET_SOCIAL_Announcement *a) | ||
350 | { | ||
351 | |||
352 | } | ||
353 | |||
354 | |||
355 | /** | ||
356 | * Convert our home to a place so we can access it via the place API. | ||
357 | * | ||
358 | * @param home Handle for the home. | ||
359 | * @return Place handle for the same home, valid as long as @a home is valid; | ||
360 | * do NOT try to GNUNET_SOCIAL_place_leave() this place, it's your home! | ||
361 | */ | ||
362 | struct GNUNET_SOCIAL_Place * | ||
363 | GNUNET_SOCIAL_home_get_place (struct GNUNET_SOCIAL_Home *home) | ||
364 | { | ||
365 | return NULL; | ||
366 | } | ||
367 | |||
368 | |||
369 | /** | ||
370 | * Leave a home. | ||
371 | |||
372 | * Invalidates home handle. | ||
373 | * Guests will be disconnected until the home is restarted. | ||
374 | * | ||
375 | * @param home Home to leave. | ||
376 | * @param keep_active Keep home active after last application disconnected. | ||
377 | */ | ||
378 | void | ||
379 | GNUNET_SOCIAL_home_leave (struct GNUNET_SOCIAL_Home *home, int keep_active) | ||
380 | { | ||
381 | |||
382 | } | ||
383 | |||
384 | /** | ||
385 | * Request entry to a place (home hosted by someone else). | ||
386 | * | ||
387 | * @param cfg Configuration to contact the social service. | ||
388 | * @param ego Owner of the home (host). | ||
389 | * @param address GNS name of the place to enter. Either in the form of | ||
390 | * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to | ||
391 | * the 'PLACE' record of the empty label ("+") in the GNS zone with the | ||
392 | * nym's public key 'NYMPUBKEY', and can be used to request entry to a | ||
393 | * pseudonym's place directly. | ||
394 | * @param method_name Method name for the message. | ||
395 | * @param env Environment containing variables for the message, or NULL. | ||
396 | * @param data Payload for the message to give to the enter callback. | ||
397 | * @param data_size Number of bytes in @a data. | ||
398 | * @param slicer Slicer to use for processing incoming requests from guests. | ||
399 | * @return NULL on errors, otherwise handle to the place. | ||
400 | */ | ||
401 | struct GNUNET_SOCIAL_Place * | ||
402 | GNUNET_SOCIAL_place_enter (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
403 | struct GNUNET_IDENTITY_Ego *ego, | ||
404 | char *address, | ||
405 | const char *method_name, | ||
406 | const struct GNUNET_ENV_Environment *env, | ||
407 | const void *data, | ||
408 | size_t data_size, | ||
409 | struct GNUNET_SOCIAL_Slicer *slicer) | ||
410 | { | ||
411 | return NULL; | ||
412 | } | ||
413 | |||
414 | /** | ||
415 | * Request entry to a place (home hosted by someone else). | ||
416 | * | ||
417 | * @param cfg Configuration to contact the social service. | ||
418 | * @param ego Owner of the home (host). | ||
419 | * @param crypto_address Public key of the place to enter. | ||
420 | * @param origin Peer identity of the origin of the underlying multicast group. | ||
421 | * @param relay_count Number of elements in the @a relays array. | ||
422 | * @param relays Relays for the underlying multicast group. | ||
423 | * @param method_name Method name for the message. | ||
424 | * @param env Environment containing variables for the message, or NULL. | ||
425 | * @param data Payload for the message to give to the enter callback. | ||
426 | * @param data_size Number of bytes in @a data. | ||
427 | * @param slicer Slicer to use for processing incoming requests from guests. | ||
428 | * @return NULL on errors, otherwise handle to the place. | ||
429 | */ | ||
430 | struct GNUNET_SOCIAL_Place * | ||
431 | GNUNET_SOCIAL_place_enter2 (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
432 | struct GNUNET_IDENTITY_Ego *ego, | ||
433 | struct GNUNET_CRYPTO_EddsaPublicKey *crypto_address, | ||
434 | struct GNUNET_PeerIdentity *origin, | ||
435 | size_t relay_count, | ||
436 | struct GNUNET_PeerIdentity *relays, | ||
437 | const char *method_name, | ||
438 | const struct GNUNET_ENV_Environment *env, | ||
439 | const void *data, | ||
440 | size_t data_size, | ||
441 | struct GNUNET_SOCIAL_Slicer *slicer) | ||
442 | { | ||
443 | return NULL; | ||
444 | } | ||
445 | |||
446 | |||
447 | /** | ||
448 | * Watch a place for changed objects. | ||
449 | * | ||
450 | * @param place Place to watch. | ||
451 | * @param object_filter Object prefix to match. | ||
452 | * @param state_cb Function to call when an object/state changes. | ||
453 | * @param state_cb_cls Closure for callback. | ||
454 | * | ||
455 | * @return Handle that can be used to cancel watching. | ||
456 | */ | ||
457 | struct GNUNET_SOCIAL_WatchHandle * | ||
458 | GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place, | ||
459 | const char *object_filter, | ||
460 | GNUNET_PSYC_StateCallback state_cb, | ||
461 | void *state_cb_cls) | ||
462 | { | ||
463 | return NULL; | ||
464 | } | ||
465 | |||
466 | |||
467 | /** | ||
468 | * Cancel watching a place for changed objects. | ||
469 | * | ||
470 | * @param wh Watch handle to cancel. | ||
471 | */ | ||
472 | void | ||
473 | GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh) | ||
474 | { | ||
475 | |||
476 | } | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Look at objects in the place with a matching name prefix. | ||
481 | * | ||
482 | * @param place The place to look its objects at. | ||
483 | * @param name_prefix Look at objects with names beginning with this value. | ||
484 | * @param state_cb Function to call for each object found. | ||
485 | * @param state_cb_cls Closure for callback function. | ||
486 | * | ||
487 | * @return Handle that can be used to stop looking at objects. | ||
488 | */ | ||
489 | struct GNUNET_SOCIAL_LookHandle * | ||
490 | GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place, | ||
491 | const char *name_prefix, | ||
492 | GNUNET_PSYC_StateCallback state_cb, | ||
493 | void *state_cb_cls) | ||
494 | { | ||
495 | return NULL; | ||
496 | } | ||
497 | |||
498 | |||
499 | /** | ||
500 | * Stop looking at objects. | ||
501 | * | ||
502 | * @param lh Look handle to stop. | ||
503 | */ | ||
504 | void | ||
505 | GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh) | ||
506 | { | ||
507 | |||
508 | } | ||
509 | |||
510 | |||
511 | |||
512 | /** | ||
513 | * Look at a particular object in the place. | ||
514 | * | ||
515 | * The best matching object is returned (its name might be less specific than | ||
516 | * what was requested). | ||
517 | * | ||
518 | * @param place The place to look the object at. | ||
519 | * @param full_name Full name of the object. | ||
520 | * @param value_size Set to the size of the returned value. | ||
521 | * @return NULL if there is no such object at this place. | ||
522 | */ | ||
523 | const void * | ||
524 | GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place, | ||
525 | const char *full_name, | ||
526 | size_t *value_size) | ||
527 | { | ||
528 | return NULL; | ||
529 | } | ||
530 | |||
531 | |||
532 | /** | ||
533 | * Talk to the host of the place. | ||
534 | * | ||
535 | * @param place Place where we want to talk to the host. | ||
536 | * @param method_name Method to invoke on the host. | ||
537 | * @param env Environment containing variables for the message, or NULL. | ||
538 | * @param notify Function to use to get the payload for the method. | ||
539 | * @param notify_cls Closure for @a notify. | ||
540 | * @param flags Flags for the message being sent. | ||
541 | * @return NULL if we are already trying to talk to the host, | ||
542 | * otherwise handle to cancel the request. | ||
543 | */ | ||
544 | struct GNUNET_SOCIAL_TalkRequest * | ||
545 | GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place, | ||
546 | const char *method_name, | ||
547 | const struct GNUNET_ENV_Environment *env, | ||
548 | GNUNET_CONNECTION_TransmitReadyNotify notify, | ||
549 | void *notify_cls, | ||
550 | enum GNUNET_SOCIAL_TalkFlags flags) | ||
551 | { | ||
552 | return NULL; | ||
553 | } | ||
554 | |||
555 | |||
556 | /** | ||
557 | * Cancel talking to the host of the place. | ||
558 | * | ||
559 | * @param tr Talk request to cancel. | ||
560 | */ | ||
561 | void | ||
562 | GNUNET_SOCIAL_place_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr) | ||
563 | { | ||
564 | |||
565 | } | ||
566 | |||
567 | |||
568 | /** | ||
569 | * Learn about the history of a place. | ||
570 | * | ||
571 | * Sends messages through the slicer function of the place where | ||
572 | * start_message_id <= message_id <= end_message_id. | ||
573 | * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set. | ||
574 | * | ||
575 | * To get the latest message, use 0 for both the start and end message ID. | ||
576 | * | ||
577 | * @param place Place we want to learn more about. | ||
578 | * @param start_message_id First historic message we are interested in. | ||
579 | * @param end_message_id Last historic message we are interested in (inclusive). | ||
580 | * @param slicer Slicer to use to process history. Can be the same as the | ||
581 | * slicer of the place, as the HISTORIC flag allows distinguishing | ||
582 | * old messages from fresh ones. | ||
583 | * @param finish_cb Function called after the last message in the history lesson | ||
584 | * is passed through the @a slicer. NULL if not needed. | ||
585 | * @param finish_cb_cls Closure for @a finish_cb. | ||
586 | * @return Handle to abort history lesson, never NULL (multiple lessons | ||
587 | * at the same time are allowed). | ||
588 | */ | ||
589 | struct GNUNET_SOCIAL_HistoryLesson * | ||
590 | GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place, | ||
591 | uint64_t start_message_id, | ||
592 | uint64_t end_message_id, | ||
593 | const struct GNUNET_SOCIAL_Slicer *slicer, | ||
594 | void (*finish_cb)(void *), | ||
595 | void *finish_cb_cls) | ||
596 | { | ||
597 | return NULL; | ||
598 | } | ||
599 | |||
600 | |||
601 | /** | ||
602 | * Stop processing messages from the history lesson. | ||
603 | * | ||
604 | * Must not be called after the finish callback of the history lesson is called. | ||
605 | * | ||
606 | * @param hist History lesson to cancel. | ||
607 | */ | ||
608 | void | ||
609 | GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist) | ||
610 | { | ||
611 | |||
612 | } | ||
613 | |||
614 | |||
615 | /** | ||
616 | * Leave a place permanently. | ||
617 | * | ||
618 | * Notifies the owner of the place about leaving, and destroys the place handle. | ||
619 | * | ||
620 | * @param place Place to leave permanently. | ||
621 | * @param keep_active Keep place active after last application disconnected. | ||
622 | */ | ||
623 | void | ||
624 | GNUNET_SOCIAL_place_leave (struct GNUNET_SOCIAL_Place *place, int keep_active) | ||
625 | { | ||
626 | |||
627 | } | ||
diff --git a/src/social/test_social.c b/src/social/test_social.c new file mode 100644 index 000000000..8851ba0df --- /dev/null +++ b/src/social/test_social.c | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet | ||
3 | * (C) 2013 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 social/test_social.c | ||
23 | * @brief Test for the SOCIAL service. | ||
24 | * @author Gabor X Toth | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #include <inttypes.h> | ||
29 | |||
30 | #include "platform.h" | ||
31 | #include "gnunet_crypto_lib.h" | ||
32 | #include "gnunet_common.h" | ||
33 | #include "gnunet_util_lib.h" | ||
34 | #include "gnunet_testing_lib.h" | ||
35 | #include "gnunet_env_lib.h" | ||
36 | #include "gnunet_social_service.h" | ||
37 | |||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
39 | |||
40 | #define DEBUG_SERVICE 0 | ||
41 | |||
42 | /** | ||
43 | * Return value from 'main'. | ||
44 | */ | ||
45 | static int res; | ||
46 | |||
47 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
48 | |||
49 | /** | ||
50 | * Handle for task for timeout termination. | ||
51 | */ | ||
52 | static GNUNET_SCHEDULER_TaskIdentifier end_badly_task; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Clean up all resources used. | ||
57 | */ | ||
58 | static void | ||
59 | cleanup () | ||
60 | { | ||
61 | |||
62 | } | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Terminate the test case (failure). | ||
67 | * | ||
68 | * @param cls NULL | ||
69 | * @param tc scheduler context | ||
70 | */ | ||
71 | static void | ||
72 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
73 | { | ||
74 | res = 1; | ||
75 | cleanup (); | ||
76 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n"); | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Terminate the test case (success). | ||
82 | * | ||
83 | * @param cls NULL | ||
84 | * @param tc scheduler context | ||
85 | */ | ||
86 | static void | ||
87 | end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
88 | { | ||
89 | res = 0; | ||
90 | cleanup (); | ||
91 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n"); | ||
92 | } | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Finish the test case (successfully). | ||
97 | */ | ||
98 | static void | ||
99 | end () | ||
100 | { | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n"); | ||
102 | |||
103 | if (end_badly_task != GNUNET_SCHEDULER_NO_TASK) | ||
104 | { | ||
105 | GNUNET_SCHEDULER_cancel (end_badly_task); | ||
106 | end_badly_task = GNUNET_SCHEDULER_NO_TASK; | ||
107 | } | ||
108 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | ||
109 | &end_normally, NULL); | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Main function of the test, run from scheduler. | ||
115 | * | ||
116 | * @param cls NULL | ||
117 | * @param cfg configuration we use (also to connect to SOCIAL service) | ||
118 | * @param peer handle to access more of the peer (not used) | ||
119 | */ | ||
120 | static void | ||
121 | #if DEBUG_SERVICE | ||
122 | run (void *cls, char *const *args, const char *cfgfile, | ||
123 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
124 | #else | ||
125 | run (void *cls, | ||
126 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
127 | struct GNUNET_TESTING_Peer *peer) | ||
128 | #endif | ||
129 | { | ||
130 | cfg = c; | ||
131 | end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
132 | |||
133 | /* FIXME: add tests */ | ||
134 | |||
135 | end (); | ||
136 | } | ||
137 | |||
138 | |||
139 | int | ||
140 | main (int argc, char *argv[]) | ||
141 | { | ||
142 | res = 1; | ||
143 | #if DEBUG_SERVICE | ||
144 | const struct GNUNET_GETOPT_CommandLineOption opts[] = { | ||
145 | GNUNET_GETOPT_OPTION_END | ||
146 | }; | ||
147 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social", | ||
148 | "test-social [options]", | ||
149 | opts, &run, NULL)) | ||
150 | return 1; | ||
151 | #else | ||
152 | if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL)) | ||
153 | return 1; | ||
154 | #endif | ||
155 | return res; | ||
156 | } | ||
157 | |||
158 | /* end of test_social.c */ | ||
diff --git a/src/social/test_social.conf b/src/social/test_social.conf new file mode 100644 index 000000000..58c731168 --- /dev/null +++ b/src/social/test_social.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | [arm] | ||
2 | DEFAULTSERVICES = multicast psycstore psyc social | ||