diff options
Diffstat (limited to 'src/include')
37 files changed, 8327 insertions, 0 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am new file mode 100644 index 000000000..8c49690e7 --- /dev/null +++ b/src/include/Makefile.am | |||
@@ -0,0 +1,42 @@ | |||
1 | SUBDIRS = . | ||
2 | |||
3 | EXTRA_DIST = \ | ||
4 | gettext.h \ | ||
5 | platform.h \ | ||
6 | plibc.h \ | ||
7 | winproc.h | ||
8 | |||
9 | gnunetincludedir = $(includedir)/GNUnet | ||
10 | |||
11 | nodist_gnunetinclude_HEADERS = \ | ||
12 | gnunet_directories.h | ||
13 | |||
14 | gnunetinclude_HEADERS = \ | ||
15 | gnunet_arm_service.h \ | ||
16 | gnunet_client_lib.h \ | ||
17 | gnunet_common.h \ | ||
18 | gnunet_configuration_lib.h \ | ||
19 | gnunet_container_lib.h \ | ||
20 | gnunet_core_service.h \ | ||
21 | gnunet_crypto_lib.h \ | ||
22 | gnunet_disk_lib.h \ | ||
23 | gnunet_fragmentation_lib.h \ | ||
24 | gnunet_getopt_lib.h \ | ||
25 | gnunet_hello_lib.h \ | ||
26 | gnunet_network_lib.h \ | ||
27 | gnunet_peerinfo_service.h \ | ||
28 | gnunet_program_lib.h \ | ||
29 | gnunet_protocols.h \ | ||
30 | gnunet_pseudonym_lib.h \ | ||
31 | gnunet_resolver_service.h \ | ||
32 | gnunet_scheduler_lib.h \ | ||
33 | gnunet_server_lib.h \ | ||
34 | gnunet_service_lib.h \ | ||
35 | gnunet_signal_lib.h \ | ||
36 | gnunet_signatures.h \ | ||
37 | gnunet_statistics_service.h \ | ||
38 | gnunet_strings_lib.h \ | ||
39 | gnunet_time_lib.h \ | ||
40 | gnunet_transport_service.h \ | ||
41 | gnunet_upnp_service.h \ | ||
42 | gnunet_util_lib.h | ||
diff --git a/src/include/gettext.h b/src/include/gettext.h new file mode 100644 index 000000000..c89197cfc --- /dev/null +++ b/src/include/gettext.h | |||
@@ -0,0 +1,71 @@ | |||
1 | /* Convenience header for conditional use of GNU <libintl.h>. | ||
2 | Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published | ||
6 | by the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public | ||
15 | License along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | ||
17 | USA. */ | ||
18 | |||
19 | #ifndef _LIBGETTEXT_H | ||
20 | #define _LIBGETTEXT_H 1 | ||
21 | |||
22 | /* NLS can be disabled through the configure --disable-nls option. */ | ||
23 | #if ENABLE_NLS | ||
24 | |||
25 | /* Get declarations of GNU message catalog functions. */ | ||
26 | # include <libintl.h> | ||
27 | |||
28 | #else | ||
29 | |||
30 | /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which | ||
31 | chokes if dcgettext is defined as a macro. So include it now, to make | ||
32 | later inclusions of <locale.h> a NOP. We don't include <libintl.h> | ||
33 | as well because people using "gettext.h" will not include <libintl.h>, | ||
34 | and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> | ||
35 | is GNUNET_OK. */ | ||
36 | #if defined(__sun) | ||
37 | # include <locale.h> | ||
38 | #endif | ||
39 | |||
40 | /* Disabled NLS. | ||
41 | The casts to 'const char *' serve the purpose of producing warnings | ||
42 | for invalid uses of the value returned from these functions. | ||
43 | On pre-ANSI systems without 'const', the config.h file is supposed to | ||
44 | contain "#define const". */ | ||
45 | # define gettext(Msgid) ((const char *) (Msgid)) | ||
46 | # define dgettext(Domainname, Msgid) ((const char *) (Msgid)) | ||
47 | # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) | ||
48 | # define ngettext(Msgid1, Msgid2, N) \ | ||
49 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) | ||
50 | # define dngettext(Domainname, Msgid1, Msgid2, N) \ | ||
51 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) | ||
52 | # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ | ||
53 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) | ||
54 | /* slight modification here to avoid warnings: generate GNUNET_NO code, | ||
55 | not even the cast... */ | ||
56 | # define textdomain(Domainname) | ||
57 | # define bindtextdomain(Domainname, Dirname) | ||
58 | # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) | ||
59 | |||
60 | #endif | ||
61 | |||
62 | /* A pseudo function call that serves as a marker for the automated | ||
63 | extraction of messages, but does not call gettext(). The run-time | ||
64 | translation is done at a different place in the code. | ||
65 | The argument, String, should be a literal string. Concatenated strings | ||
66 | and other string expressions won't work. | ||
67 | The macro's expansion is not parenthesized, so that it is suitable as | ||
68 | initializer for static 'char[]' or 'const char[]' variables. */ | ||
69 | #define gettext_noop(String) String | ||
70 | |||
71 | #endif /* _LIBGETTEXT_H */ | ||
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h new file mode 100644 index 000000000..012c27877 --- /dev/null +++ b/src/include/gnunet_arm_service.h | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 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 2, 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 include/gnunet_arm_service.h | ||
23 | * @brief API to access gnunet-arm | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_ARM_SERVICE_H | ||
28 | #define GNUNET_ARM_SERVICE_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_configuration_lib.h" | ||
39 | #include "gnunet_scheduler_lib.h" | ||
40 | #include "gnunet_time_lib.h" | ||
41 | |||
42 | /** | ||
43 | * Version of the arm API. | ||
44 | */ | ||
45 | #define GNUNET_ARM_VERSION 0x00000000 | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Callback function invoked when operation is complete. | ||
50 | * | ||
51 | * @param cls closure | ||
52 | * @param success GNUNET_YES if we think the service is running | ||
53 | * GNUNET_NO if we think the service is stopped | ||
54 | * GNUNET_SYSERR if we think ARM was not running | ||
55 | */ | ||
56 | typedef void (*GNUNET_ARM_Callback) (void *cls, int success); | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Start a service. | ||
61 | * | ||
62 | * @param service_name name of the service | ||
63 | * @param cfg configuration to use (needed to contact ARM; | ||
64 | * the ARM service may internally use a different | ||
65 | * configuration to determine how to start the service). | ||
66 | * @param sched scheduler to use | ||
67 | * @param timeout how long to wait before failing for good | ||
68 | * @param cb callback to invoke when service is ready | ||
69 | * @param cb_cls closure for callback | ||
70 | */ | ||
71 | void | ||
72 | GNUNET_ARM_start_service (const char *service_name, | ||
73 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
74 | struct GNUNET_SCHEDULER_Handle *sched, | ||
75 | struct GNUNET_TIME_Relative timeout, | ||
76 | GNUNET_ARM_Callback cb, void *cb_cls); | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Stop a service. | ||
81 | * | ||
82 | * @param service_name name of the service | ||
83 | * @param cfg configuration to use (needed to contact ARM; | ||
84 | * the ARM service may internally use a different | ||
85 | * configuration to determine how to start the service). | ||
86 | * @param sched scheduler to use | ||
87 | * @param timeout how long to wait before failing for good | ||
88 | * @param cb callback to invoke when service is ready | ||
89 | * @param cb_cls closure for callback | ||
90 | */ | ||
91 | void | ||
92 | GNUNET_ARM_stop_service (const char *service_name, | ||
93 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
94 | struct GNUNET_SCHEDULER_Handle *sched, | ||
95 | struct GNUNET_TIME_Relative timeout, | ||
96 | GNUNET_ARM_Callback cb, void *cb_cls); | ||
97 | |||
98 | |||
99 | |||
100 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
101 | { | ||
102 | #endif | ||
103 | #ifdef __cplusplus | ||
104 | } | ||
105 | #endif | ||
106 | |||
107 | #endif | ||
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h new file mode 100644 index 000000000..6a77aa391 --- /dev/null +++ b/src/include/gnunet_client_lib.h | |||
@@ -0,0 +1,160 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_client_lib.h | ||
23 | * @brief functions related to accessing services | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_CLIENT_LIB_H | ||
28 | #define GNUNET_CLIENT_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_common.h" | ||
39 | #include "gnunet_configuration_lib.h" | ||
40 | #include "gnunet_network_lib.h" | ||
41 | #include "gnunet_scheduler_lib.h" | ||
42 | #include "gnunet_time_lib.h" | ||
43 | |||
44 | /** | ||
45 | * Opaque handle for a connection to a service. | ||
46 | */ | ||
47 | struct GNUNET_CLIENT_Connection; | ||
48 | |||
49 | /** | ||
50 | * Get a connection with a service. | ||
51 | * | ||
52 | * @param sched scheduler to use | ||
53 | * @param service_name name of the service | ||
54 | * @param cfg configuration to use | ||
55 | * @return NULL on error (service unknown to configuration) | ||
56 | */ | ||
57 | struct GNUNET_CLIENT_Connection *GNUNET_CLIENT_connect (struct | ||
58 | GNUNET_SCHEDULER_Handle | ||
59 | *sched, | ||
60 | const char | ||
61 | *service_name, | ||
62 | struct | ||
63 | GNUNET_CONFIGURATION_Handle | ||
64 | *cfg); | ||
65 | |||
66 | /** | ||
67 | * Destroy connection with the service. This will | ||
68 | * automatically cancel any pending "receive" request | ||
69 | * (however, the handler will *NOT* be called, not | ||
70 | * even with a NULL message). | ||
71 | */ | ||
72 | void GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock); | ||
73 | |||
74 | /** | ||
75 | * Type of a function to call when we receive a message | ||
76 | * from the service. | ||
77 | * | ||
78 | * @param cls closure | ||
79 | * @param msg message received, NULL on timeout or fatal error | ||
80 | */ | ||
81 | typedef void (*GNUNET_CLIENT_MessageHandler) (void *cls, | ||
82 | const struct | ||
83 | GNUNET_MessageHeader * msg); | ||
84 | |||
85 | /** | ||
86 | * Read from the service. | ||
87 | * | ||
88 | * @param sched scheduler to use | ||
89 | * @param sock the service | ||
90 | * @param handler function to call with the message | ||
91 | * @param cls closure for handler | ||
92 | * @param timeout how long to wait until timing out | ||
93 | */ | ||
94 | void GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, | ||
95 | GNUNET_CLIENT_MessageHandler handler, | ||
96 | void *cls, struct GNUNET_TIME_Relative timeout); | ||
97 | |||
98 | |||
99 | /** | ||
100 | * Ask the client to call us once the specified number of bytes | ||
101 | * are free in the transmission buffer. May call the notify | ||
102 | * method immediately if enough space is available. | ||
103 | * | ||
104 | * @param client connection to the service | ||
105 | * @param size number of bytes to send | ||
106 | * @param timeout after how long should we give up (and call | ||
107 | * notify with buf NULL and size 0)? | ||
108 | * @param notify function to call | ||
109 | * @param notify_cls closure for notify | ||
110 | * @return NULL if someone else is already waiting to be notified | ||
111 | * non-NULL if the notify callback was queued (can be used to cancel | ||
112 | * using GNUNET_NETWORK_notify_transmit_ready_cancel) | ||
113 | */ | ||
114 | struct GNUNET_NETWORK_TransmitHandle | ||
115 | *GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, | ||
116 | size_t size, | ||
117 | struct GNUNET_TIME_Relative timeout, | ||
118 | GNUNET_NETWORK_TransmitReadyNotify | ||
119 | notify, void *notify_cls); | ||
120 | |||
121 | |||
122 | /** | ||
123 | * Request that the service should shutdown. | ||
124 | * Afterwards, the connection should be disconnected. | ||
125 | * | ||
126 | * @param sched scheduler to use | ||
127 | * @param sock the socket connected to the service | ||
128 | */ | ||
129 | void GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock); | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Wait until the service is running. | ||
134 | * | ||
135 | * @param sched scheduler to use | ||
136 | * @param service name of the service to wait for | ||
137 | * @param cfg configuration to use | ||
138 | * @param timeout how long to wait at most in ms | ||
139 | * @param task task to run if service is running | ||
140 | * (reason will be "PREREQ_DONE" (service running) | ||
141 | * or "TIMEOUT" (service not known to be running)) | ||
142 | * @param task_cls closure for task | ||
143 | */ | ||
144 | void GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched, | ||
145 | const char *service, | ||
146 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
147 | struct GNUNET_TIME_Relative timeout, | ||
148 | GNUNET_SCHEDULER_Task task, void *task_cls); | ||
149 | |||
150 | |||
151 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
152 | { | ||
153 | #endif | ||
154 | #ifdef __cplusplus | ||
155 | } | ||
156 | #endif | ||
157 | |||
158 | /* ifndef GNUNET_CLIENT_LIB_H */ | ||
159 | #endif | ||
160 | /* end of gnunet_client_lib.h */ | ||
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h new file mode 100644 index 000000000..61b572eb8 --- /dev/null +++ b/src/include/gnunet_common.h | |||
@@ -0,0 +1,469 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2006 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 2, 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 include/gnunet_common.h | ||
23 | * @brief commonly used definitions; globals in this file | ||
24 | * are exempt from the rule that the module name ("common") | ||
25 | * must be part of the symbol name. | ||
26 | * | ||
27 | * @author Christian Grothoff | ||
28 | * @author Nils Durner | ||
29 | */ | ||
30 | #ifndef GNUNET_COMMON_H | ||
31 | #define GNUNET_COMMON_H | ||
32 | |||
33 | /** | ||
34 | * Version of the API (for entire gnunetutil.so library). | ||
35 | */ | ||
36 | #define GNUNET_UTIL_VERSION 0x00000000 | ||
37 | |||
38 | /** | ||
39 | * Name used for "services" that are actually command-line | ||
40 | * programs invoked by the end user. | ||
41 | */ | ||
42 | #define GNUNET_CLIENT_SERVICE_NAME "client" | ||
43 | |||
44 | /** | ||
45 | * Named constants for return values. The following | ||
46 | * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)") | ||
47 | * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != GNUNET_SYSERR" | ||
48 | * and finally "GNUNET_YES != GNUNET_NO". | ||
49 | */ | ||
50 | #define GNUNET_OK 1 | ||
51 | #define GNUNET_SYSERR -1 | ||
52 | #define GNUNET_YES 1 | ||
53 | #define GNUNET_NO 0 | ||
54 | |||
55 | #define GNUNET_MIN(a,b) (((a) < (b)) ? (a) : (b)) | ||
56 | |||
57 | #define GNUNET_MAX(a,b) (((a) > (b)) ? (a) : (b)) | ||
58 | |||
59 | /** | ||
60 | * gcc-ism to get packed structs. | ||
61 | */ | ||
62 | #define GNUNET_PACKED __attribute__((packed)) | ||
63 | |||
64 | |||
65 | /* ************************ super-general types *********************** */ | ||
66 | |||
67 | /** | ||
68 | * Header for all communications. | ||
69 | */ | ||
70 | struct GNUNET_MessageHeader | ||
71 | { | ||
72 | |||
73 | /** | ||
74 | * The length of the struct (in bytes, including the length field itself) | ||
75 | */ | ||
76 | uint16_t size GNUNET_PACKED; | ||
77 | |||
78 | /** | ||
79 | * The type of the message (XX_CS_PROTO_XXXX) | ||
80 | */ | ||
81 | uint16_t type GNUNET_PACKED; | ||
82 | |||
83 | }; | ||
84 | |||
85 | |||
86 | /** | ||
87 | * @brief 512-bit hashcode | ||
88 | */ | ||
89 | typedef struct | ||
90 | { | ||
91 | uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */ | ||
92 | } | ||
93 | GNUNET_HashCode; | ||
94 | |||
95 | |||
96 | /** | ||
97 | * The identity of the host (basically the SHA-512 hashcode of | ||
98 | * it's public key). | ||
99 | */ | ||
100 | struct GNUNET_PeerIdentity | ||
101 | { | ||
102 | GNUNET_HashCode hashPubKey GNUNET_PACKED; | ||
103 | }; | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Function called with a filename. | ||
108 | * | ||
109 | * @param filename complete filename (absolute path) | ||
110 | * @param cls closure | ||
111 | * @return GNUNET_OK to continue to iterate, | ||
112 | * GNUNET_SYSERR to abort iteration with error! | ||
113 | */ | ||
114 | typedef int (*GNUNET_FileNameCallback) (void *cls, const char *filename); | ||
115 | |||
116 | |||
117 | /* ****************************** logging ***************************** */ | ||
118 | |||
119 | /** | ||
120 | * Types of errors. | ||
121 | */ | ||
122 | enum GNUNET_ErrorType | ||
123 | { | ||
124 | GNUNET_ERROR_TYPE_ERROR = 1, | ||
125 | GNUNET_ERROR_TYPE_WARNING = 2, | ||
126 | GNUNET_ERROR_TYPE_INFO = 4, | ||
127 | GNUNET_ERROR_TYPE_DEBUG = 8, | ||
128 | GNUNET_ERROR_TYPE_INVALID = 16, | ||
129 | GNUNET_ERROR_TYPE_BULK = 32 | ||
130 | }; | ||
131 | |||
132 | /** | ||
133 | * User-defined handler for log messages. | ||
134 | * | ||
135 | * @param cls closure | ||
136 | * @param kind severeity | ||
137 | * @param component what component is issuing the message? | ||
138 | * @param date when was the message logged? | ||
139 | * @param message what is the message | ||
140 | */ | ||
141 | typedef void (*GNUNET_Logger) (void *cls, | ||
142 | enum GNUNET_ErrorType kind, | ||
143 | const char *component, | ||
144 | const char *date, const char *message); | ||
145 | |||
146 | /** | ||
147 | * Main log function. | ||
148 | * | ||
149 | * @param kind how serious is the error? | ||
150 | * @param message what is the message (format string) | ||
151 | * @param ... arguments for format string | ||
152 | */ | ||
153 | void GNUNET_log (enum GNUNET_ErrorType kind, const char *message, ...); | ||
154 | |||
155 | |||
156 | |||
157 | /** | ||
158 | * Log function that specifies an alternative component. | ||
159 | * This function should be used by plugins. | ||
160 | * | ||
161 | * @param kind how serious is the error? | ||
162 | * @param comp component responsible for generating the message | ||
163 | * @param message what is the message (format string) | ||
164 | * @param ... arguments for format string | ||
165 | */ | ||
166 | void | ||
167 | GNUNET_log_from (enum GNUNET_ErrorType kind, | ||
168 | const char *comp, const char *message, ...); | ||
169 | |||
170 | |||
171 | /** | ||
172 | * Ignore the next n calls to the log function. | ||
173 | * | ||
174 | * @param n number of log calls to ignore, use 0 to | ||
175 | * assert that the log skip counter is currently zero. | ||
176 | */ | ||
177 | void GNUNET_log_skip (unsigned int n); | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Setup logging. | ||
182 | * | ||
183 | * @param component default component to use | ||
184 | * @param loglevel what types of messages should be logged | ||
185 | * @param logfile change logging to logfile (use NULL to keep stderr) | ||
186 | * @return GNUNET_OK on success, GNUNET_SYSERR if logfile could not be opened | ||
187 | */ | ||
188 | int | ||
189 | GNUNET_log_setup (const char *component, | ||
190 | const char *loglevel, const char *logfile); | ||
191 | |||
192 | /** | ||
193 | * Add a custom logger. | ||
194 | * | ||
195 | * @param logger log function | ||
196 | * @param logger_cls closure for logger | ||
197 | */ | ||
198 | void GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); | ||
199 | |||
200 | /** | ||
201 | * Remove a custom logger. | ||
202 | * | ||
203 | * @param logger log function | ||
204 | * @param logger_cls closure for logger | ||
205 | */ | ||
206 | void GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Convert a peer identity to a string (for printing debug messages). | ||
211 | * This is one of the very few calls in the entire API that is | ||
212 | * NOT reentrant! | ||
213 | * | ||
214 | * @param pid the peer identity | ||
215 | * @return string form of the pid; will be overwritten by next | ||
216 | * call to GNUNET_i2s. | ||
217 | */ | ||
218 | const char *GNUNET_i2s (const struct GNUNET_PeerIdentity *pid); | ||
219 | |||
220 | /** | ||
221 | * Convert error type to string. | ||
222 | * | ||
223 | * @param kind type to convert | ||
224 | * @return string corresponding to the type | ||
225 | */ | ||
226 | const char *GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | ||
227 | |||
228 | /** | ||
229 | * Use this for fatal errors that cannot be handled | ||
230 | */ | ||
231 | #define GNUNET_assert(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); abort(); } } while(0) | ||
232 | |||
233 | /** | ||
234 | * Use this for fatal errors that cannot be handled | ||
235 | */ | ||
236 | #define GNUNET_assert_at(cond, f, l) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), f, l); abort(); } } while(0) | ||
237 | |||
238 | /** | ||
239 | * Use this for internal assertion violations that are | ||
240 | * not fatal (can be handled) but should not occur. | ||
241 | */ | ||
242 | #define GNUNET_break(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); } } while(0) | ||
243 | |||
244 | /** | ||
245 | * Use this for assertion violations caused by other | ||
246 | * peers (i.e. protocol violations). We do not want to | ||
247 | * confuse end-users (say, some other peer runs an | ||
248 | * older, broken or incompatible GNUnet version), but | ||
249 | * we still want to see these problems during | ||
250 | * development and testing. "OP == other peer". | ||
251 | */ | ||
252 | #define GNUNET_break_op(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("External protocol violation detected at %s:%d.\n"), __FILE__, __LINE__); } } while(0) | ||
253 | |||
254 | /** | ||
255 | * Log an error message at log-level 'level' that indicates | ||
256 | * a failure of the command 'cmd' with the message given | ||
257 | * by strerror(errno). | ||
258 | */ | ||
259 | #define GNUNET_log_strerror(level, cmd) do { GNUNET_log(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, STRERROR(errno)); } while(0) | ||
260 | |||
261 | /** | ||
262 | * Log an error message at log-level 'level' that indicates | ||
263 | * a failure of the command 'cmd' with the message given | ||
264 | * by strerror(errno). | ||
265 | */ | ||
266 | #define GNUNET_log_strerror_file(level, cmd, filename) do { GNUNET_log(level, _("`%s' failed on file `%s' at %s:%d with error: %s\n"), cmd, filename,__FILE__, __LINE__, STRERROR(errno)); } while(0) | ||
267 | |||
268 | /* ************************* endianess conversion ****************** */ | ||
269 | |||
270 | /** | ||
271 | * Convert a long-long to host-byte-order. | ||
272 | * @param n the value in network byte order | ||
273 | * @return the same value in host byte order | ||
274 | */ | ||
275 | unsigned long long GNUNET_ntohll (unsigned long long n); | ||
276 | |||
277 | /** | ||
278 | * Convert a long long to network-byte-order. | ||
279 | * @param n the value in host byte order | ||
280 | * @return the same value in network byte order | ||
281 | */ | ||
282 | unsigned long long GNUNET_htonll (unsigned long long n); | ||
283 | |||
284 | |||
285 | /* ************************* allocation functions ****************** */ | ||
286 | |||
287 | /** | ||
288 | * Maximum allocation with GNUNET_malloc macro. | ||
289 | */ | ||
290 | #define GNUNET_MAX_GNUNET_MALLOC_CHECKED (1024 * 1024 * 40) | ||
291 | |||
292 | /** | ||
293 | * Wrapper around malloc. Allocates size bytes of memory. | ||
294 | * The memory will be zero'ed out. | ||
295 | * | ||
296 | * @param size the number of bytes to allocate, must be | ||
297 | * smaller than 40 MB. | ||
298 | * @return pointer to size bytes of memory | ||
299 | */ | ||
300 | #define GNUNET_malloc(size) GNUNET_xmalloc_(size, __FILE__, __LINE__) | ||
301 | |||
302 | /** | ||
303 | * Wrapper around malloc. Allocates size bytes of memory. | ||
304 | * The memory will be zero'ed out. | ||
305 | * | ||
306 | * @param size the number of bytes to allocate | ||
307 | * @return pointer to size bytes of memory | ||
308 | */ | ||
309 | #define GNUNET_malloc_large(size) GNUNET_xmalloc_unchecked_(size, __FILE__, __LINE__) | ||
310 | |||
311 | /** | ||
312 | * Wrapper around realloc. Rellocates size bytes of memory. | ||
313 | * | ||
314 | * @param ptr the pointer to reallocate | ||
315 | * @param size the number of bytes to reallocate | ||
316 | * @return pointer to size bytes of memory | ||
317 | */ | ||
318 | #define GNUNET_realloc(ptr, size) GNUNET_xrealloc_(ptr, size, __FILE__, __LINE__) | ||
319 | |||
320 | /** | ||
321 | * Wrapper around free. Frees the memory referred to by ptr. | ||
322 | * Note that is is generally better to free memory that was | ||
323 | * allocated with GNUNET_array_grow using GNUNET_array_grow(mem, size, 0) instead of GNUNET_free. | ||
324 | * | ||
325 | * @param ptr location where to free the memory. ptr must have | ||
326 | * been returned by GNUNET_strdup, GNUNET_malloc or GNUNET_array_grow earlier. | ||
327 | */ | ||
328 | #define GNUNET_free(ptr) GNUNET_xfree_(ptr, __FILE__, __LINE__) | ||
329 | |||
330 | /** | ||
331 | * Free the memory pointed to by ptr if ptr is not NULL. | ||
332 | * Equivalent to if (ptr!=null)GNUNET_free(ptr). | ||
333 | * | ||
334 | * @param ptr the location in memory to free | ||
335 | */ | ||
336 | #define GNUNET_free_non_null(ptr) do { void * __x__ = ptr; if (__x__ != NULL) { GNUNET_free(__x__); } } while(0) | ||
337 | |||
338 | /** | ||
339 | * Wrapper around GNUNET_strdup. Makes a copy of the zero-terminated string | ||
340 | * pointed to by a. | ||
341 | * | ||
342 | * @param a pointer to a zero-terminated string | ||
343 | * @return a copy of the string including zero-termination | ||
344 | */ | ||
345 | #define GNUNET_strdup(a) GNUNET_xstrdup_(a,__FILE__,__LINE__) | ||
346 | |||
347 | /** | ||
348 | * Grow a well-typed (!) array. This is a convenience | ||
349 | * method to grow a vector <tt>arr</tt> of size <tt>size</tt> | ||
350 | * to the new (target) size <tt>tsize</tt>. | ||
351 | * <p> | ||
352 | * | ||
353 | * Example (simple, well-typed stack): | ||
354 | * | ||
355 | * <pre> | ||
356 | * static struct foo * myVector = NULL; | ||
357 | * static int myVecLen = 0; | ||
358 | * | ||
359 | * static void push(struct foo * elem) { | ||
360 | * GNUNET_array_grow(myVector, myVecLen, myVecLen+1); | ||
361 | * memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo)); | ||
362 | * } | ||
363 | * | ||
364 | * static void pop(struct foo * elem) { | ||
365 | * if (myVecLen == 0) die(); | ||
366 | * memcpy(elem, myVector[myVecLen-1], sizeof(struct foo)); | ||
367 | * GNUNET_array_grow(myVector, myVecLen, myVecLen-1); | ||
368 | * } | ||
369 | * </pre> | ||
370 | * | ||
371 | * @param arr base-pointer of the vector, may be NULL if size is 0; | ||
372 | * will be updated to reflect the new address. The TYPE of | ||
373 | * arr is important since size is the number of elements and | ||
374 | * not the size in bytes | ||
375 | * @param size the number of elements in the existing vector (number | ||
376 | * of elements to copy over) | ||
377 | * @param tsize the target size for the resulting vector, use 0 to | ||
378 | * free the vector (then, arr will be NULL afterwards). | ||
379 | */ | ||
380 | #define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&arr, sizeof(arr[0]), &size, tsize, __FILE__, __LINE__) | ||
381 | |||
382 | /** | ||
383 | * Append an element to a list (growing the | ||
384 | * list by one). | ||
385 | */ | ||
386 | #define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0) | ||
387 | |||
388 | /** | ||
389 | * Like snprintf, just aborts if the buffer is of insufficient size. | ||
390 | */ | ||
391 | int GNUNET_snprintf (char *buf, size_t size, const char *format, ...); | ||
392 | |||
393 | /** | ||
394 | * Like asprintf, just portable. | ||
395 | */ | ||
396 | int GNUNET_asprintf (char **buf, const char *format, ...); | ||
397 | |||
398 | |||
399 | /* ************** internal implementations, use macros above! ************** */ | ||
400 | |||
401 | /** | ||
402 | * Allocate memory. Checks the return value, aborts if no more | ||
403 | * memory is available. Don't use GNUNET_xmalloc_ directly. Use the | ||
404 | * GNUNET_malloc macro. | ||
405 | * The memory will be zero'ed out. | ||
406 | */ | ||
407 | void *GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber); | ||
408 | |||
409 | /** | ||
410 | * Allocate memory. This function does not check if the | ||
411 | * allocation request is within reasonable bounds, allowing | ||
412 | * allocations larger than 40 MB. If you don't expect the | ||
413 | * possibility of very large allocations, use GNUNET_malloc instead. | ||
414 | * The memory will be zero'ed out. | ||
415 | */ | ||
416 | void *GNUNET_xmalloc_unchecked_ (size_t size, | ||
417 | const char *filename, int linenumber); | ||
418 | |||
419 | /** | ||
420 | * Reallocate memory. Checks the return value, aborts if no more | ||
421 | * memory is available. | ||
422 | */ | ||
423 | void *GNUNET_xrealloc_ (void *ptr, | ||
424 | const size_t n, const char *filename, int linenumber); | ||
425 | |||
426 | /** | ||
427 | * Free memory. Merely a wrapper for the case that we | ||
428 | * want to keep track of allocations. Don't use GNUNET_xfree_ | ||
429 | * directly. Use the GNUNET_free macro. | ||
430 | */ | ||
431 | void GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); | ||
432 | |||
433 | |||
434 | /** | ||
435 | * Dup a string. Don't call GNUNET_xstrdup_ directly. Use the GNUNET_strdup macro. | ||
436 | */ | ||
437 | char *GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber); | ||
438 | |||
439 | /** | ||
440 | * Grow an array, the new elements are zeroed out. | ||
441 | * Grows old by (*oldCount-newCount)*elementSize | ||
442 | * bytes and sets *oldCount to newCount. | ||
443 | * | ||
444 | * Don't call GNUNET_xgrow_ directly. Use the GNUNET_array_grow macro. | ||
445 | * | ||
446 | * @param old address of the pointer to the array | ||
447 | * *old may be NULL | ||
448 | * @param elementSize the size of the elements of the array | ||
449 | * @param oldCount address of the number of elements in the *old array | ||
450 | * @param newCount number of elements in the new array, may be 0 (then *old will be NULL afterwards) | ||
451 | */ | ||
452 | void GNUNET_xgrow_ (void **old, | ||
453 | size_t elementSize, | ||
454 | unsigned int *oldCount, | ||
455 | unsigned int newCount, | ||
456 | const char *filename, int linenumber); | ||
457 | |||
458 | |||
459 | |||
460 | |||
461 | #if __STDC_VERSION__ < 199901L | ||
462 | # if __GNUC__ >= 2 | ||
463 | # define __func__ __FUNCTION__ | ||
464 | # else | ||
465 | # define __func__ "<unknown>" | ||
466 | # endif | ||
467 | #endif | ||
468 | |||
469 | #endif /*GNUNET_COMMON_H_ */ | ||
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h new file mode 100644 index 000000000..fefc6884a --- /dev/null +++ b/src/include/gnunet_configuration_lib.h | |||
@@ -0,0 +1,238 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2006, 2008, 2009 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 2, 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 include/gnunet_configuration_lib.h | ||
23 | * @brief configuration API | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_CONFIGURATION_LIB_H | ||
29 | #define GNUNET_CONFIGURATION_LIB_H | ||
30 | |||
31 | |||
32 | #ifdef __cplusplus | ||
33 | extern "C" | ||
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | #include "gnunet_common.h" | ||
41 | |||
42 | /** | ||
43 | * A configuration object. | ||
44 | */ | ||
45 | struct GNUNET_CONFIGURATION_Handle; | ||
46 | |||
47 | /** | ||
48 | * Create a new configuration object. | ||
49 | * | ||
50 | * @param component name of responsible component | ||
51 | */ | ||
52 | struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_create (void); | ||
53 | |||
54 | /** | ||
55 | * Destroy configuration object. | ||
56 | */ | ||
57 | void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); | ||
58 | |||
59 | /** | ||
60 | * Load configuration. This function will first parse the | ||
61 | * defaults and then parse the specific configuration file | ||
62 | * to overwrite the defaults. | ||
63 | * | ||
64 | * @param filename name of the configuration file | ||
65 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
66 | */ | ||
67 | int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
68 | const char *filename); | ||
69 | |||
70 | /** | ||
71 | * Parse a configuration file, add all of the options in the | ||
72 | * file to the configuration environment. | ||
73 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
74 | */ | ||
75 | int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
76 | const char *filename); | ||
77 | |||
78 | /** | ||
79 | * Write configuration file. | ||
80 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
81 | */ | ||
82 | int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
83 | const char *filename); | ||
84 | |||
85 | /** | ||
86 | * Test if there are configuration options that were | ||
87 | * changed since the last save. | ||
88 | * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed) | ||
89 | */ | ||
90 | int GNUNET_CONFIGURATION_is_dirty (struct GNUNET_CONFIGURATION_Handle *cfg); | ||
91 | |||
92 | /** | ||
93 | * Get a configuration value that should be a number. | ||
94 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
95 | */ | ||
96 | int GNUNET_CONFIGURATION_get_value_number (struct GNUNET_CONFIGURATION_Handle | ||
97 | *cfg, const char *section, | ||
98 | const char *option, | ||
99 | unsigned long long *number); | ||
100 | |||
101 | /** | ||
102 | * Test if we have a value for a particular option | ||
103 | * @return GNUNET_YES if so, GNUNET_NO if not. | ||
104 | */ | ||
105 | int GNUNET_CONFIGURATION_have_value (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
106 | const char *section, const char *option); | ||
107 | |||
108 | /** | ||
109 | * Get a configuration value that should be a string. | ||
110 | * @param value will be set to a freshly allocated configuration | ||
111 | * value, or NULL if option is not specified | ||
112 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
113 | */ | ||
114 | int GNUNET_CONFIGURATION_get_value_string (struct GNUNET_CONFIGURATION_Handle | ||
115 | *cfg, const char *section, | ||
116 | const char *option, char **value); | ||
117 | |||
118 | /** | ||
119 | * Get a configuration value that should be the name of a file | ||
120 | * or directory. | ||
121 | * | ||
122 | * @param value will be set to a freshly allocated configuration | ||
123 | * value, or NULL if option is not specified | ||
124 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
125 | */ | ||
126 | int GNUNET_CONFIGURATION_get_value_filename (struct | ||
127 | GNUNET_CONFIGURATION_Handle *cfg, | ||
128 | const char *section, | ||
129 | const char *option, | ||
130 | char **value); | ||
131 | |||
132 | /** | ||
133 | * Iterate over the set of filenames stored in a configuration value. | ||
134 | * | ||
135 | * @return number of filenames iterated over, -1 on error | ||
136 | */ | ||
137 | int GNUNET_CONFIGURATION_iterate_value_filenames (struct | ||
138 | GNUNET_CONFIGURATION_Handle | ||
139 | *cfg, | ||
140 | const char *section, | ||
141 | const char *option, | ||
142 | GNUNET_FileNameCallback | ||
143 | cb, void *cls); | ||
144 | |||
145 | /** | ||
146 | * Get a configuration value that should be in a set of | ||
147 | * predefined strings | ||
148 | * | ||
149 | * @param choices NULL-terminated list of legal values | ||
150 | * @param value will be set to an entry in the legal list, | ||
151 | * or NULL if option is not specified and no default given | ||
152 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
153 | */ | ||
154 | int GNUNET_CONFIGURATION_get_value_choice (struct GNUNET_CONFIGURATION_Handle | ||
155 | *cfg, const char *section, | ||
156 | const char *option, | ||
157 | const char **choices, | ||
158 | const char **value); | ||
159 | |||
160 | /** | ||
161 | * Get a configuration value that should be in a set of | ||
162 | * "YES" or "NO". | ||
163 | * | ||
164 | * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR | ||
165 | */ | ||
166 | int GNUNET_CONFIGURATION_get_value_yesno (struct GNUNET_CONFIGURATION_Handle | ||
167 | *cfg, const char *section, | ||
168 | const char *option); | ||
169 | |||
170 | /** | ||
171 | * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" | ||
172 | * where either in the "PATHS" section or the environtment | ||
173 | * "FOO" is set to "DIRECTORY". | ||
174 | |||
175 | * @param old string to $-expand (will be freed!) | ||
176 | * @return $-expanded string | ||
177 | */ | ||
178 | char *GNUNET_CONFIGURATION_expand_dollar (struct GNUNET_CONFIGURATION_Handle | ||
179 | *cfg, char *old); | ||
180 | |||
181 | /** | ||
182 | * Set a configuration value that should be a number. | ||
183 | */ | ||
184 | void | ||
185 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle | ||
186 | *cfg, | ||
187 | const char *section, | ||
188 | const char *option, | ||
189 | unsigned long long number); | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Set a configuration value that should be a string. | ||
194 | * @param value | ||
195 | */ | ||
196 | void | ||
197 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle | ||
198 | *cfg, | ||
199 | const char *section, | ||
200 | const char *option, const char *value); | ||
201 | |||
202 | /** | ||
203 | * Remove a filename from a configuration value that | ||
204 | * represents a list of filenames | ||
205 | * | ||
206 | * @param value filename to remove | ||
207 | * @return GNUNET_OK on success, | ||
208 | * GNUNET_SYSERR if the filename is not in the list | ||
209 | */ | ||
210 | int GNUNET_CONFIGURATION_remove_value_filename (struct | ||
211 | GNUNET_CONFIGURATION_Handle | ||
212 | *cfg, | ||
213 | const char *section, | ||
214 | const char *option, | ||
215 | const char *value); | ||
216 | |||
217 | /** | ||
218 | * Append a filename to a configuration value that | ||
219 | * represents a list of filenames | ||
220 | * | ||
221 | * @param value filename to append | ||
222 | * @return GNUNET_OK on success, | ||
223 | * GNUNET_SYSERR if the filename already in the list | ||
224 | */ | ||
225 | int GNUNET_CONFIGURATION_append_value_filename (struct | ||
226 | GNUNET_CONFIGURATION_Handle | ||
227 | *cfg, const char *section, | ||
228 | const char *option, | ||
229 | const char *value); | ||
230 | |||
231 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
232 | { | ||
233 | #endif | ||
234 | #ifdef __cplusplus | ||
235 | } | ||
236 | #endif | ||
237 | |||
238 | #endif | ||
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h new file mode 100644 index 000000000..255f68a89 --- /dev/null +++ b/src/include/gnunet_container_lib.h | |||
@@ -0,0 +1,784 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008 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 2, 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 include/gnunet_container_lib.h | ||
23 | * @brief container classes for GNUnet | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | * @author Nils Durner | ||
27 | */ | ||
28 | |||
29 | #ifndef GNUNET_CONTAINER_LIB_H | ||
30 | #define GNUNET_CONTAINER_LIB_H | ||
31 | |||
32 | /* add error and config prototypes */ | ||
33 | #include "gnunet_crypto_lib.h" | ||
34 | #include <extractor.h> | ||
35 | |||
36 | #ifdef __cplusplus | ||
37 | extern "C" | ||
38 | { | ||
39 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
40 | } | ||
41 | #endif | ||
42 | #endif | ||
43 | |||
44 | |||
45 | /* ******************* bloomfilter ***************** */ | ||
46 | |||
47 | /** | ||
48 | * @brief bloomfilter representation (opaque) | ||
49 | */ | ||
50 | struct GNUNET_CONTAINER_BloomFilter; | ||
51 | |||
52 | /** | ||
53 | * Iterator over HashCodes. | ||
54 | * | ||
55 | * @return GNUNET_YES if next was updated | ||
56 | * GNUNET_NO if there are no more entries | ||
57 | */ | ||
58 | typedef int (*GNUNET_HashCodeIterator) (GNUNET_HashCode * next, void *arg); | ||
59 | |||
60 | /** | ||
61 | * Load a bloom-filter from a file. | ||
62 | * @param filename the name of the file (or the prefix) | ||
63 | * @param size the size of the bloom-filter (number of | ||
64 | * bytes of storage space to use) | ||
65 | * @param k the number of GNUNET_CRYPTO_hash-functions to apply per | ||
66 | * element (number of bits set per element in the set) | ||
67 | * @return the bloomfilter | ||
68 | */ | ||
69 | struct GNUNET_CONTAINER_BloomFilter *GNUNET_CONTAINER_bloomfilter_load (const | ||
70 | char | ||
71 | *filename, | ||
72 | unsigned | ||
73 | int | ||
74 | size, | ||
75 | unsigned | ||
76 | int | ||
77 | k); | ||
78 | |||
79 | /** | ||
80 | * Create a bloom filter from raw bits. | ||
81 | * | ||
82 | * @param data the raw bits in memory (maybe NULL, | ||
83 | * in which case all bits should be considered | ||
84 | * to be zero). | ||
85 | * @param size the size of the bloom-filter (number of | ||
86 | * bytes of storage space to use); also size of data | ||
87 | * -- unless data is NULL. Must be a power of 2. | ||
88 | * @param k the number of GNUNET_CRYPTO_hash-functions to apply per | ||
89 | * element (number of bits set per element in the set) | ||
90 | * @return the bloomfilter | ||
91 | */ | ||
92 | struct GNUNET_CONTAINER_BloomFilter *GNUNET_CONTAINER_bloomfilter_init (const | ||
93 | char | ||
94 | *data, | ||
95 | unsigned | ||
96 | int | ||
97 | size, | ||
98 | unsigned | ||
99 | int | ||
100 | k); | ||
101 | |||
102 | /** | ||
103 | * Copy the raw data of this bloomfilter into | ||
104 | * the given data array. | ||
105 | * | ||
106 | * @param data where to write the data | ||
107 | * @param size the size of the given data array | ||
108 | * @return GNUNET_SYSERR if the data array of the wrong size | ||
109 | */ | ||
110 | int GNUNET_CONTAINER_bloomfilter_get_raw_data (struct | ||
111 | GNUNET_CONTAINER_BloomFilter | ||
112 | *bf, char *data, | ||
113 | unsigned int size); | ||
114 | |||
115 | /** | ||
116 | * Test if an element is in the filter. | ||
117 | * @param e the element | ||
118 | * @param bf the filter | ||
119 | * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not | ||
120 | */ | ||
121 | int GNUNET_CONTAINER_bloomfilter_test (struct GNUNET_CONTAINER_BloomFilter | ||
122 | *bf, const GNUNET_HashCode * e); | ||
123 | |||
124 | /** | ||
125 | * Add an element to the filter | ||
126 | * @param bf the filter | ||
127 | * @param e the element | ||
128 | */ | ||
129 | void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter | ||
130 | *bf, const GNUNET_HashCode * e); | ||
131 | |||
132 | /** | ||
133 | * Remove an element from the filter. | ||
134 | * @param bf the filter | ||
135 | * @param e the element to remove | ||
136 | */ | ||
137 | void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter | ||
138 | *bf, const GNUNET_HashCode * e); | ||
139 | |||
140 | /** | ||
141 | * Free the space associcated with a filter | ||
142 | * in memory, flush to drive if needed (do not | ||
143 | * free the space on the drive) | ||
144 | * @param bf the filter | ||
145 | */ | ||
146 | void GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter | ||
147 | *bf); | ||
148 | |||
149 | /** | ||
150 | * Reset a bloom filter to empty. | ||
151 | * @param bf the filter | ||
152 | */ | ||
153 | void GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter | ||
154 | *bf); | ||
155 | |||
156 | /** | ||
157 | * Or the entries of the given raw data array with the | ||
158 | * data of the given bloom filter. Assumes that | ||
159 | * the size of the data array and the current filter | ||
160 | * match. | ||
161 | * @param bf the filter | ||
162 | */ | ||
163 | int GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | ||
164 | const char *data, unsigned int size); | ||
165 | |||
166 | /** | ||
167 | * Resize a bloom filter. Note that this operation | ||
168 | * is pretty costly. Essentially, the bloom filter | ||
169 | * needs to be completely re-build. | ||
170 | * | ||
171 | * @param bf the filter | ||
172 | * @param iterator an iterator over all elements stored in the BF | ||
173 | * @param iterator_arg argument to the iterator function | ||
174 | * @param size the new size for the filter | ||
175 | * @param k the new number of GNUNET_CRYPTO_hash-function to apply per element | ||
176 | */ | ||
177 | void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter | ||
178 | *bf, | ||
179 | GNUNET_HashCodeIterator iterator, | ||
180 | void *iterator_arg, | ||
181 | unsigned int size, unsigned int k); | ||
182 | |||
183 | /* ****************** metadata ******************* */ | ||
184 | |||
185 | /** | ||
186 | * Meta data to associate with a file, directory or namespace. | ||
187 | */ | ||
188 | struct GNUNET_CONTAINER_MetaData; | ||
189 | |||
190 | /** | ||
191 | * Iterator over meta data. | ||
192 | * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort | ||
193 | */ | ||
194 | typedef int (*GNUNET_CONTAINER_MetaDataProcessor) (EXTRACTOR_KeywordType type, | ||
195 | const char *data, | ||
196 | void *closure); | ||
197 | |||
198 | /** | ||
199 | * Create a fresh MetaData token. | ||
200 | */ | ||
201 | struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_create (void); | ||
202 | |||
203 | /** | ||
204 | * Duplicate a MetaData token. | ||
205 | */ | ||
206 | struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_duplicate (const | ||
207 | struct | ||
208 | GNUNET_CONTAINER_MetaData | ||
209 | *meta); | ||
210 | |||
211 | /** | ||
212 | * Free meta data. | ||
213 | */ | ||
214 | void GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData | ||
215 | *md); | ||
216 | |||
217 | /** | ||
218 | * Test if two MDs are equal. | ||
219 | */ | ||
220 | int GNUNET_CONTAINER_meta_data_test_equal (const struct | ||
221 | GNUNET_CONTAINER_MetaData *md1, | ||
222 | const struct | ||
223 | GNUNET_CONTAINER_MetaData *md2); | ||
224 | |||
225 | |||
226 | /** | ||
227 | * Extend metadata. | ||
228 | * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists | ||
229 | */ | ||
230 | int GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | ||
231 | EXTRACTOR_KeywordType type, | ||
232 | const char *data); | ||
233 | |||
234 | /** | ||
235 | * Remove an item. | ||
236 | * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md | ||
237 | */ | ||
238 | int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, | ||
239 | EXTRACTOR_KeywordType type, | ||
240 | const char *data); | ||
241 | |||
242 | /** | ||
243 | * Add the current time as the publication date | ||
244 | * to the meta-data. | ||
245 | */ | ||
246 | void GNUNET_CONTAINER_meta_data_add_publication_date (struct | ||
247 | GNUNET_CONTAINER_MetaData | ||
248 | *md); | ||
249 | |||
250 | /** | ||
251 | * Iterate over MD entries, excluding thumbnails. | ||
252 | * | ||
253 | * @return number of entries | ||
254 | */ | ||
255 | int GNUNET_CONTAINER_meta_data_get_contents (const struct | ||
256 | GNUNET_CONTAINER_MetaData *md, | ||
257 | GNUNET_CONTAINER_MetaDataProcessor | ||
258 | iterator, void *closure); | ||
259 | |||
260 | /** | ||
261 | * Get the first MD entry of the given type. | ||
262 | * @return NULL if we do not have any such entry, | ||
263 | * otherwise client is responsible for freeing the value! | ||
264 | */ | ||
265 | char *GNUNET_CONTAINER_meta_data_get_by_type (const struct | ||
266 | GNUNET_CONTAINER_MetaData *md, | ||
267 | EXTRACTOR_KeywordType type); | ||
268 | |||
269 | /** | ||
270 | * Get the first matching MD entry of the given types. | ||
271 | * @paarm ... -1-terminated list of types | ||
272 | * @return NULL if we do not have any such entry, | ||
273 | * otherwise client is responsible for freeing the value! | ||
274 | */ | ||
275 | char *GNUNET_CONTAINER_meta_data_get_first_by_types (const struct | ||
276 | GNUNET_CONTAINER_MetaData | ||
277 | *md, ...); | ||
278 | |||
279 | /** | ||
280 | * Get a thumbnail from the meta-data (if present). | ||
281 | * | ||
282 | * @param thumb will be set to the thumbnail data. Must be | ||
283 | * freed by the caller! | ||
284 | * @return number of bytes in thumbnail, 0 if not available | ||
285 | */ | ||
286 | size_t GNUNET_CONTAINER_meta_data_get_thumbnail (const struct | ||
287 | GNUNET_CONTAINER_MetaData | ||
288 | *md, unsigned char **thumb); | ||
289 | |||
290 | /** | ||
291 | * Extract meta-data from a file. | ||
292 | * | ||
293 | * @return GNUNET_SYSERR on error, otherwise the number | ||
294 | * of meta-data items obtained | ||
295 | */ | ||
296 | int GNUNET_CONTAINER_meta_data_extract_from_file (struct | ||
297 | GNUNET_CONTAINER_MetaData | ||
298 | *md, const char *filename, | ||
299 | EXTRACTOR_ExtractorList * | ||
300 | extractors); | ||
301 | |||
302 | enum GNUNET_CONTAINER_MetaDataSerializationOptions | ||
303 | { | ||
304 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = GNUNET_NO, | ||
305 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = GNUNET_YES, | ||
306 | GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2 | ||
307 | }; | ||
308 | |||
309 | |||
310 | |||
311 | /** | ||
312 | * Serialize meta-data to target. | ||
313 | * | ||
314 | * @param size maximum number of bytes available | ||
315 | * @param opt is it ok to just write SOME of the | ||
316 | * meta-data to match the size constraint, | ||
317 | * possibly discarding some data? | ||
318 | * @return number of bytes written on success, | ||
319 | * GNUNET_SYSERR on error (typically: not enough | ||
320 | * space) | ||
321 | */ | ||
322 | int GNUNET_CONTAINER_meta_data_serialize (const struct | ||
323 | GNUNET_CONTAINER_MetaData *md, | ||
324 | char *target, unsigned int size, | ||
325 | enum | ||
326 | GNUNET_CONTAINER_MetaDataSerializationOptions | ||
327 | opt); | ||
328 | |||
329 | /** | ||
330 | * Compute size of the meta-data in | ||
331 | * serialized form. | ||
332 | * @param opt is it ok to just write SOME of the | ||
333 | * meta-data to match the size constraint, | ||
334 | * possibly discarding some data? | ||
335 | */ | ||
336 | unsigned int GNUNET_CONTAINER_meta_data_get_serialized_size (const struct | ||
337 | GNUNET_CONTAINER_MetaData | ||
338 | *md, | ||
339 | enum | ||
340 | GNUNET_CONTAINER_MetaDataSerializationOptions | ||
341 | opt); | ||
342 | |||
343 | /** | ||
344 | * Deserialize meta-data. Initializes md. | ||
345 | * @param size number of bytes available | ||
346 | * @return MD on success, NULL on error (i.e. | ||
347 | * bad format) | ||
348 | */ | ||
349 | struct GNUNET_CONTAINER_MetaData | ||
350 | *GNUNET_CONTAINER_meta_data_deserialize (const char *input, | ||
351 | unsigned int size); | ||
352 | |||
353 | /** | ||
354 | * Does the meta-data claim that this is a directory? | ||
355 | * Checks if the mime-type is that of a GNUnet directory. | ||
356 | * | ||
357 | * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if | ||
358 | * we have no mime-type information (treat as 'GNUNET_NO') | ||
359 | */ | ||
360 | int GNUNET_CONTAINER_meta_data_test_for_directory (const struct | ||
361 | GNUNET_CONTAINER_MetaData | ||
362 | *md); | ||
363 | |||
364 | |||
365 | /* ******************************* HashMap **************************** */ | ||
366 | |||
367 | /** | ||
368 | * Opaque handle for a HashMap. | ||
369 | */ | ||
370 | struct GNUNET_CONTAINER_MultiHashMap; | ||
371 | |||
372 | /** | ||
373 | * Options for storing values in the HashMap. | ||
374 | */ | ||
375 | enum GNUNET_CONTAINER_MultiHashMapOption | ||
376 | { | ||
377 | /** | ||
378 | * If a value with the given key exists, replace it. | ||
379 | * Note that the old value would NOT be freed | ||
380 | * by replace (the application has to make sure that | ||
381 | * this happens if required). | ||
382 | */ | ||
383 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE, | ||
384 | |||
385 | /** | ||
386 | * Allow multiple values with the same key. | ||
387 | */ | ||
388 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, | ||
389 | |||
390 | /** | ||
391 | * There must only be one value per key; storing | ||
392 | * a value should fail if a value under the same | ||
393 | * key already exists. | ||
394 | */ | ||
395 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, | ||
396 | |||
397 | /** | ||
398 | * There must only be one value per key, but don't | ||
399 | * bother checking if a value already exists | ||
400 | * (faster than UNIQUE_ONLY; implemented just like | ||
401 | * MULTIPLE but this option documents better what | ||
402 | * is intended if UNIQUE is what is desired). | ||
403 | */ | ||
404 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST | ||
405 | }; | ||
406 | |||
407 | /** | ||
408 | * Iterator over HashCodes. | ||
409 | * | ||
410 | * @param key current key code | ||
411 | * @param value value in the hash map | ||
412 | * @param cls client-defined argument | ||
413 | * @return GNUNET_YES if we should continue to | ||
414 | * iterate, | ||
415 | * GNUNET_NO if not. | ||
416 | */ | ||
417 | typedef int (*GNUNET_CONTAINER_HashMapIterator) (const GNUNET_HashCode * key, | ||
418 | void *value, void *cls); | ||
419 | |||
420 | |||
421 | /** | ||
422 | * Create a multi hash map. | ||
423 | * | ||
424 | * @param map the map | ||
425 | * @param len initial size (map will grow as needed) | ||
426 | * @return NULL on error | ||
427 | */ | ||
428 | struct GNUNET_CONTAINER_MultiHashMap | ||
429 | *GNUNET_CONTAINER_multihashmap_create (unsigned int len); | ||
430 | |||
431 | /** | ||
432 | * Destroy a hash map. Will not free any values | ||
433 | * stored in the hash map! | ||
434 | * | ||
435 | * @param map the map | ||
436 | */ | ||
437 | void GNUNET_CONTAINER_multihashmap_destroy (struct | ||
438 | GNUNET_CONTAINER_MultiHashMap | ||
439 | *map); | ||
440 | |||
441 | /** | ||
442 | * Given a key find a value in the | ||
443 | * map matching the key. | ||
444 | * | ||
445 | * @param map the map | ||
446 | * @param key what to look for | ||
447 | * @return NULL if no value was found; note that | ||
448 | * this is indistinguishable from values that just | ||
449 | * happen to be NULL; use "contains" to test for | ||
450 | * key-value pairs with value NULL | ||
451 | */ | ||
452 | void *GNUNET_CONTAINER_multihashmap_get (const struct | ||
453 | GNUNET_CONTAINER_MultiHashMap *map, | ||
454 | const GNUNET_HashCode * key); | ||
455 | |||
456 | /** | ||
457 | * Remove the given key-value pair from the map. | ||
458 | * Note that if the key-value pair is in the map | ||
459 | * multiple times, only one of the pairs will be | ||
460 | * removed. | ||
461 | * | ||
462 | * @param map the map | ||
463 | * @param key key of the key-value pair | ||
464 | * @param value value of the key-value pair | ||
465 | * @return GNUNET_YES on success, GNUNET_NO if the key-value pair | ||
466 | * is not in the map | ||
467 | */ | ||
468 | int GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap | ||
469 | *map, const GNUNET_HashCode * key, | ||
470 | void *value); | ||
471 | |||
472 | /** | ||
473 | * Remove all entries for the given key from the map. | ||
474 | * Note that the values would not be "freed". | ||
475 | * | ||
476 | * @param map the map | ||
477 | * @param key identifies values to be removed | ||
478 | * @return number of values removed | ||
479 | */ | ||
480 | int GNUNET_CONTAINER_multihashmap_remove_all (struct | ||
481 | GNUNET_CONTAINER_MultiHashMap | ||
482 | *map, | ||
483 | const GNUNET_HashCode * key); | ||
484 | |||
485 | /** | ||
486 | * Check if the map contains any value under the given | ||
487 | * key (including values that are NULL). | ||
488 | * | ||
489 | * @param map the map | ||
490 | * @param key the key to test if a value exists for it | ||
491 | * @return GNUNET_YES if such a value exists, | ||
492 | * GNUNET_NO if not | ||
493 | */ | ||
494 | int GNUNET_CONTAINER_multihashmap_contains (const struct | ||
495 | GNUNET_CONTAINER_MultiHashMap | ||
496 | *map, | ||
497 | const GNUNET_HashCode * key); | ||
498 | |||
499 | /** | ||
500 | * Store a key-value pair in the map. | ||
501 | * | ||
502 | * @param map the map | ||
503 | * @param key key to use | ||
504 | * @param value value to use | ||
505 | * @param opt options for put | ||
506 | * @return GNUNET_OK on success, | ||
507 | * GNUNET_NO if a value was replaced (with REPLACE) | ||
508 | * GNUNET_SYSERR if UNIQUE_ONLY was the option and the | ||
509 | * value already exists | ||
510 | */ | ||
511 | int GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap | ||
512 | *map, const GNUNET_HashCode * key, | ||
513 | void *value, | ||
514 | enum | ||
515 | GNUNET_CONTAINER_MultiHashMapOption | ||
516 | opt); | ||
517 | |||
518 | /** | ||
519 | * Get the number of key-value pairs in the map. | ||
520 | * | ||
521 | * @param map the map | ||
522 | * @return the number of key value pairs | ||
523 | */ | ||
524 | unsigned int GNUNET_CONTAINER_multihashmap_size (const struct | ||
525 | GNUNET_CONTAINER_MultiHashMap | ||
526 | *map); | ||
527 | |||
528 | |||
529 | /** | ||
530 | * Iterate over all entries in the map. | ||
531 | * | ||
532 | * @param map the map | ||
533 | * @param iterator function to call on each entry | ||
534 | * @param cls extra argument to it | ||
535 | * @return the number of key value pairs processed, | ||
536 | * GNUNET_SYSERR if it aborted iteration | ||
537 | */ | ||
538 | int GNUNET_CONTAINER_multihashmap_iterate (const struct | ||
539 | GNUNET_CONTAINER_MultiHashMap *map, | ||
540 | GNUNET_CONTAINER_HashMapIterator | ||
541 | iterator, void *cls); | ||
542 | |||
543 | /** | ||
544 | * Iterate over all entries in the map | ||
545 | * that match a particular key. | ||
546 | * | ||
547 | * @param map the map | ||
548 | * @param key key that the entries must correspond to | ||
549 | * @param iterator function to call on each entry | ||
550 | * @param cls extra argument to it | ||
551 | * @return the number of key value pairs processed, | ||
552 | * GNUNET_SYSERR if it aborted iteration | ||
553 | */ | ||
554 | int GNUNET_CONTAINER_multihashmap_get_multiple (const struct | ||
555 | GNUNET_CONTAINER_MultiHashMap | ||
556 | *map, | ||
557 | const GNUNET_HashCode * key, | ||
558 | GNUNET_CONTAINER_HashMapIterator | ||
559 | iterator, void *cls); | ||
560 | /** | ||
561 | * Returns the stored value of a random non-null entry | ||
562 | * in the hash table. Returns only the first value, does | ||
563 | * not go inside bucket linked list (yet). Runs with a | ||
564 | * worst case time of N, so it's not efficient in any way | ||
565 | * shape or form!!!!. | ||
566 | */ | ||
567 | void *GNUNET_CONTAINER_multihashmap_get_random (const struct | ||
568 | GNUNET_CONTAINER_MultiHashMap | ||
569 | *map); | ||
570 | |||
571 | |||
572 | |||
573 | |||
574 | /* ******************** doubly-linked list *************** */ | ||
575 | |||
576 | /** | ||
577 | * Insert an element into a DLL. Assumes | ||
578 | * that head, tail and element are structs | ||
579 | * with prev and next fields. | ||
580 | */ | ||
581 | #define GNUNET_CONTAINER_DLL_insert(head,tail,element) \ | ||
582 | (element)->next = (head); \ | ||
583 | (element)->prev = NULL; \ | ||
584 | if ((tail) == NULL) \ | ||
585 | (tail) = element; \ | ||
586 | else \ | ||
587 | (head)->prev = element; \ | ||
588 | (head) = (element); | ||
589 | |||
590 | /** | ||
591 | * Insert an element into a DLL after the given other | ||
592 | * element. Insert at the head if the other | ||
593 | * element is NULL. | ||
594 | */ | ||
595 | #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) \ | ||
596 | (element)->prev = (other); \ | ||
597 | if (NULL == other) \ | ||
598 | { \ | ||
599 | (element)->next = (head); \ | ||
600 | (head) = (element); \ | ||
601 | } \ | ||
602 | else \ | ||
603 | { \ | ||
604 | (element)->next = (other)->next; \ | ||
605 | (other)->next = (element); \ | ||
606 | } \ | ||
607 | if (NULL == (element)->next) \ | ||
608 | (tail) = (element); \ | ||
609 | else \ | ||
610 | (element)->next->prev = (element); | ||
611 | |||
612 | |||
613 | |||
614 | |||
615 | /** | ||
616 | * Remove an element from a DLL. Assumes | ||
617 | * that head, tail and element are structs | ||
618 | * with prev and next fields. | ||
619 | */ | ||
620 | #define GNUNET_CONTAINER_DLL_remove(head,tail,element) \ | ||
621 | if ((element)->prev == NULL) \ | ||
622 | (head) = (element)->next; \ | ||
623 | else \ | ||
624 | (element)->prev->next = (element)->next; \ | ||
625 | if ((element)->next == NULL) \ | ||
626 | (tail) = (element)->prev; \ | ||
627 | else \ | ||
628 | (element)->next->prev = (element)->prev; | ||
629 | |||
630 | |||
631 | |||
632 | /* ******************** Heap *************** */ | ||
633 | |||
634 | |||
635 | /** | ||
636 | * Cost by which elements in a heap can be ordered. | ||
637 | */ | ||
638 | typedef unsigned int GNUNET_CONTAINER_HeapCost; | ||
639 | |||
640 | /* | ||
641 | * Heap type, either max or min. Hopefully makes the | ||
642 | * implementation more useful. | ||
643 | */ | ||
644 | enum GNUNET_CONTAINER_HeapOrder | ||
645 | { | ||
646 | /** | ||
647 | * Heap with the maximum cost at the root. | ||
648 | */ | ||
649 | GNUNET_CONTAINER_HEAP_ORDER_MAX, | ||
650 | |||
651 | /** | ||
652 | * Heap with the minimum cost at the root. | ||
653 | */ | ||
654 | GNUNET_CONTAINER_HEAP_ORDER_MIN | ||
655 | }; | ||
656 | |||
657 | /** | ||
658 | * Handle to a Heap. | ||
659 | */ | ||
660 | struct GNUNET_CONTAINER_Heap; | ||
661 | |||
662 | /** | ||
663 | * Create a new heap. | ||
664 | * | ||
665 | * @param type should the minimum or the maximum element be the root | ||
666 | * @return NULL on error, otherwise a fresh heap | ||
667 | */ | ||
668 | struct GNUNET_CONTAINER_Heap *GNUNET_CONTAINER_heap_create (enum | ||
669 | GNUNET_CONTAINER_HeapOrder | ||
670 | type); | ||
671 | |||
672 | /** | ||
673 | * Free a heap | ||
674 | * | ||
675 | * @param h heap to free. | ||
676 | */ | ||
677 | void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *h); | ||
678 | |||
679 | /** | ||
680 | * Function called on elements of a heap. | ||
681 | * | ||
682 | * @param cls closure | ||
683 | * @param element obj stored in heap | ||
684 | * @param cost cost of the element | ||
685 | * @return GNUNET_YES if we should continue to iterate, | ||
686 | * GNUNET_NO if not. | ||
687 | */ | ||
688 | typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls, | ||
689 | void *element, | ||
690 | GNUNET_CONTAINER_HeapCost cost); | ||
691 | /** | ||
692 | * Iterate over all entries in the map. | ||
693 | * | ||
694 | * @param heap the heap | ||
695 | * @param iterator function to call on each entry | ||
696 | * @param iterator_cls closure for iterator | ||
697 | * @return number of items handled | ||
698 | * GNUNET_SYSERR if iteration was aborted by iterator | ||
699 | */ | ||
700 | int GNUNET_CONTAINER_heap_iterate (struct GNUNET_CONTAINER_Heap *heap, | ||
701 | GNUNET_CONTAINER_HeapIterator iterator, | ||
702 | void *iterator_cls); | ||
703 | |||
704 | |||
705 | /** | ||
706 | * Inserts a new item into the heap, item is always neighbor now. | ||
707 | * @param heap the heap | ||
708 | */ | ||
709 | int | ||
710 | GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, | ||
711 | void *element, GNUNET_CONTAINER_HeapCost cost); | ||
712 | |||
713 | /** | ||
714 | * Removes root of the tree, is remove max if a max heap and remove min | ||
715 | * if a min heap, returns the data stored at the node. | ||
716 | * | ||
717 | * @param heap the heap | ||
718 | * @return NULL if the heap is empty | ||
719 | */ | ||
720 | void *GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap); | ||
721 | |||
722 | /** | ||
723 | * Returns element stored at root of tree, doesn't effect anything | ||
724 | * | ||
725 | * @param heap the heap | ||
726 | * @return NULL if the heap is empty | ||
727 | */ | ||
728 | void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap); | ||
729 | |||
730 | /** | ||
731 | * Removes any node from the tree based on the neighbor given, does | ||
732 | * not traverse the tree (backpointers) but may take more time due to | ||
733 | * percolation of nodes. | ||
734 | * @param heap the heap | ||
735 | */ | ||
736 | void *GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap, | ||
737 | void *element); | ||
738 | |||
739 | /** | ||
740 | * Updates the cost of any node in the tree | ||
741 | * | ||
742 | * @param heap the heap | ||
743 | * @param element the element for which the cost is updated | ||
744 | * @param new_cost new cost for the element | ||
745 | * @return WHAT? | ||
746 | */ | ||
747 | int | ||
748 | GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, | ||
749 | void *element, | ||
750 | GNUNET_CONTAINER_HeapCost new_cost); | ||
751 | |||
752 | /** | ||
753 | * Random walk of the tree, returns the data stored at the next random node | ||
754 | * in the walk. Calls callee with the data, or NULL if the tree is empty | ||
755 | * or some other problem crops up. | ||
756 | * | ||
757 | * @param heap the heap | ||
758 | * @return the next element from the random walk | ||
759 | */ | ||
760 | void *GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap | ||
761 | *heap); | ||
762 | |||
763 | /** | ||
764 | * Returns the current size of the heap | ||
765 | * | ||
766 | * @param heap the heap to get the size of | ||
767 | * @return number of elements in the heap | ||
768 | */ | ||
769 | unsigned int | ||
770 | GNUNET_CONTAINER_heap_get_size (struct GNUNET_CONTAINER_Heap *heap); | ||
771 | |||
772 | |||
773 | |||
774 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
775 | { | ||
776 | #endif | ||
777 | #ifdef __cplusplus | ||
778 | } | ||
779 | #endif | ||
780 | |||
781 | |||
782 | /* ifndef GNUNET_CONTAINER_LIB_H */ | ||
783 | #endif | ||
784 | /* end of gnunet_container_lib.h */ | ||
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h new file mode 100644 index 000000000..8b75271b9 --- /dev/null +++ b/src/include/gnunet_core_service.h | |||
@@ -0,0 +1,323 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 2, 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 include/gnunet_core_service.h | ||
23 | * @brief core service; this is the main API for encrypted P2P | ||
24 | * communications | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_CORE_SERVICE_H | ||
29 | #define GNUNET_CORE_SERVICE_H | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" | ||
33 | { | ||
34 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
35 | } | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | #include "gnunet_util_lib.h" | ||
40 | |||
41 | /** | ||
42 | * Version number of GNUnet-core API. | ||
43 | */ | ||
44 | #define GNUNET_CORE_VERSION 0x00000000 | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Opaque handle to the service. | ||
49 | */ | ||
50 | struct GNUNET_CORE_Handle; | ||
51 | |||
52 | |||
53 | /** | ||
54 | * Method called whenever a given peer either connects or | ||
55 | * disconnects (or list of connections was requested). | ||
56 | * | ||
57 | * @param cls closure | ||
58 | * @param peer peer identity this notification is about | ||
59 | * @param bpm how much bandwidth is available | ||
60 | * (for sending) to this peer | ||
61 | * @param last_activity when did we last | ||
62 | * receive anything from this peer? | ||
63 | */ | ||
64 | typedef void (*GNUNET_CORE_ClientEventHandler) (void *cls, | ||
65 | const struct | ||
66 | GNUNET_PeerIdentity * peer, | ||
67 | unsigned int bpm, | ||
68 | struct GNUNET_TIME_Absolute | ||
69 | last_activity); | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Type of a send callback to fill up buffers. | ||
74 | * | ||
75 | * @param receiver the receiver of the message | ||
76 | * @param position is the reference to the | ||
77 | * first unused position in the buffer where GNUnet is building | ||
78 | * the message | ||
79 | * @param padding is the number of bytes left in that buffer. | ||
80 | * @return the number of bytes written to | ||
81 | * that buffer (must be a positive number). | ||
82 | */ | ||
83 | typedef unsigned int | ||
84 | (*GNUNET_CORE_BufferFillCallback) (void *cls, | ||
85 | const struct GNUNET_PeerIdentity * | ||
86 | receiver, | ||
87 | void *position, unsigned int padding); | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Functions with this signature are called whenever a message is | ||
92 | * received or transmitted. | ||
93 | * | ||
94 | * @param cls closure | ||
95 | * @param peer the other peer involved (sender or receiver, NULL | ||
96 | * for loopback messages where we are both sender and receiver) | ||
97 | * @param message the actual message | ||
98 | * @return GNUNET_OK to keep the connection open, | ||
99 | * GNUNET_SYSERR to close it (signal serious error) | ||
100 | */ | ||
101 | typedef int | ||
102 | (*GNUNET_CORE_MessageCallback) (void *cls, | ||
103 | const struct GNUNET_PeerIdentity * other, | ||
104 | const struct GNUNET_MessageHeader * | ||
105 | message); | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Message handler. Each struct specifies how to handle on particular | ||
110 | * type of message received. | ||
111 | */ | ||
112 | struct GNUNET_CORE_MessageHandler | ||
113 | { | ||
114 | /** | ||
115 | * Function to call for messages of "type". | ||
116 | */ | ||
117 | GNUNET_CORE_MessageCallback callback; | ||
118 | |||
119 | /** | ||
120 | * Type of the message this handler covers. | ||
121 | */ | ||
122 | uint16_t type; | ||
123 | |||
124 | /** | ||
125 | * Expected size of messages of this type. Use 0 for variable-size. | ||
126 | * If non-zero, messages of the given type will be discarded if they | ||
127 | * do not have the right size. | ||
128 | */ | ||
129 | uint16_t expected_size; | ||
130 | |||
131 | }; | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Function called after GNUNET_CORE_connect has succeeded | ||
136 | * (or failed for good). Note that the private key of the | ||
137 | * peer is intentionally not exposed here; if you need it, | ||
138 | * your process should try to read the private key file | ||
139 | * directly (which should work if you are authorized...). | ||
140 | * | ||
141 | * @param cls closure | ||
142 | * @param server handle to the server, NULL if we failed | ||
143 | * @param my_identity ID of this peer, NULL if we failed | ||
144 | * @param publicKey public key of this peer, NULL if we failed | ||
145 | */ | ||
146 | typedef void | ||
147 | (*GNUNET_CORE_StartupCallback) (void *cls, | ||
148 | struct GNUNET_CORE_Handle * server, | ||
149 | const struct GNUNET_PeerIdentity * | ||
150 | my_identity, | ||
151 | const struct | ||
152 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | ||
153 | publicKey); | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Connect to the core service. Note that the connection may | ||
158 | * complete (or fail) asynchronously. | ||
159 | * | ||
160 | * @param sched scheduler to use | ||
161 | * @param cfg configuration to use | ||
162 | * @param timeout after how long should we give up trying to connect to the core service? | ||
163 | * @param cls closure for the various callbacks that follow (including handlers in the handlers array) | ||
164 | * @param init callback to call on timeout or once we have successfully | ||
165 | * connected to the core service | ||
166 | * @param connects function to call on peer connect, can be NULL | ||
167 | * @param disconnects function to call on peer disconnect / timeout, can be NULL | ||
168 | * @param bfc function to call to fill up spare bandwidth, can be NULL | ||
169 | * @param inbound_notify function to call for all inbound messages, can be NULL | ||
170 | * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the | ||
171 | * GNUNET_MessageHeader and hence we do not need to give it the full message; | ||
172 | * can be used to improve efficiency, ignored if inbound_notify is NULLL | ||
173 | * @param outbound_notify function to call for all outbound messages, can be NULL | ||
174 | * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the | ||
175 | * GNUNET_MessageHeader and hence we do not need to give it the full message | ||
176 | * can be used to improve efficiency, ignored if outbound_notify is NULLL | ||
177 | * @param handlers callbacks for messages we care about, NULL-terminated | ||
178 | */ | ||
179 | void | ||
180 | GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched, | ||
181 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
182 | struct GNUNET_TIME_Relative timeout, | ||
183 | void *cls, | ||
184 | GNUNET_CORE_StartupCallback init, | ||
185 | GNUNET_CORE_ClientEventHandler connects, | ||
186 | GNUNET_CORE_ClientEventHandler disconnects, | ||
187 | GNUNET_CORE_BufferFillCallback bfc, | ||
188 | GNUNET_CORE_MessageCallback inbound_notify, | ||
189 | int inbound_hdr_only, | ||
190 | GNUNET_CORE_MessageCallback outbound_notify, | ||
191 | int outbound_hdr_only, | ||
192 | const struct GNUNET_CORE_MessageHandler *handlers); | ||
193 | |||
194 | |||
195 | /** | ||
196 | * Disconnect from the core service. | ||
197 | * | ||
198 | * @param handle connection to core to disconnect | ||
199 | */ | ||
200 | void GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle); | ||
201 | |||
202 | |||
203 | /** | ||
204 | * Function called with statistics about the given peer. | ||
205 | * | ||
206 | * @param peer identifies the peer | ||
207 | * @param latency current latency estimate, "FOREVER" if we have been | ||
208 | * disconnected | ||
209 | * @param bpm_in set to the current bandwidth limit (receiving) for this peer | ||
210 | * @param bpm_out set to the current bandwidth limit (sending) for this peer | ||
211 | * @param amount set to the amount that was actually reserved or unreserved | ||
212 | * @param preference current traffic preference for the given peer | ||
213 | */ | ||
214 | typedef void | ||
215 | (*GNUNET_CORE_PeerConfigurationInfoCallback) (void *cls, | ||
216 | const struct | ||
217 | GNUNET_PeerIdentity * peer, | ||
218 | unsigned int bpm_in, | ||
219 | unsigned int bpm_out, | ||
220 | struct GNUNET_TIME_Relative | ||
221 | latency, int amount, | ||
222 | double preference); | ||
223 | |||
224 | |||
225 | /** | ||
226 | * Obtain statistics and/or change preferences for the given peer. | ||
227 | * | ||
228 | * @param handle connection to core to use | ||
229 | * @param peer identifies the peer | ||
230 | * @param timeout after how long should we give up (and call "info" with NULL | ||
231 | * for "peer" to signal an error)? | ||
232 | * @param bpm_out set to the current bandwidth limit (sending) for this peer, | ||
233 | * caller should set "bpm_out" to "-1" to avoid changing | ||
234 | * the current value; otherwise "bpm_out" will be lowered to | ||
235 | * the specified value; passing a pointer to "0" can be used to force | ||
236 | * us to disconnect from the peer; "bpm_out" might not increase | ||
237 | * as specified since the upper bound is generally | ||
238 | * determined by the other peer! | ||
239 | * @param amount reserve N bytes for receiving, negative | ||
240 | * amounts can be used to undo a (recent) reservation; | ||
241 | * @param preference increase incoming traffic share preference by this amount; | ||
242 | * in the absence of "amount" reservations, we use this | ||
243 | * preference value to assign proportional bandwidth shares | ||
244 | * to all connected peers | ||
245 | * @param info function to call with the resulting configuration information | ||
246 | * @param info_cls closure for info | ||
247 | */ | ||
248 | void | ||
249 | GNUNET_CORE_peer_configure (struct GNUNET_CORE_Handle *handle, | ||
250 | const struct GNUNET_PeerIdentity *peer, | ||
251 | struct GNUNET_TIME_Relative timeout, | ||
252 | unsigned int bpm_out, | ||
253 | int amount, | ||
254 | double preference, | ||
255 | GNUNET_CORE_PeerConfigurationInfoCallback info, | ||
256 | void *info_cls); | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Handle for a transmission request. | ||
261 | */ | ||
262 | struct GNUNET_CORE_TransmitHandle; | ||
263 | |||
264 | |||
265 | /** | ||
266 | * Ask the core to call "notify" once it is ready to transmit the | ||
267 | * given number of bytes to the specified "target". If we are not yet | ||
268 | * connected to the specified peer, a call to this function will cause | ||
269 | * us to try to establish a connection. | ||
270 | * | ||
271 | * @param handle connection to core service | ||
272 | * @param priority how important is the message? | ||
273 | * @param maxdelay how long can the message wait? | ||
274 | * @param target who should receive the message, | ||
275 | * use NULL for this peer (loopback) | ||
276 | * @param notify_size how many bytes of buffer space does notify want? | ||
277 | * @param notify function to call when buffer space is available | ||
278 | * @param notify_cls closure for notify | ||
279 | * @return non-NULL if the notify callback was queued, | ||
280 | * NULL if we can not even queue the request (insufficient | ||
281 | * memory); if NULL is returned, "notify" will NOT be called. | ||
282 | */ | ||
283 | struct GNUNET_CORE_TransmitHandle *GNUNET_CORE_notify_transmit_ready (struct | ||
284 | GNUNET_CORE_Handle | ||
285 | *handle, | ||
286 | unsigned | ||
287 | int | ||
288 | priority, | ||
289 | struct | ||
290 | GNUNET_TIME_Relative | ||
291 | maxdelay, | ||
292 | const | ||
293 | struct | ||
294 | GNUNET_PeerIdentity | ||
295 | *target, | ||
296 | size_t | ||
297 | notify_size, | ||
298 | GNUNET_NETWORK_TransmitReadyNotify | ||
299 | notify, | ||
300 | void | ||
301 | *notify_cls); | ||
302 | |||
303 | |||
304 | /** | ||
305 | * Cancel the specified transmission-ready notification. | ||
306 | * | ||
307 | * @param h handle that was returned by "notify_transmit_ready". | ||
308 | */ | ||
309 | void | ||
310 | GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle | ||
311 | *h); | ||
312 | |||
313 | |||
314 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
315 | { | ||
316 | #endif | ||
317 | #ifdef __cplusplus | ||
318 | } | ||
319 | #endif | ||
320 | |||
321 | /* ifndef GNUNET_CORE_SERVICE_H */ | ||
322 | #endif | ||
323 | /* end of gnunet_core_service.h */ | ||
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h new file mode 100644 index 000000000..361d244e2 --- /dev/null +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -0,0 +1,567 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 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 2, 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 include/gnunet_crypto_lib.h | ||
23 | * @brief cryptographic primitives for GNUnet | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | * @author Krista Bennett | ||
27 | * @author Gerd Knorr <kraxel@bytesex.org> | ||
28 | * @author Ioana Patrascu | ||
29 | * @author Tzvetan Horozov | ||
30 | */ | ||
31 | |||
32 | #ifndef GNUNET_CRYPTO_LIB_H | ||
33 | #define GNUNET_CRYPTO_LIB_H | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" | ||
37 | { | ||
38 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
39 | } | ||
40 | #endif | ||
41 | #endif | ||
42 | |||
43 | #include "gnunet_common.h" | ||
44 | #include "gnunet_scheduler_lib.h" | ||
45 | |||
46 | |||
47 | enum GNUNET_CRYPTO_Quality | ||
48 | { | ||
49 | GNUNET_CRYPTO_QUALITY_WEAK, | ||
50 | GNUNET_CRYPTO_QUALITY_STRONG | ||
51 | }; | ||
52 | |||
53 | |||
54 | /** | ||
55 | * @brief length of the sessionkey in bytes (256 BIT sessionkey) | ||
56 | */ | ||
57 | #define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8) | ||
58 | |||
59 | |||
60 | /** | ||
61 | * @brief Length of RSA encrypted data (2048 bit) | ||
62 | * | ||
63 | * We currently do not handle encryption of data | ||
64 | * that can not be done in a single call to the | ||
65 | * RSA methods (read: large chunks of data). | ||
66 | * We should never need that, as we can use | ||
67 | * the GNUNET_CRYPTO_hash for larger pieces of data for signing, | ||
68 | * and for encryption, we only need to encode sessionkeys! | ||
69 | */ | ||
70 | #define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256 | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Length of an RSA KEY (d,e,len), 2048 bit (=256 octests) key d, 2 byte e | ||
75 | */ | ||
76 | #define GNUNET_CRYPTO_RSA_KEY_LENGTH 258 | ||
77 | |||
78 | |||
79 | /** | ||
80 | * The private information of an RSA key pair. | ||
81 | */ | ||
82 | struct GNUNET_CRYPTO_RsaPrivateKey; | ||
83 | |||
84 | |||
85 | /** | ||
86 | * @brief 0-terminated ASCII encoding of a GNUNET_HashCode. | ||
87 | */ | ||
88 | struct GNUNET_CRYPTO_HashAsciiEncoded | ||
89 | { | ||
90 | unsigned char encoding[104]; | ||
91 | }; | ||
92 | |||
93 | |||
94 | |||
95 | /** | ||
96 | * @brief an RSA signature | ||
97 | */ | ||
98 | struct GNUNET_CRYPTO_RsaSignature | ||
99 | { | ||
100 | unsigned char sig[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH]; | ||
101 | }; | ||
102 | |||
103 | |||
104 | /** | ||
105 | * @brief header of what an RSA signature signs | ||
106 | * this must be followed by "size - 8" bytes of | ||
107 | * the actual signed data | ||
108 | */ | ||
109 | struct GNUNET_CRYPTO_RsaSignaturePurpose | ||
110 | { | ||
111 | /** | ||
112 | * How many bytes does this signature sign? | ||
113 | * (including this purpose header); in network | ||
114 | * byte order (!). | ||
115 | */ | ||
116 | uint32_t size GNUNET_PACKED; | ||
117 | |||
118 | /** | ||
119 | * What does this signature vouch for? This | ||
120 | * must contain a GNUNET_SIGNATURE_PURPOSE_XXX | ||
121 | * constant (from gnunet_signatures.h). In | ||
122 | * network byte order! | ||
123 | */ | ||
124 | uint32_t purpose GNUNET_PACKED; | ||
125 | |||
126 | }; | ||
127 | |||
128 | |||
129 | /** | ||
130 | * @brief A public key. | ||
131 | */ | ||
132 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | ||
133 | { | ||
134 | /** | ||
135 | * In big-endian, must be GNUNET_CRYPTO_RSA_KEY_LENGTH+4 | ||
136 | */ | ||
137 | uint16_t len GNUNET_PACKED; | ||
138 | |||
139 | /** | ||
140 | * Size of n in key; in big-endian! | ||
141 | */ | ||
142 | uint16_t sizen GNUNET_PACKED; | ||
143 | |||
144 | /** | ||
145 | * The key itself, contains n followed by e. | ||
146 | */ | ||
147 | unsigned char key[GNUNET_CRYPTO_RSA_KEY_LENGTH]; | ||
148 | |||
149 | /** | ||
150 | * Padding (must be 0) | ||
151 | */ | ||
152 | uint16_t padding GNUNET_PACKED; | ||
153 | }; | ||
154 | |||
155 | |||
156 | /** | ||
157 | * RSA Encrypted data. | ||
158 | */ | ||
159 | struct GNUNET_CRYPTO_RsaEncryptedData | ||
160 | { | ||
161 | unsigned char encoding[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH]; | ||
162 | }; | ||
163 | |||
164 | |||
165 | /** | ||
166 | * @brief type for session keys | ||
167 | */ | ||
168 | struct GNUNET_CRYPTO_AesSessionKey | ||
169 | { | ||
170 | /** | ||
171 | * Actual key. | ||
172 | */ | ||
173 | unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH]; | ||
174 | |||
175 | /** | ||
176 | * checksum! | ||
177 | */ | ||
178 | uint32_t crc32 GNUNET_PACKED; | ||
179 | }; | ||
180 | |||
181 | |||
182 | /** | ||
183 | * @brief IV for sym cipher | ||
184 | * | ||
185 | * NOTE: must be smaller (!) in size than the | ||
186 | * GNUNET_HashCode. | ||
187 | */ | ||
188 | struct GNUNET_CRYPTO_AesInitializationVector | ||
189 | { | ||
190 | unsigned char iv[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; | ||
191 | }; | ||
192 | |||
193 | |||
194 | /* **************** Functions and Macros ************* */ | ||
195 | |||
196 | |||
197 | /** | ||
198 | * Compute the CRC32 checksum for the first len | ||
199 | * bytes of the buffer. | ||
200 | * | ||
201 | * @param buf the data over which we're taking the CRC | ||
202 | * @param len the length of the buffer in bytes | ||
203 | * @return the resulting CRC32 checksum | ||
204 | */ | ||
205 | int GNUNET_CRYPTO_crc32_n (const void *buf, unsigned int len); | ||
206 | |||
207 | |||
208 | /** | ||
209 | * Produce a random value. | ||
210 | * | ||
211 | * @param i the upper limit (exclusive) for the random number | ||
212 | * @return a random value in the interval [0,i[. | ||
213 | */ | ||
214 | unsigned int GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality, | ||
215 | unsigned int i); | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Random on unsigned 64-bit values. We break them down into signed | ||
220 | * 32-bit values and reassemble the 64-bit random value bit-wise. | ||
221 | */ | ||
222 | unsigned long long GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | ||
223 | unsigned long long u); | ||
224 | |||
225 | |||
226 | /** | ||
227 | * Get an array with a random permutation of the | ||
228 | * numbers 0...n-1. | ||
229 | * @param mode GNUNET_CRYPTO_QUALITY_STRONG if the strong (but expensive) PRNG should be used, GNUNET_CRYPTO_QUALITY_WEAK otherwise | ||
230 | * @param n the size of the array | ||
231 | * @return the permutation array (allocated from heap) | ||
232 | */ | ||
233 | unsigned int *GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, | ||
234 | unsigned int n); | ||
235 | |||
236 | |||
237 | /** | ||
238 | * Create a new Session key. | ||
239 | */ | ||
240 | void GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey | ||
241 | *key); | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Check that a new session key is well-formed. | ||
246 | * | ||
247 | * @return GNUNET_OK if the key is valid | ||
248 | */ | ||
249 | int GNUNET_CRYPTO_aes_check_session_key (const struct | ||
250 | GNUNET_CRYPTO_AesSessionKey *key); | ||
251 | |||
252 | |||
253 | /** | ||
254 | * Encrypt a block with the public key of another | ||
255 | * host that uses the same cyper. | ||
256 | * | ||
257 | * @param block the block to encrypt | ||
258 | * @param len the size of the block | ||
259 | * @param sessionkey the key used to encrypt | ||
260 | * @param iv the initialization vector to use, use INITVALUE | ||
261 | * for streams. | ||
262 | * @returns the size of the encrypted block, -1 for errors | ||
263 | */ | ||
264 | int GNUNET_CRYPTO_aes_encrypt (const void *block, | ||
265 | uint16_t len, | ||
266 | const struct GNUNET_CRYPTO_AesSessionKey | ||
267 | *sessionkey, | ||
268 | const struct | ||
269 | GNUNET_CRYPTO_AesInitializationVector *iv, | ||
270 | void *result); | ||
271 | |||
272 | |||
273 | /** | ||
274 | * Decrypt a given block with the sessionkey. | ||
275 | * | ||
276 | * @param sessionkey the key used to decrypt | ||
277 | * @param block the data to decrypt, encoded as returned by encrypt | ||
278 | * @param size how big is the block? | ||
279 | * @param iv the initialization vector to use | ||
280 | * @param result address to store the result at | ||
281 | * @return -1 on failure, size of decrypted block on success | ||
282 | */ | ||
283 | int GNUNET_CRYPTO_aes_decrypt (const struct GNUNET_CRYPTO_AesSessionKey | ||
284 | *sessionkey, const void *block, uint16_t size, | ||
285 | const struct | ||
286 | GNUNET_CRYPTO_AesInitializationVector *iv, | ||
287 | void *result); | ||
288 | |||
289 | |||
290 | /** | ||
291 | * Convert GNUNET_CRYPTO_hash to ASCII encoding. | ||
292 | * @param block the GNUNET_CRYPTO_hash code | ||
293 | * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be | ||
294 | * safely cast to char*, a '\0' termination is set). | ||
295 | */ | ||
296 | void GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, | ||
297 | struct GNUNET_CRYPTO_HashAsciiEncoded | ||
298 | *result); | ||
299 | |||
300 | |||
301 | /** | ||
302 | * Convert ASCII encoding back to GNUNET_CRYPTO_hash | ||
303 | * @param enc the encoding | ||
304 | * @param result where to store the GNUNET_CRYPTO_hash code | ||
305 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding | ||
306 | */ | ||
307 | int GNUNET_CRYPTO_hash_from_string (const char *enc, | ||
308 | GNUNET_HashCode * result); | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Compute the distance between 2 hashcodes. | ||
313 | * The computation must be fast, not involve | ||
314 | * a.a or a.e (they're used elsewhere), and | ||
315 | * be somewhat consistent. And of course, the | ||
316 | * result should be a positive number. | ||
317 | * @return number between 0 and 65536 | ||
318 | */ | ||
319 | unsigned int GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | ||
320 | const GNUNET_HashCode * b); | ||
321 | |||
322 | |||
323 | /** | ||
324 | * Hash block of given size. | ||
325 | * @param block the data to GNUNET_CRYPTO_hash, length is given as a second argument | ||
326 | * @param ret pointer to where to write the hashcode | ||
327 | */ | ||
328 | void GNUNET_CRYPTO_hash (const void *block, unsigned int size, | ||
329 | GNUNET_HashCode * ret); | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Function called once the hash computation over the | ||
334 | * specified file has completed. | ||
335 | * | ||
336 | * @param cls closure | ||
337 | * @param res resulting hash, NULL on error | ||
338 | */ | ||
339 | typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls, | ||
340 | const GNUNET_HashCode * | ||
341 | res); | ||
342 | |||
343 | |||
344 | /** | ||
345 | * Compute the hash of an entire file. | ||
346 | * | ||
347 | * @param sched scheduler to use | ||
348 | * @param priority scheduling priority to use | ||
349 | * @param run_on_shutdown should we complete even on shutdown? | ||
350 | * @param filename name of file to hash | ||
351 | * @param blocksize number of bytes to process in one task | ||
352 | * @param callback function to call upon completion | ||
353 | * @param callback_cls closure for callback | ||
354 | */ | ||
355 | void GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, | ||
356 | enum GNUNET_SCHEDULER_Priority priority, | ||
357 | int run_on_shutdown, | ||
358 | const char *filename, | ||
359 | size_t blocksize, | ||
360 | GNUNET_CRYPTO_HashCompletedCallback callback, | ||
361 | void *callback_cls); | ||
362 | |||
363 | |||
364 | /** | ||
365 | * Create a random hash code. | ||
366 | */ | ||
367 | void GNUNET_CRYPTO_hash_create_random (GNUNET_HashCode * result); | ||
368 | |||
369 | |||
370 | /** | ||
371 | * compute result(delta) = b - a | ||
372 | */ | ||
373 | void GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | ||
374 | const GNUNET_HashCode * b, | ||
375 | GNUNET_HashCode * result); | ||
376 | |||
377 | |||
378 | /** | ||
379 | * compute result(b) = a + delta | ||
380 | */ | ||
381 | void GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | ||
382 | const GNUNET_HashCode * delta, | ||
383 | GNUNET_HashCode * result); | ||
384 | |||
385 | |||
386 | /** | ||
387 | * compute result = a ^ b | ||
388 | */ | ||
389 | void GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, | ||
390 | const GNUNET_HashCode * b, | ||
391 | GNUNET_HashCode * result); | ||
392 | |||
393 | |||
394 | /** | ||
395 | * Convert a hashcode into a key. | ||
396 | */ | ||
397 | void GNUNET_CRYPTO_hash_to_AES_key (const GNUNET_HashCode * hc, | ||
398 | struct GNUNET_CRYPTO_AesSessionKey *skey, | ||
399 | struct | ||
400 | GNUNET_CRYPTO_AesInitializationVector | ||
401 | *iv); | ||
402 | |||
403 | |||
404 | /** | ||
405 | * Obtain a bit from a hashcode. | ||
406 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | ||
407 | * @param bit index into the hashcode, [0...159] | ||
408 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | ||
409 | */ | ||
410 | int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, | ||
411 | unsigned int bit); | ||
412 | |||
413 | |||
414 | /** | ||
415 | * Compare function for HashCodes, producing a total ordering | ||
416 | * of all hashcodes. | ||
417 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | ||
418 | */ | ||
419 | int GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, | ||
420 | const GNUNET_HashCode * h2); | ||
421 | |||
422 | |||
423 | /** | ||
424 | * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target | ||
425 | * in the XOR metric (Kademlia). | ||
426 | * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. | ||
427 | */ | ||
428 | int GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | ||
429 | const GNUNET_HashCode * h2, | ||
430 | const GNUNET_HashCode * target); | ||
431 | |||
432 | |||
433 | /** | ||
434 | * Create a new private key. Caller must free return value. | ||
435 | */ | ||
436 | struct GNUNET_CRYPTO_RsaPrivateKey *GNUNET_CRYPTO_rsa_key_create (void); | ||
437 | |||
438 | |||
439 | /** | ||
440 | * Create a new private key by reading it from a file. If the | ||
441 | * files does not exist, create a new key and write it to the | ||
442 | * file. Caller must free return value. Note that this function | ||
443 | * can not guarantee that another process might not be trying | ||
444 | * the same operation on the same file at the same time. The | ||
445 | * caller must somehow know that the file either already exists | ||
446 | * with a valid key OR be sure that no other process is calling | ||
447 | * this function at the same time. If the contents of the file | ||
448 | * are invalid the old file is deleted and a fresh key is | ||
449 | * created. | ||
450 | * | ||
451 | * @return new private key, NULL on error (for example, | ||
452 | * permission denied) | ||
453 | */ | ||
454 | struct GNUNET_CRYPTO_RsaPrivateKey | ||
455 | *GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); | ||
456 | |||
457 | |||
458 | /** | ||
459 | * Deterministically (!) create a private key using only the | ||
460 | * given HashCode as input to the PRNG. | ||
461 | */ | ||
462 | struct GNUNET_CRYPTO_RsaPrivateKey | ||
463 | *GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * input); | ||
464 | |||
465 | |||
466 | /** | ||
467 | * Free memory occupied by the private key. | ||
468 | * @param hostkey pointer to the memory to free | ||
469 | */ | ||
470 | void GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); | ||
471 | |||
472 | |||
473 | /** | ||
474 | * Extract the public key of the host. | ||
475 | * @param result where to write the result. | ||
476 | */ | ||
477 | void GNUNET_CRYPTO_rsa_key_get_public (const struct | ||
478 | GNUNET_CRYPTO_RsaPrivateKey *hostkey, | ||
479 | struct | ||
480 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | ||
481 | *result); | ||
482 | |||
483 | |||
484 | /** | ||
485 | * Encrypt a block with the public key of another host that uses the | ||
486 | * same cyper. | ||
487 | * | ||
488 | * @param block the block to encrypt | ||
489 | * @param size the size of block | ||
490 | * @param publicKey the encoded public key used to encrypt | ||
491 | * @param target where to store the encrypted block | ||
492 | * @returns GNUNET_SYSERR on error, GNUNET_OK if ok | ||
493 | */ | ||
494 | int GNUNET_CRYPTO_rsa_encrypt (const void *block, | ||
495 | uint16_t size, | ||
496 | const struct | ||
497 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | ||
498 | *publicKey, | ||
499 | struct GNUNET_CRYPTO_RsaEncryptedData *target); | ||
500 | |||
501 | |||
502 | /** | ||
503 | * Decrypt a given block with the hostkey. | ||
504 | * | ||
505 | * @param key the key to use | ||
506 | * @param block the data to decrypt, encoded as returned by encrypt, not consumed | ||
507 | * @param result pointer to a location where the result can be stored | ||
508 | * @param size how many bytes of a result are expected? Must be exact. | ||
509 | * @returns the size of the decrypted block (that is, size) or -1 on error | ||
510 | */ | ||
511 | int GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | ||
512 | const struct GNUNET_CRYPTO_RsaEncryptedData | ||
513 | *block, void *result, uint16_t size); | ||
514 | |||
515 | |||
516 | /** | ||
517 | * Sign a given block. | ||
518 | * | ||
519 | * @param key private key to use for the signing | ||
520 | * @param purpose what to sign (size, purpose) | ||
521 | * @param result where to write the signature | ||
522 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | ||
523 | */ | ||
524 | int GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | ||
525 | const struct GNUNET_CRYPTO_RsaSignaturePurpose | ||
526 | *purpose, | ||
527 | struct GNUNET_CRYPTO_RsaSignature *result); | ||
528 | |||
529 | |||
530 | /** | ||
531 | * Verify signature. Note that the caller MUST have already | ||
532 | * checked that "validate->size" bytes are actually available. | ||
533 | * | ||
534 | * @param purpose what is the purpose that validate should have? | ||
535 | * @param validate block to validate (size, purpose, data) | ||
536 | * @param sig signature that is being validated | ||
537 | * @param publicKey public key of the signer | ||
538 | * @returns GNUNET_OK if ok, GNUNET_SYSERR if invalid | ||
539 | */ | ||
540 | int GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | ||
541 | const struct GNUNET_CRYPTO_RsaSignaturePurpose | ||
542 | *validate, | ||
543 | const struct GNUNET_CRYPTO_RsaSignature *sig, | ||
544 | const struct | ||
545 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | ||
546 | *publicKey); | ||
547 | |||
548 | |||
549 | |||
550 | /** | ||
551 | * This function should only be called in testcases | ||
552 | * where strong entropy gathering is not desired | ||
553 | * (for example, for hostkey generation). | ||
554 | */ | ||
555 | void GNUNET_CRYPTO_random_disable_entropy_gathering (void); | ||
556 | |||
557 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
558 | { | ||
559 | #endif | ||
560 | #ifdef __cplusplus | ||
561 | } | ||
562 | #endif | ||
563 | |||
564 | |||
565 | /* ifndef GNUNET_CRYPTO_LIB_H */ | ||
566 | #endif | ||
567 | /* end of gnunet_crypto_lib.h */ | ||
diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h new file mode 100644 index 000000000..b20c6b100 --- /dev/null +++ b/src/include/gnunet_datastore_service.h | |||
@@ -0,0 +1,187 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_datastore_service.h | ||
23 | * @brief API that can be used manage the | ||
24 | * datastore for files stored on a GNUnet node; | ||
25 | * note that the datastore is NOT responsible for | ||
26 | * on-demand encoding, that is achieved using | ||
27 | * a special kind of entry. | ||
28 | * @author Christian Grothoff | ||
29 | */ | ||
30 | |||
31 | #ifndef GNUNET_DATASTORE_SERVICE_H | ||
32 | #define GNUNET_DATASTORE_SERVICE_H | ||
33 | |||
34 | #include "gnunet_core.h" | ||
35 | |||
36 | #ifdef __cplusplus | ||
37 | extern "C" | ||
38 | { | ||
39 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
40 | } | ||
41 | #endif | ||
42 | #endif | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Handle to the datastore service. | ||
47 | */ | ||
48 | struct GNUNET_DATASTORE_Handle; | ||
49 | |||
50 | |||
51 | /** | ||
52 | * An iterator over a set of items stored in the datastore. | ||
53 | * | ||
54 | * @param cls closure | ||
55 | * @param key key for the content | ||
56 | * @param size number of bytes in data | ||
57 | * @param data content stored | ||
58 | * @param type type of the content | ||
59 | * @param priority priority of the content | ||
60 | * @param anonymity anonymity-level for the content | ||
61 | * @param expiration expiration time for the content | ||
62 | * @param uid unique identifier for the datum; | ||
63 | * maybe 0 if no unique identifier is available | ||
64 | * | ||
65 | * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue, | ||
66 | * GNUNET_NO to delete the item and continue (if supported) | ||
67 | */ | ||
68 | typedef int (*GNUNET_DATASTORE_Iterator) (void *cls, | ||
69 | const GNUNET_HashCode * key, | ||
70 | uint32_t size, | ||
71 | const void *data, | ||
72 | uint32_t type, | ||
73 | uint32_t priority, | ||
74 | uint32_t anonymity, | ||
75 | struct GNUNET_TIME_Absolute | ||
76 | expiration, unsigned long long uid); | ||
77 | |||
78 | /** | ||
79 | * Connect to the datastore service. | ||
80 | * | ||
81 | * @param cfg configuration to use | ||
82 | * @param sched scheduler to use | ||
83 | * @return handle to use to access the service | ||
84 | */ | ||
85 | struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct | ||
86 | GNUNET_CONFIGURATION_Handle | ||
87 | *cfg, | ||
88 | struct | ||
89 | GNUNET_SCHEDULER_Handle | ||
90 | *sched); | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Disconnect from the datastore service (and free | ||
95 | * associated resources). | ||
96 | * @param h handle to the datastore | ||
97 | */ | ||
98 | void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h); | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Get the current on-disk size of the datastore. | ||
103 | * @param h handle to the datastore | ||
104 | * @return size estimate, -1 if datastore is not available (yet) | ||
105 | */ | ||
106 | unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h); | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Store an item in the datastore. If the item is already present, | ||
111 | * the priorities are summed up and the higher expiration time and | ||
112 | * lower anonymity level is used. | ||
113 | * | ||
114 | * @param h handle to the datastore | ||
115 | * @param key key for the value | ||
116 | * @param size number of bytes in data | ||
117 | * @param data content stored | ||
118 | * @param type type of the content | ||
119 | * @param priority priority of the content | ||
120 | * @param anonymity anonymity-level for the content | ||
121 | * @param expiration expiration time for the content | ||
122 | */ | ||
123 | void | ||
124 | GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | ||
125 | const GNUNET_HashCode * key, | ||
126 | uint32_t size, | ||
127 | const void *data, | ||
128 | unit32_t type, | ||
129 | uint32_t priority, | ||
130 | uint32_t anonymity, | ||
131 | struct GNUNET_TIME_Absolute expiration); | ||
132 | |||
133 | /** | ||
134 | * Iterate over the results for a particular key | ||
135 | * in the datastore. | ||
136 | * | ||
137 | * @param h handle to the datastore | ||
138 | * @param key maybe NULL (to match all entries) | ||
139 | * @param type desired type, 0 for any | ||
140 | * @param iter function to call on each matching value; | ||
141 | * will be called once with a NULL value at the end | ||
142 | * @param iter_cls closure for iter | ||
143 | */ | ||
144 | void | ||
145 | GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h, | ||
146 | const GNUNET_HashCode * key, | ||
147 | uint32_t type, | ||
148 | GNUNET_DATASTORE_Iterator iter, void *iter_cls); | ||
149 | |||
150 | |||
151 | /** | ||
152 | * Get a random value from the datastore. | ||
153 | * | ||
154 | * @param h handle to the datastore | ||
155 | * @param iter function to call on each matching value; | ||
156 | * will be called exactly once; if no values | ||
157 | * are available, the value will be NULL. | ||
158 | * @param iter_cls closure for iter | ||
159 | */ | ||
160 | void | ||
161 | GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h, | ||
162 | GNUNET_DATASTORE_Iterator iter, void *iter_cls); | ||
163 | |||
164 | |||
165 | /** | ||
166 | * Explicitly remove some content from the database. | ||
167 | * | ||
168 | * @param h handle to the datastore | ||
169 | * @param key key for the value | ||
170 | * @param size number of bytes in data | ||
171 | * @param data content stored | ||
172 | */ | ||
173 | void | ||
174 | GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, | ||
175 | const GNUNET_HashCode * key, | ||
176 | uint32_t size, const void *data); | ||
177 | |||
178 | |||
179 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
180 | { | ||
181 | #endif | ||
182 | #ifdef __cplusplus | ||
183 | } | ||
184 | #endif | ||
185 | |||
186 | /* end of gnunet_datastore_service.h */ | ||
187 | #endif | ||
diff --git a/src/include/gnunet_directories.h.in b/src/include/gnunet_directories.h.in new file mode 100644 index 000000000..b05b6d9ce --- /dev/null +++ b/src/include/gnunet_directories.h.in | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006 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 2, 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 include/gnunet_directories.h | ||
23 | * @brief directories and files in GNUnet (default locations) | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_DIRECTORIES | ||
29 | #define GNUNET_DIRECTORIES | ||
30 | |||
31 | #define GNUNET_DEFAULT_CLIENT_CONFIG_FILE "@GN_USER_HOME_DIR@/gnunet.conf" | ||
32 | #define GNUNET_DEFAULT_DAEMON_CONFIG_FILE "@GN_DAEMON_CONFIG_DIR@/gnunetd.conf" | ||
33 | |||
34 | #endif | ||
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h new file mode 100644 index 000000000..3886be7c9 --- /dev/null +++ b/src/include/gnunet_disk_lib.h | |||
@@ -0,0 +1,279 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006 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 2, 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 include/gnunet_disk_lib.h | ||
23 | * @brief disk IO apis | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_DISK_LIB_H | ||
27 | #define GNUNET_DISK_LIB_H | ||
28 | |||
29 | #include "gnunet_configuration_lib.h" | ||
30 | #include "gnunet_scheduler_lib.h" | ||
31 | |||
32 | /* we need size_t, and since it can be both unsigned int | ||
33 | or unsigned long long, this IS platform dependent; | ||
34 | but "stdlib.h" should be portable 'enough' to be | ||
35 | unconditionally available... */ | ||
36 | #include <stdlib.h> | ||
37 | |||
38 | #ifdef __cplusplus | ||
39 | extern "C" | ||
40 | { | ||
41 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
42 | } | ||
43 | #endif | ||
44 | #endif | ||
45 | |||
46 | /** | ||
47 | * Get the number of blocks that are left on the partition that | ||
48 | * contains the given file (for normal users). | ||
49 | * | ||
50 | * @param part a file on the partition to check | ||
51 | * @return -1 on errors, otherwise the number of free blocks | ||
52 | */ | ||
53 | long GNUNET_DISK_get_blocks_available (const char *part); | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Check that fil corresponds to a filename | ||
58 | * (of a file that exists and that is not a directory). | ||
59 | * | ||
60 | * @returns GNUNET_YES if yes, GNUNET_NO if not a file, GNUNET_SYSERR if something | ||
61 | * else (will print an error message in that case, too). | ||
62 | */ | ||
63 | int GNUNET_DISK_file_test (const char *fil); | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Get the size of the file (or directory) | ||
68 | * of the given file (in bytes). | ||
69 | * | ||
70 | * @param includeSymLinks should symbolic links be | ||
71 | * included? | ||
72 | * | ||
73 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
74 | */ | ||
75 | int GNUNET_DISK_file_size (const char *filename, | ||
76 | unsigned long long *size, int includeSymLinks); | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Wrapper around "open()". Opens a file. | ||
81 | * | ||
82 | * @return file handle, -1 on error | ||
83 | */ | ||
84 | int GNUNET_DISK_file_open (const char *filename, int oflag, ...); | ||
85 | |||
86 | |||
87 | /** | ||
88 | * Wrapper around "close()". Closes a file. | ||
89 | */ | ||
90 | void GNUNET_DISK_file_close (const char *filename, int fd); | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Read the contents of a binary file into a buffer. | ||
95 | * @param fileName the name of the file, not freed, | ||
96 | * must already be expanded! | ||
97 | * @param len the maximum number of bytes to read | ||
98 | * @param result the buffer to write the result to | ||
99 | * @return the number of bytes read on success, -1 on failure | ||
100 | */ | ||
101 | int GNUNET_DISK_file_read (const char *fileName, int len, void *result); | ||
102 | |||
103 | |||
104 | /** | ||
105 | * Write a buffer to a file. | ||
106 | * @param fileName the name of the file, NOT freed! | ||
107 | * @param buffer the data to write | ||
108 | * @param n number of bytes to write | ||
109 | * @param mode the mode for file permissions | ||
110 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
111 | */ | ||
112 | int GNUNET_DISK_file_write (const char *fileName, | ||
113 | const void *buffer, unsigned int n, | ||
114 | const char *mode); | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Copy a file. | ||
119 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
120 | */ | ||
121 | int GNUNET_DISK_file_copy (const char *src, const char *dst); | ||
122 | |||
123 | |||
124 | /** | ||
125 | * Scan a directory for files. The name of the directory | ||
126 | * must be expanded first (!). | ||
127 | * | ||
128 | * @param dirName the name of the directory | ||
129 | * @param callback the method to call for each file | ||
130 | * @param data argument to pass to callback | ||
131 | * @return the number of files found, -1 on error | ||
132 | */ | ||
133 | int GNUNET_DISK_directory_scan (const char *dirName, | ||
134 | GNUNET_FileNameCallback callback, void *data); | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Opaque handle used for iterating over a directory. | ||
139 | */ | ||
140 | struct GNUNET_DISK_DirectoryIterator; | ||
141 | |||
142 | |||
143 | /** | ||
144 | * Function called to iterate over a directory. | ||
145 | * | ||
146 | * @param cls closure | ||
147 | * @param di argument to pass to "GNUNET_DISK_directory_iterator_next" to | ||
148 | * get called on the next entry (or finish cleanly) | ||
149 | * @param filename complete filename (absolute path) | ||
150 | * @param dirname directory name (absolute path) | ||
151 | */ | ||
152 | typedef void (*GNUNET_DISK_DirectoryIteratorCallback) (void *cls, | ||
153 | struct | ||
154 | GNUNET_DISK_DirectoryIterator | ||
155 | * di, | ||
156 | const char *filename, | ||
157 | const char *dirname); | ||
158 | |||
159 | |||
160 | /** | ||
161 | * This function must be called during the DiskIteratorCallback | ||
162 | * (exactly once) to schedule the task to process the next | ||
163 | * filename in the directory (if there is one). | ||
164 | * | ||
165 | * @param iter opaque handle for the iterator | ||
166 | * @param can set to GNUNET_YES to terminate the iteration early | ||
167 | * @return GNUNET_YES if iteration will continue, | ||
168 | * GNUNET_NO if this was the last entry (and iteration is complete), | ||
169 | * GNUNET_SYSERR if "can" was YES | ||
170 | */ | ||
171 | int GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator | ||
172 | *iter, int can); | ||
173 | |||
174 | |||
175 | /** | ||
176 | * Scan a directory for files using the scheduler to run a task for | ||
177 | * each entry. The name of the directory must be expanded first (!). | ||
178 | * If a scheduler does not need to be used, GNUNET_DISK_directory_scan | ||
179 | * may provide a simpler API. | ||
180 | * | ||
181 | * @param sched scheduler to use | ||
182 | * @param prio priority to use | ||
183 | * @param dirName the name of the directory | ||
184 | * @param callback the method to call for each file | ||
185 | * @param callback_cls closure for callback | ||
186 | */ | ||
187 | void GNUNET_DISK_directory_iterator_start (struct GNUNET_SCHEDULER_Handle | ||
188 | *sched, | ||
189 | enum GNUNET_SCHEDULER_Priority | ||
190 | prio, const char *dirName, | ||
191 | GNUNET_DISK_DirectoryIteratorCallback | ||
192 | callback, void *callback_cls); | ||
193 | |||
194 | |||
195 | /** | ||
196 | * Create the directory structure for storing | ||
197 | * a file. | ||
198 | * | ||
199 | * @param filename name of a file in the directory | ||
200 | * @returns GNUNET_OK on success, GNUNET_SYSERR on failure, | ||
201 | * GNUNET_NO if directory exists but is not writeable | ||
202 | */ | ||
203 | int GNUNET_DISK_directory_create_for_file (const char *filename); | ||
204 | |||
205 | |||
206 | /** | ||
207 | * Test if fil is a directory that can be accessed. | ||
208 | * Will not print an error message if the directory | ||
209 | * does not exist. Will log errors if GNUNET_SYSERR is | ||
210 | * returned. | ||
211 | * | ||
212 | * @return GNUNET_YES if yes, GNUNET_NO if does not exist, GNUNET_SYSERR | ||
213 | * on any error and if exists but not directory | ||
214 | */ | ||
215 | int GNUNET_DISK_directory_test (const char *fil); | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Remove all files in a directory (rm -rf). Call with | ||
220 | * caution. | ||
221 | * | ||
222 | * @param fileName the file to remove | ||
223 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
224 | */ | ||
225 | int GNUNET_DISK_directory_remove (const char *fileName); | ||
226 | |||
227 | |||
228 | /** | ||
229 | * Implementation of "mkdir -p" | ||
230 | * | ||
231 | * @param dir the directory to create | ||
232 | * @returns GNUNET_SYSERR on failure, GNUNET_OK otherwise | ||
233 | */ | ||
234 | int GNUNET_DISK_directory_create (const char *dir); | ||
235 | |||
236 | |||
237 | /** | ||
238 | * @brief Removes special characters as ':' from a filename. | ||
239 | * @param fn the filename to canonicalize | ||
240 | */ | ||
241 | void GNUNET_DISK_filename_canonicalize (char *fn); | ||
242 | |||
243 | |||
244 | /** | ||
245 | * @brief Change owner of a file | ||
246 | * @param filename file to change | ||
247 | * @param user new owner of the file | ||
248 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
249 | */ | ||
250 | int GNUNET_DISK_file_change_owner (const char *filename, const char *user); | ||
251 | |||
252 | |||
253 | /** | ||
254 | * Construct full path to a file inside of the private | ||
255 | * directory used by GNUnet. Also creates the corresponding | ||
256 | * directory. If the resulting name is supposed to be | ||
257 | * a directory, end the last argument in '/' (or pass | ||
258 | * DIR_SEPARATOR_STR as the last argument before NULL). | ||
259 | * | ||
260 | * @param serviceName name of the service asking | ||
261 | * @param varargs is NULL-terminated list of | ||
262 | * path components to append to the | ||
263 | * private directory name. | ||
264 | * @return the constructed filename | ||
265 | */ | ||
266 | char *GNUNET_DISK_get_home_filename (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
267 | const char *serviceName, ...); | ||
268 | |||
269 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
270 | { | ||
271 | #endif | ||
272 | #ifdef __cplusplus | ||
273 | } | ||
274 | #endif | ||
275 | |||
276 | |||
277 | /* ifndef GNUNET_DISK_LIB_H */ | ||
278 | #endif | ||
279 | /* end of gnunet_disk_lib.h */ | ||
diff --git a/src/include/gnunet_fragmentation_lib.h b/src/include/gnunet_fragmentation_lib.h new file mode 100644 index 000000000..5089fae6a --- /dev/null +++ b/src/include/gnunet_fragmentation_lib.h | |||
@@ -0,0 +1,113 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 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 2, 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 | * @file include/gnunet_fragmentation_lib.h | ||
22 | * @brief library to help fragment messages | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_FRAGMENTATION_LIB_H | ||
27 | #define GNUNET_FRAGMENTATION_LIB_H | ||
28 | |||
29 | #include "gnunet_common.h" | ||
30 | #include "gnunet_statistics_service.h" | ||
31 | |||
32 | #ifdef __cplusplus | ||
33 | extern "C" | ||
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | /** | ||
41 | * Function that is called with messages | ||
42 | * created by the fragmentation module. | ||
43 | * | ||
44 | * @param cls closure | ||
45 | * @param msg the message that was created | ||
46 | */ | ||
47 | typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls, | ||
48 | const struct | ||
49 | GNUNET_MessageHeader * msg); | ||
50 | |||
51 | |||
52 | /** | ||
53 | * Fragment an over-sized message. | ||
54 | * | ||
55 | * @param msg the message to fragment | ||
56 | * @param mtu the maximum message size | ||
57 | * @param proc function to call for each fragment | ||
58 | * @param proc_cls closure for proc | ||
59 | */ | ||
60 | void GNUNET_FRAGMENT_fragment (const struct GNUNET_MessageHeader *msg, | ||
61 | uint16_t mtu, | ||
62 | GNUNET_FRAGMENT_MessageProcessor proc, | ||
63 | void *proc_cls); | ||
64 | |||
65 | /** | ||
66 | * Defragmentation context. | ||
67 | */ | ||
68 | struct GNUNET_FRAGMENT_Context; | ||
69 | |||
70 | /** | ||
71 | * Create a defragmentation context. | ||
72 | * | ||
73 | * @param stats statistics context | ||
74 | * @param proc function to call with defragmented messages | ||
75 | * @param proc_cls closure for proc | ||
76 | * @return the defragmentation context | ||
77 | */ | ||
78 | struct GNUNET_FRAGMENT_Context *GNUNET_FRAGMENT_context_create (struct | ||
79 | GNUNET_STATISTICS_Handle | ||
80 | *stats, | ||
81 | GNUNET_FRAGMENT_MessageProcessor | ||
82 | proc, | ||
83 | void | ||
84 | *proc_cls); | ||
85 | |||
86 | |||
87 | /** | ||
88 | * Destroy the given defragmentation context. | ||
89 | */ | ||
90 | void GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *ctx); | ||
91 | |||
92 | |||
93 | /** | ||
94 | * We have received a fragment. Process it. | ||
95 | * | ||
96 | * @param ctx the context | ||
97 | * @param sender who transmitted the fragment | ||
98 | * @param msg the message that was received | ||
99 | */ | ||
100 | void GNUNET_FRAGMENT_process (struct GNUNET_FRAGMENT_Context *ctx, | ||
101 | const struct GNUNET_PeerIdentity *sender, | ||
102 | const struct GNUNET_MessageHeader *msg); | ||
103 | |||
104 | |||
105 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
106 | { | ||
107 | #endif | ||
108 | #ifdef __cplusplus | ||
109 | } | ||
110 | #endif | ||
111 | |||
112 | /* end of gnunet_fragmentation_lib.h */ | ||
113 | #endif | ||
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h new file mode 100644 index 000000000..722155568 --- /dev/null +++ b/src/include/gnunet_getopt_lib.h | |||
@@ -0,0 +1,251 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 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 2, 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 include/gnunet_getopt_lib.h | ||
23 | * @brief command line parsing and --help formatting | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_GETOPT_LIB_H | ||
29 | #define GNUNET_GETOPT_LIB_H | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" | ||
33 | { | ||
34 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
35 | } | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | #include "gnunet_configuration_lib.h" | ||
40 | |||
41 | /** | ||
42 | * @brief General context for command line processors. | ||
43 | */ | ||
44 | struct GNUNET_GETOPT_CommandLineProcessorContext | ||
45 | { | ||
46 | |||
47 | /** | ||
48 | * Name of the application | ||
49 | */ | ||
50 | const char *binaryName; | ||
51 | |||
52 | /** | ||
53 | * Name of application with option summary | ||
54 | */ | ||
55 | const char *binaryOptions; | ||
56 | |||
57 | /** | ||
58 | * Array with all command line options. | ||
59 | */ | ||
60 | const struct GNUNET_GETOPT_CommandLineOption *allOptions; | ||
61 | |||
62 | /** | ||
63 | * For configuration | ||
64 | */ | ||
65 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
66 | |||
67 | /** | ||
68 | * Original command line | ||
69 | */ | ||
70 | char *const *argv; | ||
71 | |||
72 | /** | ||
73 | * Total number of argv's. | ||
74 | */ | ||
75 | unsigned int argc; | ||
76 | |||
77 | /** | ||
78 | * Current argument. | ||
79 | */ | ||
80 | unsigned int currentArgument; | ||
81 | |||
82 | }; | ||
83 | |||
84 | /** | ||
85 | * @brief Process a command line option | ||
86 | * | ||
87 | * @param ctx context for all options | ||
88 | * @param scls specific closure (for this processor) | ||
89 | * @param option long name of the option (i.e. "config" for --config) | ||
90 | * @param value argument, NULL if none was given | ||
91 | * @return GNUNET_OK to continue processing other options, GNUNET_SYSERR to abort | ||
92 | */ | ||
93 | typedef | ||
94 | int (*GNUNET_GETOPT_CommandLineOptionProcessor) (struct | ||
95 | GNUNET_GETOPT_CommandLineProcessorContext | ||
96 | * ctx, void *scls, | ||
97 | const char *option, | ||
98 | const char *value); | ||
99 | |||
100 | /** | ||
101 | * @brief Definition of a command line option. | ||
102 | */ | ||
103 | struct GNUNET_GETOPT_CommandLineOption | ||
104 | { | ||
105 | |||
106 | /** | ||
107 | * Short name of the option (use '\0' for none). | ||
108 | */ | ||
109 | const char shortName; | ||
110 | |||
111 | /** | ||
112 | * Long name of the option (may not be NULL) | ||
113 | */ | ||
114 | const char *name; | ||
115 | |||
116 | /** | ||
117 | * Name of the argument for the user in help text | ||
118 | */ | ||
119 | const char *argumentHelp; | ||
120 | |||
121 | /** | ||
122 | * Help text for the option (description) | ||
123 | */ | ||
124 | const char *description; | ||
125 | |||
126 | /** | ||
127 | * Is an argument required? 0: GNUNET_NO (includes optional), 1: GNUNET_YES. | ||
128 | */ | ||
129 | int require_argument; | ||
130 | |||
131 | /** | ||
132 | * Handler for the option. | ||
133 | */ | ||
134 | GNUNET_GETOPT_CommandLineOptionProcessor processor; | ||
135 | |||
136 | /** | ||
137 | * Specific closure to pass to the processor. | ||
138 | */ | ||
139 | void *scls; | ||
140 | |||
141 | }; | ||
142 | |||
143 | /** | ||
144 | * Macro defining the option to print the command line | ||
145 | * help text. | ||
146 | * | ||
147 | * @param about string with brief description of the application | ||
148 | */ | ||
149 | #define GNUNET_GETOPT_OPTION_HELP(about) \ | ||
150 | { 'h', "help", (const char *) NULL, gettext_noop("print this help"), 0, &GNUNET_GETOPT_format_help_, (void *) about } | ||
151 | |||
152 | /** | ||
153 | * Macro defining the option to print the version of | ||
154 | * the application | ||
155 | * | ||
156 | * @param version string with the version number | ||
157 | */ | ||
158 | #define GNUNET_GETOPT_OPTION_VERSION(version) \ | ||
159 | { 'v', "version", (const char *) NULL, gettext_noop("print the version number"), 0, &GNUNET_GETOPT_print_version_, (void *) version } | ||
160 | |||
161 | /** | ||
162 | * Get the log level | ||
163 | */ | ||
164 | #define GNUNET_GETOPT_OPTION_LOGFILE(logfn) \ | ||
165 | { 'l', "logfile", "LOGFILE", gettext_noop("configure logging to write logs to LOGFILE"), 1, &GNUNET_GETOPT_set_string, (void *) logfn } | ||
166 | |||
167 | /** | ||
168 | * Set the configuration option for logging. | ||
169 | */ | ||
170 | #define GNUNET_GETOPT_OPTION_LOGLEVEL(loglev) \ | ||
171 | { 'L', "log", "LOGLEVEL", gettext_noop("configure logging to use LOGLEVEL"), 1, &GNUNET_GETOPT_set_string, (void *) loglev } | ||
172 | |||
173 | /** | ||
174 | * Get number of verbose flags | ||
175 | */ | ||
176 | #define GNUNET_GETOPT_OPTION_VERBOSE(level) \ | ||
177 | { 'V', "verbose", (const char *) NULL, gettext_noop("be verbose"), 0, &GNUNET_GETOPT_increment_value, (void *) level } | ||
178 | |||
179 | /** | ||
180 | * Get configuration file name | ||
181 | */ | ||
182 | #define GNUNET_GETOPT_OPTION_CFG_FILE(fn) \ | ||
183 | { 'c', "config", "FILENAME", gettext_noop("use configuration file FILENAME"), 1, &GNUNET_GETOPT_set_string, (void *) fn } | ||
184 | |||
185 | /** | ||
186 | * Marker to end the list of options. | ||
187 | */ | ||
188 | #define GNUNET_GETOPT_OPTION_END \ | ||
189 | { '\0', NULL, NULL, NULL, 0, NULL, NULL } | ||
190 | |||
191 | /** | ||
192 | * Parse the command line. | ||
193 | * | ||
194 | * @param binaryName name of the binary / application with options | ||
195 | * @param cfg for storing/accessing configuration data | ||
196 | * @param allOptions defined options and handlers | ||
197 | * @param argc number of arguments | ||
198 | * @param argv actual arguments | ||
199 | * @return index into argv with first non-option | ||
200 | * argument, or GNUNET_SYSERR on error | ||
201 | */ | ||
202 | int GNUNET_GETOPT_run (const char *binaryName, | ||
203 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
204 | const struct GNUNET_GETOPT_CommandLineOption | ||
205 | *allOptions, unsigned int argc, char *const *argv); | ||
206 | |||
207 | int GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext | ||
208 | *ctx, void *scls, const char *option, | ||
209 | const char *value); | ||
210 | |||
211 | int GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext | ||
212 | *ctx, void *scls, const char *option, | ||
213 | const char *value); | ||
214 | |||
215 | int GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext | ||
216 | *ctx, void *scls, const char *option, | ||
217 | const char *value); | ||
218 | |||
219 | int GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext | ||
220 | *ctx, void *scls, const char *option, | ||
221 | const char *value); | ||
222 | |||
223 | int | ||
224 | GNUNET_GETOPT_increment_value (struct | ||
225 | GNUNET_GETOPT_CommandLineProcessorContext *ctx, | ||
226 | void *scls, const char *option, | ||
227 | const char *value); | ||
228 | |||
229 | /* *************** internal prototypes - use macros above! ************* */ | ||
230 | |||
231 | int GNUNET_GETOPT_format_help_ (struct | ||
232 | GNUNET_GETOPT_CommandLineProcessorContext | ||
233 | *ctx, void *scls, const char *option, | ||
234 | const char *value); | ||
235 | |||
236 | int GNUNET_GETOPT_print_version_ (struct | ||
237 | GNUNET_GETOPT_CommandLineProcessorContext | ||
238 | *ctx, void *scls, const char *option, | ||
239 | const char *value); | ||
240 | |||
241 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
242 | { | ||
243 | #endif | ||
244 | #ifdef __cplusplus | ||
245 | } | ||
246 | #endif | ||
247 | |||
248 | |||
249 | /* ifndef GNUNET_GETOPT_LIB_H */ | ||
250 | #endif | ||
251 | /* end of gnunet_getopt_lib.h */ | ||
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h new file mode 100644 index 000000000..2ba6df6ab --- /dev/null +++ b/src/include/gnunet_hello_lib.h | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006 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 2, 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 include/gnunet_hello_lib.h | ||
23 | * @brief helper library for handling HELLOs | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_HELLO_LIB_H | ||
28 | #define GNUNET_HELLO_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_common.h" | ||
39 | #include "gnunet_crypto_lib.h" | ||
40 | |||
41 | /** | ||
42 | * A HELLO message is used to exchange information about | ||
43 | * transports with other peers. This struct is guaranteed | ||
44 | * to start with a "GNUNET_MessageHeader", everything else | ||
45 | * should be internal to the HELLO library. | ||
46 | */ | ||
47 | struct GNUNET_HELLO_Message; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Copy the given address information into | ||
52 | * the given buffer using the format of HELLOs. | ||
53 | * | ||
54 | * @param tname name of the transport plugin | ||
55 | * @param expiration expiration for the address | ||
56 | * @param addr the address | ||
57 | * @param addr_len length of the address in bytes | ||
58 | * @param target where to copy the address | ||
59 | * @param max maximum number of bytes to copy to target | ||
60 | * @return number of bytes copied, 0 if | ||
61 | * the target buffer was not big enough. | ||
62 | */ | ||
63 | size_t | ||
64 | GNUNET_HELLO_add_address (const char *tname, | ||
65 | struct GNUNET_TIME_Absolute expiration, | ||
66 | const void *addr, | ||
67 | size_t addr_len, char *target, size_t max); | ||
68 | |||
69 | |||
70 | /** | ||
71 | * Callback function used to fill a buffer of max bytes with a list of | ||
72 | * addresses in the format used by HELLOs. Should use | ||
73 | * "GNUNET_HELLO_add_address" as a helper function. | ||
74 | * | ||
75 | * @param cls closure | ||
76 | * @param max maximum number of bytes that can be written to buf | ||
77 | * @param buf where to write the address information | ||
78 | * @return number of bytes written, 0 to signal the | ||
79 | * end of the iteration. | ||
80 | */ | ||
81 | typedef size_t | ||
82 | (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls, | ||
83 | size_t max, void *buf); | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Construct a HELLO message given the public key, | ||
88 | * expiration time and an iterator that spews the | ||
89 | * transport addresses. | ||
90 | * | ||
91 | * @return the hello message | ||
92 | */ | ||
93 | struct GNUNET_HELLO_Message *GNUNET_HELLO_create (const struct | ||
94 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | ||
95 | *publicKey, | ||
96 | GNUNET_HELLO_GenerateAddressListCallback | ||
97 | addrgen, void *addrgen_cls); | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Return the size of the given HELLO message. | ||
102 | * @param hello to inspect | ||
103 | * @return the size, 0 if HELLO is invalid | ||
104 | */ | ||
105 | uint16_t GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello); | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Construct a HELLO message by merging the | ||
110 | * addresses in two existing HELLOs (which | ||
111 | * must be for the same peer). | ||
112 | * | ||
113 | * @param h1 first HELLO message | ||
114 | * @param h2 the second HELLO message | ||
115 | * @return the combined hello message | ||
116 | */ | ||
117 | struct GNUNET_HELLO_Message *GNUNET_HELLO_merge (const struct | ||
118 | GNUNET_HELLO_Message *h1, | ||
119 | const struct | ||
120 | GNUNET_HELLO_Message *h2); | ||
121 | |||
122 | |||
123 | /** | ||
124 | * Iterator callback to go over all addresses. | ||
125 | * | ||
126 | * @param cls closure | ||
127 | * @param tname name of the transport | ||
128 | * @param expiration expiration time | ||
129 | * @param addr the address | ||
130 | * @param addrlen length of the address | ||
131 | * @return GNUNET_OK to keep the address, | ||
132 | * GNUNET_NO to delete it from the HELLO | ||
133 | * GNUNET_SYSERR to stop iterating (but keep current address) | ||
134 | */ | ||
135 | typedef int | ||
136 | (*GNUNET_HELLO_AddressIterator) (void *cls, | ||
137 | const char *tname, | ||
138 | struct GNUNET_TIME_Absolute expiration, | ||
139 | const void *addr, size_t addrlen); | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Iterate over all of the addresses in the HELLO. | ||
144 | * | ||
145 | * @param msg HELLO to iterate over; client does not need to | ||
146 | * have verified that msg is well-formed (beyond starting | ||
147 | * with a GNUNET_MessageHeader of the right type). | ||
148 | * @param return_modified if a modified copy should be returned, | ||
149 | * otherwise NULL will be returned | ||
150 | * @param it iterator to call on each address | ||
151 | * @param it_cls closure for it | ||
152 | */ | ||
153 | struct GNUNET_HELLO_Message *GNUNET_HELLO_iterate_addresses (const struct | ||
154 | GNUNET_HELLO_Message | ||
155 | *msg, | ||
156 | int | ||
157 | return_modified, | ||
158 | GNUNET_HELLO_AddressIterator | ||
159 | it, | ||
160 | void *it_cls); | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Iterate over addresses in "new_hello" that | ||
165 | * are NOT already present in "old_hello". | ||
166 | * | ||
167 | * @param new_hello a HELLO message | ||
168 | * @param old_hello a HELLO message | ||
169 | * @param expiration_limit ignore addresses in old_hello | ||
170 | * that expired before the given time stamp | ||
171 | * @param it iterator to call on each address | ||
172 | * @param it_cls closure for it | ||
173 | */ | ||
174 | void | ||
175 | GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message | ||
176 | *new_hello, | ||
177 | const struct GNUNET_HELLO_Message | ||
178 | *old_hello, | ||
179 | struct GNUNET_TIME_Absolute | ||
180 | expiration_limit, | ||
181 | GNUNET_HELLO_AddressIterator it, | ||
182 | void *it_cls); | ||
183 | |||
184 | |||
185 | /** | ||
186 | * Get the public key from a HELLO message. | ||
187 | * | ||
188 | * @param hello the hello message | ||
189 | * @param publicKey where to copy the public key information, can be NULL | ||
190 | * @return GNUNET_SYSERR if the HELLO was malformed | ||
191 | */ | ||
192 | int | ||
193 | GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello, | ||
194 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | ||
195 | *publicKey); | ||
196 | |||
197 | |||
198 | |||
199 | /* ifndef GNUNET_HELLO_LIB_H */ | ||
200 | #endif | ||
201 | /* end of gnunet_hello_lib.h */ | ||
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h new file mode 100644 index 000000000..8731eacec --- /dev/null +++ b/src/include/gnunet_network_lib.h | |||
@@ -0,0 +1,308 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 2, 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 include/gnunet_network_lib.h | ||
23 | * @brief basic, low-level TCP networking interface | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #ifndef GNUNET_NETWORK_LIB_H | ||
27 | #define GNUNET_NETWORK_LIB_H | ||
28 | |||
29 | #ifdef __cplusplus | ||
30 | extern "C" | ||
31 | { | ||
32 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
33 | } | ||
34 | #endif | ||
35 | #endif | ||
36 | |||
37 | #include "gnunet_scheduler_lib.h" | ||
38 | #include "gnunet_time_lib.h" | ||
39 | |||
40 | /** | ||
41 | * Timeout we use on TCP connect before trying another | ||
42 | * result from the DNS resolver. 5s. | ||
43 | */ | ||
44 | #define GNUNET_NETWORK_CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
45 | |||
46 | /** | ||
47 | * @brief handle for a network socket | ||
48 | */ | ||
49 | struct GNUNET_NETWORK_SocketHandle; | ||
50 | |||
51 | |||
52 | /** | ||
53 | * Function to call for access control checks. | ||
54 | * | ||
55 | * @param cls closure | ||
56 | * @param addr address | ||
57 | * @param addrlen length of address | ||
58 | * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR | ||
59 | * for unknown address family (will be denied). | ||
60 | */ | ||
61 | typedef int (*GNUNET_NETWORK_AccessCheck) (void *cls, | ||
62 | const struct sockaddr * addr, | ||
63 | socklen_t addrlen); | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Callback function for data received from the network. Note that | ||
68 | * both "available" and "err" would be 0 if the read simply timed out. | ||
69 | * | ||
70 | * @param cls closure | ||
71 | * @param buf pointer to received data | ||
72 | * @param available number of bytes availabe in "buf", | ||
73 | * possibly 0 (on errors) | ||
74 | * @param addr address of the sender | ||
75 | * @param addrlen size of addr | ||
76 | * @param errCode value of errno (on errors receiving) | ||
77 | */ | ||
78 | typedef void (*GNUNET_NETWORK_Receiver) (void *cls, | ||
79 | const void *buf, | ||
80 | size_t available, | ||
81 | const struct sockaddr * addr, | ||
82 | socklen_t addrlen, int errCode); | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Create a socket handle by boxing an existing OS socket. The OS | ||
87 | * socket should henceforth be no longer used directly. | ||
88 | * GNUNET_socket_destroy will close it. | ||
89 | * | ||
90 | * @param sched scheduler to use | ||
91 | * @param osSocket existing socket to box | ||
92 | * @param maxbuf maximum write buffer size for the socket (use | ||
93 | * 0 for sockets that need no write buffers, such as listen sockets) | ||
94 | * @return the boxed socket handle | ||
95 | */ | ||
96 | struct GNUNET_NETWORK_SocketHandle | ||
97 | *GNUNET_NETWORK_socket_create_from_existing (struct GNUNET_SCHEDULER_Handle | ||
98 | *sched, int osSocket, | ||
99 | size_t maxbuf); | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Create a socket handle by accepting on a listen socket. This | ||
104 | * function may block if the listen socket has no connection ready. | ||
105 | * | ||
106 | * @param sched scheduler to use | ||
107 | * @param access function to use to check if access is allowed | ||
108 | * @param access_cls closure for access | ||
109 | * @param lsock listen socket | ||
110 | * @param maxbuf maximum write buffer size for the socket (use | ||
111 | * 0 for sockets that need no write buffers, such as listen sockets) | ||
112 | * @return the socket handle, NULL on error (for example, access refused) | ||
113 | */ | ||
114 | struct GNUNET_NETWORK_SocketHandle | ||
115 | *GNUNET_NETWORK_socket_create_from_accept (struct GNUNET_SCHEDULER_Handle | ||
116 | *sched, | ||
117 | GNUNET_NETWORK_AccessCheck | ||
118 | access, void *access_cls, | ||
119 | int lsock, size_t maxbuf); | ||
120 | |||
121 | |||
122 | /** | ||
123 | * Create a socket handle by (asynchronously) connecting to a host. | ||
124 | * This function returns immediately, even if the connection has not | ||
125 | * yet been established. This function only creates TCP connections. | ||
126 | * | ||
127 | * @param sched scheduler to use | ||
128 | * @param hostname name of the host to connect to | ||
129 | * @param port port to connect to | ||
130 | * @param maxbuf maximum write buffer size for the socket (use | ||
131 | * 0 for sockets that need no write buffers, such as listen sockets) | ||
132 | * @return the socket handle | ||
133 | */ | ||
134 | struct GNUNET_NETWORK_SocketHandle | ||
135 | *GNUNET_NETWORK_socket_create_from_connect (struct GNUNET_SCHEDULER_Handle | ||
136 | *sched, const char *hostname, | ||
137 | uint16_t port, size_t maxbuf); | ||
138 | |||
139 | |||
140 | |||
141 | /** | ||
142 | * Create a socket handle by (asynchronously) connecting to a host. | ||
143 | * This function returns immediately, even if the connection has not | ||
144 | * yet been established. This function only creates TCP connections. | ||
145 | * | ||
146 | * @param sched scheduler to use | ||
147 | * @param af_family address family to use | ||
148 | * @param serv_addr server address | ||
149 | * @param addrlen length of server address | ||
150 | * @param maxbuf maximum write buffer size for the socket (use | ||
151 | * 0 for sockets that need no write buffers, such as listen sockets) | ||
152 | * @return the socket handle | ||
153 | */ | ||
154 | struct GNUNET_NETWORK_SocketHandle | ||
155 | *GNUNET_NETWORK_socket_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle | ||
156 | *sched, int af_family, | ||
157 | const struct sockaddr | ||
158 | *serv_addr, socklen_t addrlen, | ||
159 | size_t maxbuf); | ||
160 | |||
161 | /** | ||
162 | * Check if socket is valid (no fatal errors have happened so far). | ||
163 | * Note that a socket that is still trying to connect is considered | ||
164 | * valid. | ||
165 | * | ||
166 | * @param sock socket to check | ||
167 | * @return GNUNET_YES if valid, GNUNET_NO otherwise | ||
168 | */ | ||
169 | int GNUNET_NETWORK_socket_check (struct GNUNET_NETWORK_SocketHandle *sock); | ||
170 | |||
171 | |||
172 | /** | ||
173 | * Obtain the network address of the other party. | ||
174 | * | ||
175 | * @param sock the client to get the address for | ||
176 | * @param addr where to store the address | ||
177 | * @param addrlen where to store the length of the address | ||
178 | * @return GNUNET_OK on success | ||
179 | */ | ||
180 | int GNUNET_NETWORK_socket_get_address (struct GNUNET_NETWORK_SocketHandle | ||
181 | *sock, void **addr, size_t * addrlen); | ||
182 | |||
183 | /** | ||
184 | * Close the socket and free associated resources. Pending | ||
185 | * transmissions are simply dropped. A pending receive call will be | ||
186 | * called with an error code of "EPIPE". | ||
187 | * | ||
188 | * @param sock socket to destroy | ||
189 | */ | ||
190 | void GNUNET_NETWORK_socket_destroy (struct GNUNET_NETWORK_SocketHandle *sock); | ||
191 | |||
192 | |||
193 | /** | ||
194 | * Receive data from the given socket. Note that this function will | ||
195 | * call "receiver" asynchronously using the scheduler. It will | ||
196 | * "immediately" return. Note that there MUST only be one active | ||
197 | * receive call per socket at any given point in time (so do not | ||
198 | * call receive again until the receiver callback has been invoked). | ||
199 | * | ||
200 | * @param sock socket handle | ||
201 | * @param max maximum number of bytes to read | ||
202 | * @param timeout maximum amount of time to wait | ||
203 | * @param receiver function to call with received data | ||
204 | * @param receiver_cls closure for receiver | ||
205 | * @return scheduler task ID used for receiving, GNUNET_SCHEDULER_NO_PREREQUISITE_TASK on error | ||
206 | */ | ||
207 | GNUNET_SCHEDULER_TaskIdentifier | ||
208 | GNUNET_NETWORK_receive (struct GNUNET_NETWORK_SocketHandle *sock, | ||
209 | size_t max, | ||
210 | struct GNUNET_TIME_Relative timeout, | ||
211 | GNUNET_NETWORK_Receiver receiver, void *receiver_cls); | ||
212 | |||
213 | |||
214 | /** | ||
215 | * Cancel receive job on the given socket. Note that the | ||
216 | * receiver callback must not have been called yet in order | ||
217 | * for the cancellation to be valid. | ||
218 | * | ||
219 | * @param sock socket handle | ||
220 | * @param task task identifier returned from the receive call | ||
221 | * @return closure of the original receiver callback | ||
222 | */ | ||
223 | void *GNUNET_NETWORK_receive_cancel (struct GNUNET_NETWORK_SocketHandle *sock, | ||
224 | GNUNET_SCHEDULER_TaskIdentifier task); | ||
225 | |||
226 | |||
227 | /** | ||
228 | * Function called to notify a client about the socket | ||
229 | * begin ready to queue more data. "buf" will be | ||
230 | * NULL and "size" zero if the socket was closed for | ||
231 | * writing in the meantime. | ||
232 | * | ||
233 | * @param cls closure | ||
234 | * @param size number of bytes available in buf | ||
235 | * @param buf where the callee should write the message | ||
236 | * @return number of bytes written to buf | ||
237 | */ | ||
238 | typedef size_t (*GNUNET_NETWORK_TransmitReadyNotify) (void *cls, | ||
239 | size_t size, void *buf); | ||
240 | |||
241 | |||
242 | /** | ||
243 | * Opaque handle that can be used to cancel | ||
244 | * a transmit-ready notification. | ||
245 | */ | ||
246 | struct GNUNET_NETWORK_TransmitHandle; | ||
247 | |||
248 | /** | ||
249 | * Ask the socket to call us once the specified number of bytes | ||
250 | * are free in the transmission buffer. May call the notify | ||
251 | * method immediately if enough space is available. Note that | ||
252 | * this function will abort if "size" is greater than | ||
253 | * "maxbuf" (as specified when the socket handle was created). | ||
254 | * | ||
255 | * Note that "notify" will be called either when enough | ||
256 | * buffer space is available OR when the socket is destroyed. | ||
257 | * The size parameter given to notify is guaranteed to be | ||
258 | * larger or equal to size if the buffer is ready, or zero | ||
259 | * if the socket was destroyed (or at least closed for | ||
260 | * writing). Finally, any time before 'notify' is called, a | ||
261 | * client may call "notify_transmit_ready_cancel" to cancel | ||
262 | * the transmission request. | ||
263 | * | ||
264 | * Only one transmission request can be scheduled at the same | ||
265 | * time. Notify will be run with the same scheduler priority | ||
266 | * as that of the caller. | ||
267 | * | ||
268 | * @param sock socket | ||
269 | * @param size number of bytes to send | ||
270 | * @param timeout after how long should we give up (and call | ||
271 | * notify with buf NULL and size 0)? | ||
272 | * @param notify function to call when buffer space is available | ||
273 | * @param notify_cls closure for notify | ||
274 | * @return non-NULL if the notify callback was queued, | ||
275 | * NULL if we are already going to notify someone else (busy) | ||
276 | */ | ||
277 | struct GNUNET_NETWORK_TransmitHandle | ||
278 | *GNUNET_NETWORK_notify_transmit_ready (struct GNUNET_NETWORK_SocketHandle | ||
279 | *sock, size_t size, | ||
280 | struct GNUNET_TIME_Relative timeout, | ||
281 | GNUNET_NETWORK_TransmitReadyNotify | ||
282 | notify, void *notify_cls); | ||
283 | |||
284 | |||
285 | /** | ||
286 | * Cancel the specified transmission-ready | ||
287 | * notification. | ||
288 | * | ||
289 | * @param h handle for notification to cancel | ||
290 | */ | ||
291 | void | ||
292 | GNUNET_NETWORK_notify_transmit_ready_cancel (struct | ||
293 | GNUNET_NETWORK_TransmitHandle | ||
294 | *h); | ||
295 | |||
296 | |||
297 | |||
298 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
299 | { | ||
300 | #endif | ||
301 | #ifdef __cplusplus | ||
302 | } | ||
303 | #endif | ||
304 | |||
305 | |||
306 | /* ifndef GNUNET_NETWORK_LIB_H */ | ||
307 | #endif | ||
308 | /* end of gnunet_network_lib.h */ | ||
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h new file mode 100644 index 000000000..dfab4a747 --- /dev/null +++ b/src/include/gnunet_os_lib.h | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006 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 2, 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 include/gnunet_os_lib.h | ||
23 | * @brief low level process routines | ||
24 | * @author Christian Grothoff | ||
25 | * @author Krista Bennett | ||
26 | * @author Gerd Knorr <kraxel@bytesex.org> | ||
27 | * @author Ioana Patrascu | ||
28 | * @author Tzvetan Horozov | ||
29 | * @author Milan | ||
30 | */ | ||
31 | |||
32 | #ifndef GNUNET_OS_LIB_H | ||
33 | #define GNUNET_OS_LIB_H | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" | ||
37 | { | ||
38 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
39 | } | ||
40 | #endif | ||
41 | #endif | ||
42 | |||
43 | #include "gnunet_common.h" | ||
44 | #include "gnunet_configuration_lib.h" | ||
45 | #include "gnunet_scheduler_lib.h" | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Possible installation paths to request | ||
50 | */ | ||
51 | enum GNUNET_OS_InstallationPathKind | ||
52 | { | ||
53 | GNUNET_OS_IPK_PREFIX, | ||
54 | GNUNET_OS_IPK_BINDIR, | ||
55 | GNUNET_OS_IPK_LIBDIR, | ||
56 | GNUNET_OS_IPK_DATADIR, | ||
57 | GNUNET_OS_IPK_LOCALEDIR, | ||
58 | GNUNET_OS_IPK_SELF_PREFIX | ||
59 | }; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Get the path to a specific GNUnet installation directory or, with | ||
64 | * GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation | ||
65 | * directory. | ||
66 | * | ||
67 | * @param dirkind what kind of directory is desired? | ||
68 | * @return a pointer to the dir path (to be freed by the caller) | ||
69 | */ | ||
70 | char *GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind | ||
71 | dirkind); | ||
72 | |||
73 | |||
74 | /** | ||
75 | * Callback function invoked for each interface found. | ||
76 | * | ||
77 | * @param cls closure | ||
78 | * @param name name of the interface (can be NULL for unknown) | ||
79 | * @param isDefault is this presumably the default interface | ||
80 | * @param addr address of this interface (can be NULL for unknown or unassigned) | ||
81 | * @param addrlen length of the address | ||
82 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | ||
83 | */ | ||
84 | typedef int (*GNUNET_OS_NetworkInterfaceProcessor) (void *cls, | ||
85 | const char *name, | ||
86 | int isDefault, | ||
87 | const struct sockaddr * | ||
88 | addr, socklen_t addrlen); | ||
89 | |||
90 | |||
91 | /** | ||
92 | * @brief Enumerate all network interfaces | ||
93 | * @param callback the callback function | ||
94 | */ | ||
95 | void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor | ||
96 | proc, void *cls); | ||
97 | |||
98 | /** | ||
99 | * Get the current CPU load. | ||
100 | * | ||
101 | * @param cfg to determine acceptable load level (LOAD::MAXCPULOAD) | ||
102 | * @return -1 on error, otherwise load value (between 0 and 100, | ||
103 | * (100 is equivalent to full load for one CPU) | ||
104 | */ | ||
105 | int GNUNET_OS_load_cpu_get (struct GNUNET_CONFIGURATION_Handle *cfg); | ||
106 | |||
107 | /** | ||
108 | * Get the current IO load. | ||
109 | * | ||
110 | * @param cfg to determine acceptable load level (LOAD::MAXIOLOAD) | ||
111 | * @return -1 on error, otherwise load value (between 0 and 100, | ||
112 | * 100 means that we spend all of our cycles waiting for | ||
113 | * the disk) | ||
114 | */ | ||
115 | int GNUNET_OS_load_disk_get (struct GNUNET_CONFIGURATION_Handle *cfg); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Set process priority | ||
120 | * | ||
121 | * @param proc id of the process | ||
122 | * @param prio priority value | ||
123 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
124 | */ | ||
125 | int GNUNET_OS_set_process_priority (pid_t proc, | ||
126 | enum GNUNET_SCHEDULER_Priority prio); | ||
127 | |||
128 | |||
129 | /** | ||
130 | * Start a process. | ||
131 | * | ||
132 | * @param filename name of the binary | ||
133 | * @param ... NULL-terminated list of arguments to the process | ||
134 | * @return process ID of the new process, -1 on error | ||
135 | */ | ||
136 | pid_t GNUNET_OS_start_process (const char *filename, ...); | ||
137 | |||
138 | /** | ||
139 | * Start a process. | ||
140 | * | ||
141 | * @param filename name of the binary | ||
142 | * @param argv NULL-terminated list of arguments to the process, | ||
143 | * including the process name as the first argument | ||
144 | * @return process ID of the new process, -1 on error | ||
145 | */ | ||
146 | pid_t GNUNET_OS_start_process_v (const char *filename, char *const argv[]); | ||
147 | |||
148 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
149 | { | ||
150 | #endif | ||
151 | #ifdef __cplusplus | ||
152 | } | ||
153 | #endif | ||
154 | |||
155 | |||
156 | /* ifndef GNUNET_OS_LIB_H */ | ||
157 | #endif | ||
158 | /* end of gnunet_os_lib.h */ | ||
diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h new file mode 100644 index 000000000..45c52c447 --- /dev/null +++ b/src/include/gnunet_peerinfo_service.h | |||
@@ -0,0 +1,111 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 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 2, 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 | * @file include/gnunet_peerinfo_service.h | ||
22 | * @brief Code to maintain the list of currently known hosts | ||
23 | * (in memory structure of data/hosts) and their trust ratings | ||
24 | * (in memory structure of data/trust) | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_PEERINFO_SERVICE_H | ||
29 | #define GNUNET_PEERINFO_SERVICE_H | ||
30 | |||
31 | #include "gnunet_common.h" | ||
32 | #include "gnunet_configuration_lib.h" | ||
33 | #include "gnunet_crypto_lib.h" | ||
34 | #include "gnunet_hello_lib.h" | ||
35 | |||
36 | #ifdef __cplusplus | ||
37 | extern "C" | ||
38 | { | ||
39 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
40 | } | ||
41 | #endif | ||
42 | #endif | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Add a host to the persistent list. | ||
47 | * | ||
48 | * @param cfg configuration to use | ||
49 | * @param sched scheduler to use | ||
50 | * @param peer identity of the peer | ||
51 | * @param hello the verified (!) HELLO message | ||
52 | */ | ||
53 | void | ||
54 | GNUNET_PEERINFO_add_peer (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
55 | struct GNUNET_SCHEDULER_Handle *sched, | ||
56 | const struct GNUNET_PeerIdentity *peer, | ||
57 | const struct GNUNET_HELLO_Message *hello); | ||
58 | |||
59 | /** | ||
60 | * Type of an iterator over the hosts. Note that each | ||
61 | * host will be called with each available protocol. | ||
62 | * | ||
63 | * @param cls closure | ||
64 | * @param peer id of the peer, NULL for last call | ||
65 | * @param hello hello message for the peer (can be NULL) | ||
66 | * @param trust amount of trust we have in the peer | ||
67 | */ | ||
68 | typedef void | ||
69 | (*GNUNET_PEERINFO_Processor) (void *cls, | ||
70 | const struct GNUNET_PeerIdentity * peer, | ||
71 | const struct GNUNET_HELLO_Message * hello, | ||
72 | uint32_t trust); | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Call a method for each known matching host and change | ||
77 | * its trust value. The method will be invoked once for | ||
78 | * each host and then finally once with a NULL pointer. | ||
79 | * Note that the last call can be triggered by timeout or | ||
80 | * by simply being done; however, the trust argument will | ||
81 | * be set to zero if we are done, 1 if we timed out and | ||
82 | * 2 for fatal error. | ||
83 | * | ||
84 | * @param cfg configuration to use | ||
85 | * @param sched scheduler to use | ||
86 | * @param peer restrict iteration to this peer only (can be NULL) | ||
87 | * @param trust_delta how much to change the trust in all matching peers | ||
88 | * @param timeout how long to wait until timing out | ||
89 | * @param callback the method to call for each peer | ||
90 | * @param callback_cls closure for callback | ||
91 | */ | ||
92 | void | ||
93 | GNUNET_PEERINFO_for_all (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
94 | struct GNUNET_SCHEDULER_Handle *sched, | ||
95 | const struct GNUNET_PeerIdentity *peer, | ||
96 | int trust_delta, | ||
97 | struct GNUNET_TIME_Relative timeout, | ||
98 | GNUNET_PEERINFO_Processor callback, | ||
99 | void *callback_cls); | ||
100 | |||
101 | |||
102 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
103 | { | ||
104 | #endif | ||
105 | #ifdef __cplusplus | ||
106 | } | ||
107 | #endif | ||
108 | |||
109 | |||
110 | /* end of gnunet_peerinfo_service.h */ | ||
111 | #endif | ||
diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h new file mode 100644 index 000000000..e4f603c4e --- /dev/null +++ b/src/include/gnunet_plugin_lib.h | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006 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 2, 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 include/gnunet_plugin_lib.h | ||
23 | * @brief plugin loading and unloading | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_PLUGIN_LIB_H | ||
28 | #define GNUNET_PLUGIN_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_common.h" | ||
39 | #include "gnunet_configuration_lib.h" | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Signature of any function exported by a plugin. | ||
44 | */ | ||
45 | typedef void *(*GNUNET_PLUGIN_Callback) (void *arg); | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Setup plugin (runs the "init" callback and returns whatever "init" | ||
50 | * returned). If "init" returns NULL, the plugin is unloaded. | ||
51 | * | ||
52 | * Note that the library must export symbols called | ||
53 | * "library_name_init" and "library_name_done". These will be called | ||
54 | * when the library is loaded and unloaded respectively. | ||
55 | * | ||
56 | * @param library_name name of the plugin to load | ||
57 | * @param arg argument to the plugin initialization function | ||
58 | * @return whatever the initialization function returned | ||
59 | */ | ||
60 | void *GNUNET_PLUGIN_load (const char *library_name, void *arg); | ||
61 | |||
62 | |||
63 | /** | ||
64 | * Unload plugin (runs the "done" callback and returns whatever "done" | ||
65 | * returned). The plugin is then unloaded. | ||
66 | * | ||
67 | * @param library_name name of the plugin to unload | ||
68 | * @param arg argument to the plugin shutdown function | ||
69 | * @return whatever the shutdown function returned | ||
70 | */ | ||
71 | void *GNUNET_PLUGIN_unload (const char *library_name, void *arg); | ||
72 | |||
73 | |||
74 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
75 | { | ||
76 | #endif | ||
77 | #ifdef __cplusplus | ||
78 | } | ||
79 | #endif | ||
80 | |||
81 | |||
82 | /* ifndef GNUNET_PLUGIN_LIB_H */ | ||
83 | #endif | ||
84 | /* end of gnunet_plugin_lib.h */ | ||
diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h new file mode 100644 index 000000000..fcd00b8ef --- /dev/null +++ b/src/include/gnunet_program_lib.h | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_program_lib.h | ||
23 | * @brief functions related to starting programs | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_PROGRAM_LIB_H | ||
28 | #define GNUNET_PROGRAM_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_configuration_lib.h" | ||
39 | #include "gnunet_getopt_lib.h" | ||
40 | #include "gnunet_scheduler_lib.h" | ||
41 | |||
42 | /** | ||
43 | * Main function that will be run. | ||
44 | * | ||
45 | * @param cls closure | ||
46 | * @param sched the scheduler to use | ||
47 | * @param args remaining command-line arguments | ||
48 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
49 | * @param cfg configuration | ||
50 | */ | ||
51 | typedef void (*GNUNET_PROGRAM_Main) (void *cls, | ||
52 | struct GNUNET_SCHEDULER_Handle * sched, | ||
53 | char *const *args, | ||
54 | const char *cfgfile, | ||
55 | struct GNUNET_CONFIGURATION_Handle * | ||
56 | cfg); | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Run a standard GNUnet command startup sequence (initialize loggers | ||
61 | * and configuration, parse options). | ||
62 | * | ||
63 | * @param argc number of command line arguments | ||
64 | * @param argv command line arguments | ||
65 | * @param binaryName our expected name | ||
66 | * @param binaryHelp helptext for "-h" option (about the app) | ||
67 | * @param options command line options | ||
68 | * @param task main function to run | ||
69 | * @param task_cls closure for task | ||
70 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | ||
71 | */ | ||
72 | int GNUNET_PROGRAM_run (int argc, | ||
73 | char *const *argv, | ||
74 | const char *binaryName, | ||
75 | const char *binaryHelp, | ||
76 | const struct GNUNET_GETOPT_CommandLineOption *options, | ||
77 | GNUNET_PROGRAM_Main task, void *task_cls); | ||
78 | |||
79 | |||
80 | |||
81 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
82 | { | ||
83 | #endif | ||
84 | #ifdef __cplusplus | ||
85 | } | ||
86 | #endif | ||
87 | |||
88 | /* ifndef GNUNET_PROGRAM_LIB_H */ | ||
89 | #endif | ||
90 | /* end of gnunet_program_lib.h */ | ||
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h new file mode 100644 index 000000000..c86ad83ce --- /dev/null +++ b/src/include/gnunet_protocols.h | |||
@@ -0,0 +1,319 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_protocols.h | ||
23 | * @brief constants for network protocols | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_PROTOCOLS_H | ||
28 | #define GNUNET_PROTOCOLS_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | /** | ||
39 | * Test if service is online. | ||
40 | */ | ||
41 | #define GNUNET_MESSAGE_TYPE_TEST 0 | ||
42 | |||
43 | /** | ||
44 | * Request service shutdown. | ||
45 | */ | ||
46 | #define GNUNET_MESSAGE_TYPE_SHUTDOWN 1 | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Request DNS resolution. | ||
51 | */ | ||
52 | #define GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST 2 | ||
53 | |||
54 | /** | ||
55 | * Response to a DNS resolution request. | ||
56 | */ | ||
57 | #define GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE 3 | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Set a statistical value. | ||
62 | */ | ||
63 | #define GNUNET_MESSAGE_TYPE_STATISTICS_SET 4 | ||
64 | |||
65 | /** | ||
66 | * Get a statistical value(s). | ||
67 | */ | ||
68 | #define GNUNET_MESSAGE_TYPE_STATISTICS_GET 5 | ||
69 | |||
70 | /** | ||
71 | * Response to a STATISTICS_GET message (with value). | ||
72 | */ | ||
73 | #define GNUNET_MESSAGE_TYPE_STATISTICS_VALUE 6 | ||
74 | |||
75 | /** | ||
76 | * Response to a STATISTICS_GET message (end of value stream). | ||
77 | */ | ||
78 | #define GNUNET_MESSAGE_TYPE_STATISTICS_END 7 | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Request to ARM to start a service. | ||
83 | */ | ||
84 | #define GNUNET_MESSAGE_TYPE_ARM_START 8 | ||
85 | |||
86 | /** | ||
87 | * Request to ARM to stop a service. | ||
88 | */ | ||
89 | #define GNUNET_MESSAGE_TYPE_ARM_STOP 9 | ||
90 | |||
91 | /** | ||
92 | * Response from ARM: service is now up. | ||
93 | */ | ||
94 | #define GNUNET_MESSAGE_TYPE_ARM_IS_UP 10 | ||
95 | |||
96 | /** | ||
97 | * Response from ARM: service is now down. | ||
98 | * (failed to start it). | ||
99 | */ | ||
100 | #define GNUNET_MESSAGE_TYPE_ARM_IS_DOWN 11 | ||
101 | |||
102 | |||
103 | /** | ||
104 | * HELLO message used for communicating peer addresses. | ||
105 | * Managed by libgnunethello. | ||
106 | */ | ||
107 | #define GNUNET_MESSAGE_TYPE_HELLO 16 | ||
108 | |||
109 | /** | ||
110 | * FRAGMENT of a larger message. | ||
111 | * Managed by libgnunetfragment. | ||
112 | */ | ||
113 | #define GNUNET_MESSAGE_TYPE_FRAGMENT 18 | ||
114 | |||
115 | |||
116 | /** | ||
117 | * Message from the core saying that the transport | ||
118 | * server should start giving it messages. This | ||
119 | * should automatically trigger the transmission of | ||
120 | * a HELLO message. | ||
121 | */ | ||
122 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_START 20 | ||
123 | |||
124 | /** | ||
125 | * Message from TRANSPORT notifying about a | ||
126 | * client that connected to us. | ||
127 | */ | ||
128 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT 21 | ||
129 | |||
130 | /** | ||
131 | * Message from TRANSPORT notifying about a | ||
132 | * client that disconnected from us. | ||
133 | */ | ||
134 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT 22 | ||
135 | |||
136 | /** | ||
137 | * Request to TRANSPORT to transmit a message. | ||
138 | */ | ||
139 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND 23 | ||
140 | |||
141 | /** | ||
142 | * Confirmation from TRANSPORT that message for | ||
143 | * transmission has been queued (and that the next | ||
144 | * message to this peer can now be passed to the | ||
145 | * service). Note that this confirmation does NOT | ||
146 | * imply that the message was fully transmitted. | ||
147 | */ | ||
148 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK 24 | ||
149 | |||
150 | /** | ||
151 | * Message from TRANSPORT notifying about a | ||
152 | * message that was received. | ||
153 | */ | ||
154 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV 25 | ||
155 | |||
156 | /** | ||
157 | * Message telling transport to limit its receive rate. | ||
158 | */ | ||
159 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA 26 | ||
160 | |||
161 | /** | ||
162 | * Message telling transport to try to connect to the | ||
163 | * given peer. | ||
164 | */ | ||
165 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_TRY_CONNECT 27 | ||
166 | |||
167 | /** | ||
168 | * Request to other peer to confirm receipt. | ||
169 | */ | ||
170 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_PING 28 | ||
171 | |||
172 | /** | ||
173 | * Message from other peer confirming receipt. | ||
174 | */ | ||
175 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_PONG 29 | ||
176 | |||
177 | /** | ||
178 | * Response to another peer confirming that communication was | ||
179 | * established. | ||
180 | */ | ||
181 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ACK 30 | ||
182 | |||
183 | |||
184 | /** | ||
185 | * Request addition of a HELLO | ||
186 | */ | ||
187 | #define GNUNET_MESSAGE_TYPE_PEERINFO_ADD 32 | ||
188 | |||
189 | /** | ||
190 | * Request update and listing of a peer. | ||
191 | */ | ||
192 | #define GNUNET_MESSAGE_TYPE_PEERINFO_GET 33 | ||
193 | |||
194 | /** | ||
195 | * Request update and listing of all peers. | ||
196 | */ | ||
197 | #define GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL 34 | ||
198 | |||
199 | /** | ||
200 | * Information about one of the peers. | ||
201 | */ | ||
202 | #define GNUNET_MESSAGE_TYPE_PEERINFO_INFO 35 | ||
203 | |||
204 | /** | ||
205 | * End of information about other peers. | ||
206 | */ | ||
207 | #define GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END 36 | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Welcome message between TCP transports. | ||
212 | */ | ||
213 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME 40 | ||
214 | |||
215 | /** | ||
216 | * Data message between TCP transports. | ||
217 | */ | ||
218 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_DATA 41 | ||
219 | |||
220 | |||
221 | /** | ||
222 | * Initial setup message from core client to core. | ||
223 | */ | ||
224 | #define GNUNET_MESSAGE_TYPE_CORE_INIT 64 | ||
225 | |||
226 | /** | ||
227 | * Response from core to core client to INIT message. | ||
228 | */ | ||
229 | #define GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY 65 | ||
230 | |||
231 | /** | ||
232 | * Notify clients about new peer-to-peer connections. | ||
233 | */ | ||
234 | #define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT 66 | ||
235 | |||
236 | /** | ||
237 | * Notify clients about peer disconnecting. | ||
238 | */ | ||
239 | #define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT 67 | ||
240 | |||
241 | /** | ||
242 | * Notify clients about incoming P2P messages. | ||
243 | */ | ||
244 | #define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND 68 | ||
245 | |||
246 | /** | ||
247 | * Notify clients about outgoing P2P transmissions. | ||
248 | */ | ||
249 | #define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND 69 | ||
250 | |||
251 | /** | ||
252 | * Request from client to "configure" P2P connection. | ||
253 | */ | ||
254 | #define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE 70 | ||
255 | |||
256 | /** | ||
257 | * Response from server about (possibly updated) P2P | ||
258 | * connection configuration. | ||
259 | */ | ||
260 | #define GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO 71 | ||
261 | |||
262 | /** | ||
263 | * Solicitation from server for transmission (may have | ||
264 | * been requested or also be transmitted without | ||
265 | * client's request). | ||
266 | */ | ||
267 | #define GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC 72 | ||
268 | |||
269 | /** | ||
270 | * Response from client with message to transmit. | ||
271 | */ | ||
272 | #define GNUNET_MESSAGE_TYPE_CORE_SEND 73 | ||
273 | |||
274 | |||
275 | /** | ||
276 | * Session key exchange between peers. | ||
277 | */ | ||
278 | #define GNUNET_MESSAGE_TYPE_CORE_SET_KEY 80 | ||
279 | |||
280 | /** | ||
281 | * Encapsulation for an encrypted message between peers. | ||
282 | */ | ||
283 | #define GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE 81 | ||
284 | |||
285 | /** | ||
286 | * Check that other peer is alife (challenge). | ||
287 | */ | ||
288 | #define GNUNET_MESSAGE_TYPE_CORE_PING 82 | ||
289 | |||
290 | /** | ||
291 | * Confirmation that other peer is alife. | ||
292 | */ | ||
293 | #define GNUNET_MESSAGE_TYPE_CORE_PONG 83 | ||
294 | |||
295 | /** | ||
296 | * Request by the other peer to terminate the connection. | ||
297 | */ | ||
298 | #define GNUNET_MESSAGE_TYPE_CORE_HANGUP 84 | ||
299 | |||
300 | |||
301 | /* | ||
302 | TODO: | ||
303 | - DV | ||
304 | - DHT | ||
305 | - datastores | ||
306 | - applications (FS, VPN, CHAT, TRACEKIT, TBENCH) | ||
307 | */ | ||
308 | |||
309 | |||
310 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
311 | { | ||
312 | #endif | ||
313 | #ifdef __cplusplus | ||
314 | } | ||
315 | #endif | ||
316 | |||
317 | /* ifndef GNUNET_PROTOCOLS_H */ | ||
318 | #endif | ||
319 | /* end of gnunet_protocols.h */ | ||
diff --git a/src/include/gnunet_pseudonym_lib.h b/src/include/gnunet_pseudonym_lib.h new file mode 100644 index 000000000..0ee9ce7ac --- /dev/null +++ b/src/include/gnunet_pseudonym_lib.h | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_pseudonym_lib.h | ||
23 | * @brief functions related to pseudonyms | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_PSEUDONYM_LIB_H | ||
28 | #define GNUNET_PSEUDONYM_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_common.h" | ||
39 | #include "gnunet_configuration_lib.h" | ||
40 | #include "gnunet_container_lib.h" | ||
41 | |||
42 | /** | ||
43 | * Iterator over all known pseudonyms. | ||
44 | * | ||
45 | * @param rating the local rating of the pseudonym | ||
46 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | ||
47 | */ | ||
48 | typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls, | ||
49 | const GNUNET_HashCode * | ||
50 | pseudonym, | ||
51 | const struct | ||
52 | GNUNET_CONTAINER_MetaData * md, | ||
53 | int rating); | ||
54 | |||
55 | /** | ||
56 | * Change the ranking of a pseudonym. | ||
57 | * | ||
58 | * @param pseudonym id of the pseudonym | ||
59 | * @param delta by how much should the rating be changed? | ||
60 | * @return new rating of the namespace | ||
61 | */ | ||
62 | int GNUNET_PSEUDONYM_rank (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
63 | const GNUNET_HashCode * pseudonym, int delta); | ||
64 | |||
65 | /** | ||
66 | * Add a pseudonym to the set of known pseudonyms. | ||
67 | * | ||
68 | * @param pseudonym the pseudonym's identifier | ||
69 | */ | ||
70 | void GNUNET_PSEUDONYM_add (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
71 | const GNUNET_HashCode * pseudo, | ||
72 | const struct GNUNET_CONTAINER_MetaData *meta); | ||
73 | |||
74 | |||
75 | /** | ||
76 | * List all known pseudonyms. | ||
77 | */ | ||
78 | int GNUNET_PSEUDONYM_list_all (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
79 | GNUNET_PSEUDONYM_Iterator iterator, | ||
80 | void *closure); | ||
81 | |||
82 | /** | ||
83 | * Register callback to be invoked whenever we discover | ||
84 | * a new pseudonym. | ||
85 | */ | ||
86 | int GNUNET_PSEUDONYM_discovery_callback_register (struct | ||
87 | GNUNET_CONFIGURATION_Handle | ||
88 | *cfg, | ||
89 | GNUNET_PSEUDONYM_Iterator | ||
90 | iterator, void *closure); | ||
91 | |||
92 | /** | ||
93 | * Unregister namespace discovery callback. | ||
94 | */ | ||
95 | int | ||
96 | GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator | ||
97 | iterator, void *closure); | ||
98 | |||
99 | /** | ||
100 | * Return the unique, human readable name for the given pseudonym. | ||
101 | * | ||
102 | * @return NULL on failure (should never happen) | ||
103 | */ | ||
104 | char *GNUNET_PSEUDONYM_id_to_name (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
105 | const GNUNET_HashCode * pseudo); | ||
106 | |||
107 | /** | ||
108 | * Get the pseudonym ID belonging to the given human readable name. | ||
109 | * | ||
110 | * @return GNUNET_OK on success | ||
111 | */ | ||
112 | int GNUNET_PSEUDONYM_name_to_id (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
113 | const char *hname, GNUNET_HashCode * psid); | ||
114 | |||
115 | |||
116 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
117 | { | ||
118 | #endif | ||
119 | #ifdef __cplusplus | ||
120 | } | ||
121 | #endif | ||
122 | |||
123 | /* ifndef GNUNET_PSEUDONYM_LIB_H */ | ||
124 | #endif | ||
125 | /* end of gnunet_pseudonym_lib.h */ | ||
diff --git a/src/include/gnunet_resolver_service.h b/src/include/gnunet_resolver_service.h new file mode 100644 index 000000000..ac7aebcc7 --- /dev/null +++ b/src/include/gnunet_resolver_service.h | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_resolver_service.h | ||
23 | * @brief functions related to doing DNS lookups | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_RESOLVER_SERVICE_H | ||
28 | #define GNUNET_RESOLVER_SERVICE_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_configuration_lib.h" | ||
39 | #include "gnunet_scheduler_lib.h" | ||
40 | #include "gnunet_time_lib.h" | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Function called by the resolver for each address obtained from DNS. | ||
45 | * | ||
46 | * @param cls closure | ||
47 | * @param addr one of the addresses of the host, NULL for the last address | ||
48 | * @param addrlen length of the address | ||
49 | */ | ||
50 | typedef void (*GNUNET_RESOLVER_AddressCallback) (void *cls, | ||
51 | const struct sockaddr * addr, | ||
52 | socklen_t addrlen); | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Convert a string to one or more IP addresses. | ||
57 | * | ||
58 | * @param sched scheduler to use | ||
59 | * @param cfg configuration to use | ||
60 | * @param hostname the hostname to resolve | ||
61 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" | ||
62 | * @param callback function to call with addresses | ||
63 | * @param cls closure for callback | ||
64 | * @param timeout how long to try resolving | ||
65 | */ | ||
66 | void | ||
67 | GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, | ||
68 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
69 | const char *hostname, | ||
70 | int domain, | ||
71 | struct GNUNET_TIME_Relative timeout, | ||
72 | GNUNET_RESOLVER_AddressCallback callback, void *cls); | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Resolve our hostname to an IP address. | ||
77 | * | ||
78 | * @param sched scheduler to use | ||
79 | * @param cfg configuration to use | ||
80 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" | ||
81 | * @param callback function to call with addresses | ||
82 | * @param cls closure for callback | ||
83 | * @param timeout how long to try resolving | ||
84 | */ | ||
85 | void | ||
86 | GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, | ||
87 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
88 | int domain, | ||
89 | struct GNUNET_TIME_Relative timeout, | ||
90 | GNUNET_RESOLVER_AddressCallback callback, | ||
91 | void *cls); | ||
92 | |||
93 | |||
94 | /** | ||
95 | * Function called by the resolver for each hostname obtained from DNS. | ||
96 | * | ||
97 | * @param cls closure | ||
98 | * @param hostname one of the names for the host, NULL | ||
99 | * on the last call to the callback | ||
100 | */ | ||
101 | typedef void (*GNUNET_RESOLVER_HostnameCallback) (void *cls, | ||
102 | const char *hostname); | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Get an IP address as a string. | ||
107 | * | ||
108 | * @param sched scheduler to use | ||
109 | * @param cfg configuration to use | ||
110 | * @param sa host address | ||
111 | * @param salen length of host address | ||
112 | * @param do_resolve use GNUNET_NO to return numeric hostname | ||
113 | * @param timeout how long to try resolving | ||
114 | * @param callback function to call with hostnames | ||
115 | * @param cls closure for callback | ||
116 | */ | ||
117 | void GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, | ||
118 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
119 | const struct sockaddr *sa, | ||
120 | socklen_t salen, | ||
121 | int do_resolve, | ||
122 | struct GNUNET_TIME_Relative timeout, | ||
123 | GNUNET_RESOLVER_HostnameCallback callback, | ||
124 | void *cls); | ||
125 | |||
126 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
127 | { | ||
128 | #endif | ||
129 | #ifdef __cplusplus | ||
130 | } | ||
131 | #endif | ||
132 | |||
133 | /* ifndef GNUNET_RESOLVER_SERVICE_H */ | ||
134 | #endif | ||
135 | /* end of gnunet_resolver_service.h */ | ||
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h new file mode 100644 index 000000000..aa5830942 --- /dev/null +++ b/src/include/gnunet_scheduler_lib.h | |||
@@ -0,0 +1,442 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 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 2, 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 include/gnunet_scheduler_lib.h | ||
23 | * @brief API to schedule computations using continuation passing style | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_SCHEDULER_LIB_H | ||
28 | #define GNUNET_SCHEDULER_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_time_lib.h" | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Opaque handle for the scheduling service. | ||
43 | */ | ||
44 | struct GNUNET_SCHEDULER_Handle; | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Opaque reference to a task. | ||
49 | */ | ||
50 | typedef unsigned long long GNUNET_SCHEDULER_TaskIdentifier; | ||
51 | |||
52 | |||
53 | /** | ||
54 | * Constant used to indicate that the scheduled | ||
55 | * task has no others as prerequisites. | ||
56 | */ | ||
57 | #define GNUNET_SCHEDULER_NO_PREREQUISITE_TASK ((GNUNET_SCHEDULER_TaskIdentifier) 0) | ||
58 | |||
59 | /** | ||
60 | * Reasons why the schedule may have triggered | ||
61 | * the task now. | ||
62 | */ | ||
63 | enum GNUNET_SCHEDULER_Reason | ||
64 | { | ||
65 | /** | ||
66 | * This is the very first task run during startup. | ||
67 | */ | ||
68 | GNUNET_SCHEDULER_REASON_STARTUP = 0, | ||
69 | |||
70 | /** | ||
71 | * We are shutting down and are running all shutdown-related tasks | ||
72 | * (regardless of timeout, etc.). | ||
73 | */ | ||
74 | GNUNET_SCHEDULER_REASON_SHUTDOWN = 1, | ||
75 | |||
76 | /** | ||
77 | * The specified timeout has expired. | ||
78 | * (also set if the delay given was 0). | ||
79 | */ | ||
80 | GNUNET_SCHEDULER_REASON_TIMEOUT = 2, | ||
81 | |||
82 | /** | ||
83 | * The reading socket is ready. | ||
84 | */ | ||
85 | GNUNET_SCHEDULER_REASON_READ_READY = 4, | ||
86 | |||
87 | /** | ||
88 | * The writing socket is ready. | ||
89 | */ | ||
90 | GNUNET_SCHEDULER_REASON_WRITE_READY = 8, | ||
91 | |||
92 | /** | ||
93 | * The prerequisite task is done. | ||
94 | */ | ||
95 | GNUNET_SCHEDULER_REASON_PREREQ_DONE = 16 | ||
96 | }; | ||
97 | |||
98 | |||
99 | /** | ||
100 | * Valid task priorities. Use these, do not | ||
101 | * pass random integers! | ||
102 | */ | ||
103 | enum GNUNET_SCHEDULER_Priority | ||
104 | { | ||
105 | /** | ||
106 | * Run with the same priority as the current job. | ||
107 | */ | ||
108 | GNUNET_SCHEDULER_PRIORITY_KEEP = 0, | ||
109 | |||
110 | /** | ||
111 | * Run when otherwise idle. | ||
112 | */ | ||
113 | GNUNET_SCHEDULER_PRIORITY_IDLE = 1, | ||
114 | |||
115 | /** | ||
116 | * Run as background job (higher than idle, | ||
117 | * lower than default). | ||
118 | */ | ||
119 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND = 2, | ||
120 | |||
121 | /** | ||
122 | * Run with the default priority (normal | ||
123 | * P2P operations). Higher than BACKGROUND. | ||
124 | */ | ||
125 | GNUNET_SCHEDULER_PRIORITY_DEFAULT = 3, | ||
126 | |||
127 | /** | ||
128 | * Run with high priority (important requests). | ||
129 | * Higher than DEFAULT. | ||
130 | */ | ||
131 | GNUNET_SCHEDULER_PRIORITY_HIGH = 4, | ||
132 | |||
133 | /** | ||
134 | * Run with priority for interactive tasks. | ||
135 | * Higher than "HIGH". | ||
136 | */ | ||
137 | GNUNET_SCHEDULER_PRIORITY_UI = 5, | ||
138 | |||
139 | /** | ||
140 | * Run with priority for urgent tasks. Use | ||
141 | * for things like aborts and shutdowns that | ||
142 | * need to preempt "UI"-level tasks. | ||
143 | * Higher than "UI". | ||
144 | */ | ||
145 | GNUNET_SCHEDULER_PRIORITY_URGENT = 6, | ||
146 | |||
147 | /** | ||
148 | * Number of priorities (must be the last priority). | ||
149 | * This priority must not be used by clients. | ||
150 | */ | ||
151 | GNUNET_SCHEDULER_PRIORITY_COUNT = 7 | ||
152 | }; | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Context information passed to each scheduler task. | ||
157 | */ | ||
158 | struct GNUNET_SCHEDULER_TaskContext | ||
159 | { | ||
160 | |||
161 | /** | ||
162 | * Scheduler running the task | ||
163 | */ | ||
164 | struct GNUNET_SCHEDULER_Handle *sched; | ||
165 | |||
166 | /** | ||
167 | * Reason why the task is run now | ||
168 | */ | ||
169 | enum GNUNET_SCHEDULER_Reason reason; | ||
170 | |||
171 | /** | ||
172 | * Set of file descriptors ready for reading; | ||
173 | * note that additional bits may be set | ||
174 | * that were not in the original request | ||
175 | */ | ||
176 | const fd_set *read_ready; | ||
177 | |||
178 | /** | ||
179 | * Set of file descriptors ready for writing; | ||
180 | * note that additional bits may be set | ||
181 | * that were not in the original request. | ||
182 | */ | ||
183 | const fd_set *write_ready; | ||
184 | |||
185 | }; | ||
186 | |||
187 | |||
188 | /** | ||
189 | * Signature of the main function of a task. | ||
190 | * | ||
191 | * @param cls closure | ||
192 | * @param tc context information (why was this task triggered now) | ||
193 | */ | ||
194 | typedef void (*GNUNET_SCHEDULER_Task) (void *cls, | ||
195 | const struct | ||
196 | GNUNET_SCHEDULER_TaskContext * tc); | ||
197 | |||
198 | |||
199 | /** | ||
200 | * Initialize and run scheduler. This function will return when | ||
201 | * either a shutdown was initiated (via signal) and all tasks marked | ||
202 | * to "run_on_shutdown" have been completed or when all tasks in | ||
203 | * general have been completed. | ||
204 | * | ||
205 | * @param task task to run immediately | ||
206 | * @param cls closure of task | ||
207 | */ | ||
208 | void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls); | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Request the shutdown of a scheduler. This function can be used to | ||
213 | * stop a scheduler, for example from within the signal | ||
214 | * handler for signals causing shutdowns. | ||
215 | */ | ||
216 | void GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched); | ||
217 | |||
218 | |||
219 | /** | ||
220 | * Get information about the current load of this scheduler. Use this | ||
221 | * function to determine if an elective task should be added or simply | ||
222 | * dropped (if the decision should be made based on the number of | ||
223 | * tasks ready to run). | ||
224 | * | ||
225 | * @param sched scheduler to query | ||
226 | * @param p priority-level to query, use KEEP to query the level | ||
227 | * of the current task, use COUNT to get the sum over | ||
228 | * all priority levels | ||
229 | * @return number of tasks pending right now | ||
230 | */ | ||
231 | unsigned int GNUNET_SCHEDULER_get_load (struct GNUNET_SCHEDULER_Handle *sched, | ||
232 | enum GNUNET_SCHEDULER_Priority p); | ||
233 | |||
234 | |||
235 | /** | ||
236 | * Cancel the task with the specified identifier. | ||
237 | * The task must not yet have run. | ||
238 | * | ||
239 | * @param sched scheduler to use | ||
240 | * @param task id of the task to cancel | ||
241 | * @return the closure of the callback of the cancelled task | ||
242 | */ | ||
243 | void *GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Handle *sched, | ||
244 | GNUNET_SCHEDULER_TaskIdentifier task); | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Continue the current execution with the given function. This is | ||
249 | * similar to the other "add" functions except that there is no delay | ||
250 | * and the reason code can be specified. | ||
251 | * | ||
252 | * @param sched scheduler to use | ||
253 | * @param main main function of the task | ||
254 | * @param cls closure of task | ||
255 | * @param reason reason for task invocation | ||
256 | */ | ||
257 | void | ||
258 | GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched, | ||
259 | int run_on_shutdown, | ||
260 | GNUNET_SCHEDULER_Task main, | ||
261 | void *cls, | ||
262 | enum GNUNET_SCHEDULER_Reason reason); | ||
263 | |||
264 | |||
265 | /** | ||
266 | * Schedule a new task to be run after the specified | ||
267 | * prerequisite task has completed. | ||
268 | * | ||
269 | * @param sched scheduler to use | ||
270 | * @param run_on_shutdown run on shutdown? | ||
271 | * @param prio how important is this task? | ||
272 | * @param prerequisite_task run this task after the task with the given | ||
273 | * task identifier completes (and any of our other | ||
274 | * conditions, such as delay, read or write-readyness | ||
275 | * are satisfied). Use GNUNET_SCHEDULER_NO_PREREQUISITE_TASK to not have any dependency | ||
276 | * on completion of other tasks. | ||
277 | * @param main main function of the task | ||
278 | * @param cls closure of task | ||
279 | * @return unique task identifier for the job | ||
280 | * only valid until "main" is started! | ||
281 | */ | ||
282 | GNUNET_SCHEDULER_TaskIdentifier | ||
283 | GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched, | ||
284 | int run_on_shutdown, | ||
285 | enum GNUNET_SCHEDULER_Priority prio, | ||
286 | GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | ||
287 | GNUNET_SCHEDULER_Task main, void *cls); | ||
288 | |||
289 | |||
290 | /** | ||
291 | * Schedule a new task to be run with a specified delay. The task | ||
292 | * will be scheduled for execution once the delay has expired and the | ||
293 | * prerequisite task has completed. | ||
294 | * | ||
295 | * @param sched scheduler to use | ||
296 | * @param run_on_shutdown run on shutdown? You can use this | ||
297 | * argument to run a function only during shutdown | ||
298 | * by setting delay to -1. Set this | ||
299 | * argument to GNUNET_NO to skip this task if | ||
300 | * the user requested process termination. | ||
301 | * @param prio how important is this task? | ||
302 | * @param prerequisite_task run this task after the task with the given | ||
303 | * task identifier completes (and any of our other | ||
304 | * conditions, such as delay, read or write-readyness | ||
305 | * are satisfied). Use GNUNET_SCHEDULER_NO_PREREQUISITE_TASK to not have any dependency | ||
306 | * on completion of other tasks. | ||
307 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" | ||
308 | * @param main main function of the task | ||
309 | * @param cls closure of task | ||
310 | * @return unique task identifier for the job | ||
311 | * only valid until "main" is started! | ||
312 | */ | ||
313 | GNUNET_SCHEDULER_TaskIdentifier | ||
314 | GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched, | ||
315 | int run_on_shutdown, | ||
316 | enum GNUNET_SCHEDULER_Priority prio, | ||
317 | GNUNET_SCHEDULER_TaskIdentifier | ||
318 | prerequisite_task, | ||
319 | struct GNUNET_TIME_Relative delay, | ||
320 | GNUNET_SCHEDULER_Task main, void *cls); | ||
321 | |||
322 | |||
323 | /** | ||
324 | * Schedule a new task to be run with a specified delay or when the | ||
325 | * specified file descriptor is ready for reading. The delay can be | ||
326 | * used as a timeout on the socket being ready. The task will be | ||
327 | * scheduled for execution once either the delay has expired or the | ||
328 | * socket operation is ready. | ||
329 | * | ||
330 | * @param sched scheduler to use | ||
331 | * @param run_on_shutdown run on shutdown? Set this | ||
332 | * argument to GNUNET_NO to skip this task if | ||
333 | * the user requested process termination. | ||
334 | * @param prio how important is this task? | ||
335 | * @param prerequisite_task run this task after the task with the given | ||
336 | * task identifier completes (and any of our other | ||
337 | * conditions, such as delay, read or write-readyness | ||
338 | * are satisfied). Use GNUNET_SCHEDULER_NO_PREREQUISITE_TASK to not have any dependency | ||
339 | * on completion of other tasks. | ||
340 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" | ||
341 | * @param rfd read file-descriptor | ||
342 | * @param main main function of the task | ||
343 | * @param cls closure of task | ||
344 | * @return unique task identifier for the job | ||
345 | * only valid until "main" is started! | ||
346 | */ | ||
347 | GNUNET_SCHEDULER_TaskIdentifier | ||
348 | GNUNET_SCHEDULER_add_read (struct GNUNET_SCHEDULER_Handle *sched, | ||
349 | int run_on_shutdown, | ||
350 | enum GNUNET_SCHEDULER_Priority prio, | ||
351 | GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | ||
352 | struct GNUNET_TIME_Relative delay, | ||
353 | int rfd, GNUNET_SCHEDULER_Task main, void *cls); | ||
354 | |||
355 | |||
356 | /** | ||
357 | * Schedule a new task to be run with a specified delay or when the | ||
358 | * specified file descriptor is ready for writing. The delay can be | ||
359 | * used as a timeout on the socket being ready. The task will be | ||
360 | * scheduled for execution once either the delay has expired or the | ||
361 | * socket operation is ready. | ||
362 | * | ||
363 | * @param sched scheduler to use | ||
364 | * @param run_on_shutdown run on shutdown? Set this | ||
365 | * argument to GNUNET_NO to skip this task if | ||
366 | * the user requested process termination. | ||
367 | * @param prio how important is this task? | ||
368 | * @param prerequisite_task run this task after the task with the given | ||
369 | * task identifier completes (and any of our other | ||
370 | * conditions, such as delay, read or write-readyness | ||
371 | * are satisfied). Use GNUNET_SCHEDULER_NO_PREREQUISITE_TASK to not have any dependency | ||
372 | * on completion of other tasks. | ||
373 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" | ||
374 | * @param wfd write file-descriptor | ||
375 | * @param main main function of the task | ||
376 | * @param cls closure of task | ||
377 | * @return unique task identifier for the job | ||
378 | * only valid until "main" is started! | ||
379 | */ | ||
380 | GNUNET_SCHEDULER_TaskIdentifier | ||
381 | GNUNET_SCHEDULER_add_write (struct GNUNET_SCHEDULER_Handle *sched, | ||
382 | int run_on_shutdown, | ||
383 | enum GNUNET_SCHEDULER_Priority prio, | ||
384 | GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | ||
385 | struct GNUNET_TIME_Relative delay, | ||
386 | int wfd, GNUNET_SCHEDULER_Task main, void *cls); | ||
387 | |||
388 | |||
389 | /** | ||
390 | * Schedule a new task to be run with a specified delay or when any of | ||
391 | * the specified file descriptor sets is ready. The delay can be used | ||
392 | * as a timeout on the socket(s) being ready. The task will be | ||
393 | * scheduled for execution once either the delay has expired or any of | ||
394 | * the socket operations is ready. This is the most general | ||
395 | * function of the "add" family. Note that the "prerequisite_task" | ||
396 | * must be satisfied in addition to any of the other conditions. In | ||
397 | * other words, the task will be started when | ||
398 | * <code> | ||
399 | * (prerequisite-run) | ||
400 | * && (delay-ready | ||
401 | * || any-rs-ready | ||
402 | * || any-ws-ready | ||
403 | * || (shutdown-active && run-on-shutdown) ) | ||
404 | * </code> | ||
405 | * | ||
406 | * @param sched scheduler to use | ||
407 | * @param run_on_shutdown run on shutdown? Set this | ||
408 | * argument to GNUNET_NO to skip this task if | ||
409 | * the user requested process termination. | ||
410 | * @param prio how important is this task? | ||
411 | * @param prerequisite_task run this task after the task with the given | ||
412 | * task identifier completes (and any of our other | ||
413 | * conditions, such as delay, read or write-readyness | ||
414 | * are satisfied). Use GNUNET_SCHEDULER_NO_PREREQUISITE_TASK to not have any dependency | ||
415 | * on completion of other tasks. | ||
416 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" | ||
417 | * @param nfds highest-numbered file descriptor in any of the two sets plus one | ||
418 | * @param rs set of file descriptors we want to read (can be NULL) | ||
419 | * @param ws set of file descriptors we want to write (can be NULL) | ||
420 | * @param main main function of the task | ||
421 | * @param cls closure of task | ||
422 | * @return unique task identifier for the job | ||
423 | * only valid until "main" is started! | ||
424 | */ | ||
425 | GNUNET_SCHEDULER_TaskIdentifier | ||
426 | GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched, | ||
427 | int run_on_shutdown, | ||
428 | enum GNUNET_SCHEDULER_Priority prio, | ||
429 | GNUNET_SCHEDULER_TaskIdentifier | ||
430 | prerequisite_task, | ||
431 | struct GNUNET_TIME_Relative delay, | ||
432 | int nfds, const fd_set * rs, const fd_set * ws, | ||
433 | GNUNET_SCHEDULER_Task main, void *cls); | ||
434 | |||
435 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
436 | { | ||
437 | #endif | ||
438 | #ifdef __cplusplus | ||
439 | } | ||
440 | #endif | ||
441 | |||
442 | #endif | ||
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h new file mode 100644 index 000000000..4e4f35e26 --- /dev/null +++ b/src/include/gnunet_server_lib.h | |||
@@ -0,0 +1,498 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 2, 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 include/gnunet_server_lib.h | ||
23 | * @brief library for building GNUnet network servers | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_SERVER_LIB_H | ||
29 | #define GNUNET_SERVER_LIB_H | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" | ||
33 | { | ||
34 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
35 | } | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | #include "gnunet_common.h" | ||
40 | #include "gnunet_network_lib.h" | ||
41 | #include "gnunet_scheduler_lib.h" | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Largest supported message. | ||
46 | */ | ||
47 | #define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536 | ||
48 | |||
49 | |||
50 | /** | ||
51 | * @brief handle for a server | ||
52 | */ | ||
53 | struct GNUNET_SERVER_Handle; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * @brief opaque handle for a client of the server | ||
58 | */ | ||
59 | struct GNUNET_SERVER_Client; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Functions with this signature are called whenever a message is | ||
64 | * received. | ||
65 | * | ||
66 | * @param cls closure | ||
67 | * @param server the server handling the message | ||
68 | * @param client identification of the client | ||
69 | * @param message the actual message | ||
70 | */ | ||
71 | typedef void (*GNUNET_SERVER_MessageCallback) (void *cls, | ||
72 | struct GNUNET_SERVER_Handle * | ||
73 | server, | ||
74 | struct GNUNET_SERVER_Client * | ||
75 | client, | ||
76 | const struct | ||
77 | GNUNET_MessageHeader * | ||
78 | message); | ||
79 | |||
80 | |||
81 | |||
82 | /** | ||
83 | * Message handler. Each struct specifies how to handle on particular | ||
84 | * type of message received. | ||
85 | */ | ||
86 | struct GNUNET_SERVER_MessageHandler | ||
87 | { | ||
88 | /** | ||
89 | * Function to call for messages of "type". | ||
90 | */ | ||
91 | GNUNET_SERVER_MessageCallback callback; | ||
92 | |||
93 | /** | ||
94 | * Closure argument for "callback". | ||
95 | */ | ||
96 | void *callback_cls; | ||
97 | |||
98 | /** | ||
99 | * Type of the message this handler covers. | ||
100 | */ | ||
101 | uint16_t type; | ||
102 | |||
103 | /** | ||
104 | * Expected size of messages of this type. Use 0 for | ||
105 | * variable-size. If non-zero, messages of the given | ||
106 | * type will be discarded (and the connection closed) | ||
107 | * if they do not have the right size. | ||
108 | */ | ||
109 | uint16_t expected_size; | ||
110 | |||
111 | }; | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Create a new server. | ||
116 | * | ||
117 | * @param sched scheduler to use | ||
118 | * @param access function for access control | ||
119 | * @param access_cls closure for access | ||
120 | * @param serverAddr address to listen on (including port), use NULL | ||
121 | * for internal server (no listening) | ||
122 | * @param socklen length of serverAddr | ||
123 | * @param maxbuf maximum write buffer size for accepted sockets | ||
124 | * @param idle_timeout after how long should we timeout idle connections? | ||
125 | * @param require_found if YES, connections sending messages of unknown type | ||
126 | * will be closed | ||
127 | * @return handle for the new server, NULL on error | ||
128 | * (typically, "port" already in use) | ||
129 | */ | ||
130 | struct GNUNET_SERVER_Handle *GNUNET_SERVER_create (struct | ||
131 | GNUNET_SCHEDULER_Handle | ||
132 | *sched, | ||
133 | GNUNET_NETWORK_AccessCheck | ||
134 | access, void *access_cls, | ||
135 | const struct sockaddr | ||
136 | *serverAddr, | ||
137 | socklen_t socklen, | ||
138 | size_t maxbuf, | ||
139 | struct GNUNET_TIME_Relative | ||
140 | idle_timeout, | ||
141 | int require_found); | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Free resources held by this server. | ||
146 | */ | ||
147 | void GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s); | ||
148 | |||
149 | |||
150 | /** | ||
151 | * Add additional handlers to an existing server. | ||
152 | * | ||
153 | * @param server the server to add handlers to | ||
154 | * @param handlers array of message handlers for | ||
155 | * incoming messages; the last entry must | ||
156 | * have "NULL" for the "callback"; multiple | ||
157 | * entries for the same type are allowed, | ||
158 | * they will be called in order of occurence. | ||
159 | * These handlers can be removed later; | ||
160 | * the handlers array must exist until removed | ||
161 | * (or server is destroyed). | ||
162 | */ | ||
163 | void | ||
164 | GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, | ||
165 | const struct GNUNET_SERVER_MessageHandler | ||
166 | *handlers); | ||
167 | |||
168 | |||
169 | /** | ||
170 | * Notify us when the server has enough space to transmit | ||
171 | * a message of the given size to the given client. | ||
172 | * | ||
173 | * @param client client to transmit message to | ||
174 | * @param size requested amount of buffer space | ||
175 | * @param timeout after how long should we give up (and call | ||
176 | * notify with buf NULL and size 0)? | ||
177 | * @param callback function to call when space is available | ||
178 | * @param callback_cls closure for callback | ||
179 | * @return non-NULL if the notify callback was queued; can be used | ||
180 | * to cancel the request using | ||
181 | * GNUNET_NETWORK_notify_transmit_ready_cancel. | ||
182 | * NULL if we are already going to notify someone else (busy) | ||
183 | */ | ||
184 | struct GNUNET_NETWORK_TransmitHandle | ||
185 | *GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | ||
186 | size_t size, | ||
187 | struct GNUNET_TIME_Relative timeout, | ||
188 | GNUNET_NETWORK_TransmitReadyNotify | ||
189 | callback, void *callback_cls); | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Resume receiving from this client, we are done processing the | ||
194 | * current request. This function must be called from within each | ||
195 | * GNUNET_SERVER_MessageCallback (or its respective continuations). | ||
196 | * | ||
197 | * @param client client we were processing a message of | ||
198 | * @param success GNUNET_OK to keep the connection open and | ||
199 | * continue to receive | ||
200 | * GNUNET_SYSERR to close the connection (signal | ||
201 | * serious error) | ||
202 | */ | ||
203 | void | ||
204 | GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success); | ||
205 | |||
206 | |||
207 | /** | ||
208 | * Inject a message into the server, pretend it came | ||
209 | * from the specified client. Delivery of the message | ||
210 | * will happen instantly (if a handler is installed; | ||
211 | * otherwise the call does nothing). | ||
212 | * | ||
213 | * @param server the server receiving the message | ||
214 | * @param sender the "pretended" sender of the message | ||
215 | * can be NULL! | ||
216 | * @param message message to transmit | ||
217 | * @return GNUNET_OK if the message was OK and the | ||
218 | * connection can stay open | ||
219 | * GNUNET_SYSERR if the connection to the | ||
220 | * client should be shut down | ||
221 | */ | ||
222 | int | ||
223 | GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, | ||
224 | struct GNUNET_SERVER_Client *sender, | ||
225 | const struct GNUNET_MessageHeader *message); | ||
226 | |||
227 | |||
228 | /** | ||
229 | * Add a TCP socket-based connection to the set of handles managed by | ||
230 | * this server. Use this function for outgoing (P2P) connections that | ||
231 | * we initiated (and where this server should process incoming | ||
232 | * messages). | ||
233 | * | ||
234 | * @param server the server to use | ||
235 | * @param connection the connection to manage (client must | ||
236 | * stop using this connection from now on) | ||
237 | * @return the client handle (client should call | ||
238 | * "client_drop" on the return value eventually) | ||
239 | */ | ||
240 | struct GNUNET_SERVER_Client *GNUNET_SERVER_connect_socket (struct | ||
241 | GNUNET_SERVER_Handle | ||
242 | *server, | ||
243 | struct | ||
244 | GNUNET_NETWORK_SocketHandle | ||
245 | *connection); | ||
246 | |||
247 | |||
248 | /** | ||
249 | * Receive data from the given connection. This function should call | ||
250 | * "receiver" asynchronously using the scheduler. It must return | ||
251 | * "immediately". | ||
252 | * | ||
253 | * @param cls closure | ||
254 | * @param sched scheduler to use | ||
255 | * @param max maximum number of bytes to read | ||
256 | * @param timeout maximum amount of time to wait (use -1 for "forever") | ||
257 | * @param receiver function to call with received data | ||
258 | * @param receiver_cls closure for receiver | ||
259 | * @return task identifier that can be used to cancel the receive, | ||
260 | * GNUNET_SCHEDULER_NO_PREREQUISITE_TASK should be returned | ||
261 | * if the receiver function was already called | ||
262 | */ | ||
263 | typedef GNUNET_SCHEDULER_TaskIdentifier | ||
264 | (*GNUNET_SERVER_ReceiveCallback) (void *cls, | ||
265 | size_t max, | ||
266 | struct GNUNET_TIME_Relative timeout, | ||
267 | GNUNET_NETWORK_Receiver | ||
268 | receiver, void *receiver_cls); | ||
269 | |||
270 | |||
271 | /** | ||
272 | * Cancel receive request. | ||
273 | * | ||
274 | * @param cls closure | ||
275 | * @param ti task identifier from the receive callback | ||
276 | */ | ||
277 | typedef void (*GNUNET_SERVER_ReceiveCancelCallback) (void *cls, | ||
278 | GNUNET_SCHEDULER_TaskIdentifier | ||
279 | ti); | ||
280 | |||
281 | |||
282 | /** | ||
283 | * Notify us when the connection is ready to transmit size bytes. | ||
284 | * | ||
285 | * @param cls closure | ||
286 | * @param size number of bytes to be ready for sending | ||
287 | * @param timeout after how long should we give up (and call | ||
288 | * notify with buf NULL and size 0)? | ||
289 | * @param notify function to call | ||
290 | * @param notify_cls closure for notify | ||
291 | * @return a handle that can be used to cancel | ||
292 | * the transmission request or NULL if | ||
293 | * queueing a transmission request failed | ||
294 | */ | ||
295 | typedef void *(*GNUNET_SERVER_TransmitReadyCallback) (void *cls, | ||
296 | size_t size, | ||
297 | struct | ||
298 | GNUNET_TIME_Relative | ||
299 | timeout, | ||
300 | GNUNET_NETWORK_TransmitReadyNotify | ||
301 | notify, | ||
302 | void *notify_cls); | ||
303 | |||
304 | |||
305 | /** | ||
306 | * Cancel an earlier transmit notification request. | ||
307 | * | ||
308 | * @param cls closure | ||
309 | * @param ctx handle that was returned by the TransmitReadyCallback | ||
310 | */ | ||
311 | typedef void (*GNUNET_SERVER_TransmitReadyCancelCallback) (void *cls, | ||
312 | void *ctx); | ||
313 | |||
314 | |||
315 | /** | ||
316 | * Check if connection is still valid (no fatal errors have happened so far). | ||
317 | * | ||
318 | * @param cls closure | ||
319 | * @return GNUNET_YES if valid, GNUNET_NO otherwise | ||
320 | */ | ||
321 | typedef int (*GNUNET_SERVER_CheckCallback) (void *cls); | ||
322 | |||
323 | |||
324 | /** | ||
325 | * Destroy this connection (free resources). | ||
326 | * | ||
327 | * @param cls closure | ||
328 | */ | ||
329 | typedef void (*GNUNET_SERVER_DestroyCallback) (void *cls); | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Add an arbitrary connection to the set of handles managed by this | ||
334 | * server. This can be used if a sending and receiving does not | ||
335 | * really go over the network (internal transmission) or for servers | ||
336 | * using UDP. | ||
337 | * | ||
338 | * @param server the server to use | ||
339 | * @param chandle opaque handle for the connection | ||
340 | * @param creceive receive function for the connection | ||
341 | * @param creceive_cancel cancel receive function for the connection | ||
342 | * @param cnotify transmit notification function for the connection | ||
343 | * @param cnotify_cancel transmit notification cancellation function for the connection | ||
344 | * @param ccheck function to test if the connection is still up | ||
345 | * @param cdestroy function to close and free the connection | ||
346 | * @return the client handle (client should call | ||
347 | * "client_drop" on the return value eventually) | ||
348 | */ | ||
349 | struct GNUNET_SERVER_Client *GNUNET_SERVER_connect_callback (struct | ||
350 | GNUNET_SERVER_Handle | ||
351 | *server, | ||
352 | void *chandle, | ||
353 | GNUNET_SERVER_ReceiveCallback | ||
354 | creceive, | ||
355 | GNUNET_SERVER_ReceiveCancelCallback | ||
356 | ccancel, | ||
357 | GNUNET_SERVER_TransmitReadyCallback | ||
358 | cnotify, | ||
359 | GNUNET_SERVER_TransmitReadyCancelCallback | ||
360 | cnotify_cancel, | ||
361 | GNUNET_SERVER_CheckCallback | ||
362 | ccheck, | ||
363 | GNUNET_SERVER_DestroyCallback | ||
364 | cdestroy); | ||
365 | |||
366 | |||
367 | /** | ||
368 | * Notify the server that the given client handle should | ||
369 | * be kept (keeps the connection up if possible, increments | ||
370 | * the internal reference counter). | ||
371 | * | ||
372 | * @param client the client to keep | ||
373 | */ | ||
374 | void GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client); | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Notify the server that the given client handle is no | ||
379 | * longer required. Decrements the reference counter. If | ||
380 | * that counter reaches zero an inactive connection maybe | ||
381 | * closed. | ||
382 | * | ||
383 | * @param client the client to drop | ||
384 | */ | ||
385 | void GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); | ||
386 | |||
387 | |||
388 | /** | ||
389 | * Obtain the network address of the other party. | ||
390 | * | ||
391 | * @param client the client to get the address for | ||
392 | * @param addr where to store the address | ||
393 | * @param addrlen where to store the length of the address | ||
394 | * @return GNUNET_OK on success | ||
395 | */ | ||
396 | int GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, | ||
397 | void **addr, size_t * addrlen); | ||
398 | |||
399 | |||
400 | /** | ||
401 | * Functions with this signature are called whenever a client | ||
402 | * is disconnected on the network level. | ||
403 | * | ||
404 | * @param cls closure | ||
405 | * @param client identification of the client | ||
406 | */ | ||
407 | typedef void (*GNUNET_SERVER_DisconnectCallback) (void *cls, | ||
408 | struct GNUNET_SERVER_Client | ||
409 | * client); | ||
410 | |||
411 | |||
412 | /** | ||
413 | * Ask the server to notify us whenever a client disconnects. | ||
414 | * This function is called whenever the actual network connection | ||
415 | * is closed; the reference count may be zero or larger than zero | ||
416 | * at this point. | ||
417 | * | ||
418 | * @param server the server manageing the clients | ||
419 | * @param callback function to call on disconnect | ||
420 | * @param callback_cls closure for callback | ||
421 | */ | ||
422 | void GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, | ||
423 | GNUNET_SERVER_DisconnectCallback | ||
424 | callback, void *callback_cls); | ||
425 | |||
426 | |||
427 | /** | ||
428 | * Ask the server to disconnect from the given client. | ||
429 | * This is the same as returning GNUNET_SYSERR from a message | ||
430 | * handler, except that it allows dropping of a client even | ||
431 | * when not handling a message from that client. | ||
432 | * | ||
433 | * @param client the client to disconnect from | ||
434 | */ | ||
435 | void GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); | ||
436 | |||
437 | |||
438 | /** | ||
439 | * The tansmit context is the key datastructure for a conveniance API | ||
440 | * used for transmission of complex results to the client followed | ||
441 | * ONLY by signaling receive_done with success or error | ||
442 | */ | ||
443 | struct GNUNET_SERVER_TransmitContext; | ||
444 | |||
445 | |||
446 | /** | ||
447 | * Create a new transmission context for the | ||
448 | * given client. | ||
449 | * | ||
450 | * @param client client to create the context for. | ||
451 | * @return NULL on error | ||
452 | */ | ||
453 | struct GNUNET_SERVER_TransmitContext | ||
454 | *GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client | ||
455 | *client); | ||
456 | |||
457 | |||
458 | /** | ||
459 | * Append a message to the transmission context. | ||
460 | * All messages in the context will be sent by | ||
461 | * the transmit_context_run method. | ||
462 | * | ||
463 | * @param tc context to use | ||
464 | * @param data what to append to the result message | ||
465 | * @param length length of data | ||
466 | * @param type type of the message | ||
467 | */ | ||
468 | void | ||
469 | GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext | ||
470 | *tc, const void *data, size_t length, | ||
471 | uint16_t type); | ||
472 | |||
473 | /** | ||
474 | * Execute a transmission context. If there is | ||
475 | * an error in the transmission, the receive_done | ||
476 | * method will be called with an error code (GNUNET_SYSERR), | ||
477 | * otherwise with GNUNET_OK. | ||
478 | * | ||
479 | * @param tc transmission context to use | ||
480 | * @param timeout when to time out and abort the transmission | ||
481 | */ | ||
482 | void | ||
483 | GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, | ||
484 | struct GNUNET_TIME_Relative timeout); | ||
485 | |||
486 | |||
487 | |||
488 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
489 | { | ||
490 | #endif | ||
491 | #ifdef __cplusplus | ||
492 | } | ||
493 | #endif | ||
494 | |||
495 | |||
496 | /* ifndef GNUNET_SERVER_LIB_H */ | ||
497 | #endif | ||
498 | /* end of gnunet_server_lib.h */ | ||
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h new file mode 100644 index 000000000..dbfb2588b --- /dev/null +++ b/src/include/gnunet_service_lib.h | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 2, 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 include/gnunet_service_lib.h | ||
23 | * @brief functions related to starting services | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_SERVICE_LIB_H | ||
28 | #define GNUNET_SERVICE_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_configuration_lib.h" | ||
39 | #include "gnunet_server_lib.h" | ||
40 | |||
41 | /** | ||
42 | * Function called by the service's run | ||
43 | * method to run service-specific setup code. | ||
44 | * | ||
45 | * @param cls closure | ||
46 | * @param sched scheduler to use | ||
47 | * @param server the initialized server | ||
48 | * @param cfg configuration to use | ||
49 | */ | ||
50 | typedef void (*GNUNET_SERVICE_Main) (void *cls, | ||
51 | struct GNUNET_SCHEDULER_Handle * sched, | ||
52 | struct GNUNET_SERVER_Handle * server, | ||
53 | struct GNUNET_CONFIGURATION_Handle * | ||
54 | cfg); | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Function called when the service shuts | ||
59 | * down to run service-specific teardown code. | ||
60 | * | ||
61 | * @param cls closure | ||
62 | * @param cfg configuration to use | ||
63 | */ | ||
64 | typedef void (*GNUNET_SERVICE_Term) (void *cls, | ||
65 | struct GNUNET_CONFIGURATION_Handle * | ||
66 | cfg); | ||
67 | |||
68 | |||
69 | /** | ||
70 | * Run a standard GNUnet service startup sequence (initialize loggers | ||
71 | * and configuration, parse options). | ||
72 | * | ||
73 | * @param argc number of command line arguments | ||
74 | * @param argv command line arguments | ||
75 | * @param serviceName our service name | ||
76 | * @param task main task of the service | ||
77 | * @param task_cls closure for task | ||
78 | * @param term termination task of the service | ||
79 | * @param term_cls closure for term | ||
80 | * @return GNUNET_SYSERR on error, GNUNET_OK | ||
81 | * if we shutdown nicely | ||
82 | */ | ||
83 | int GNUNET_SERVICE_run (int argc, | ||
84 | char *const *argv, | ||
85 | const char *serviceName, | ||
86 | GNUNET_SERVICE_Main task, | ||
87 | void *task_cls, | ||
88 | GNUNET_SERVICE_Term term, void *term_cls); | ||
89 | |||
90 | |||
91 | struct GNUNET_SERVICE_Context; | ||
92 | |||
93 | /** | ||
94 | * Run a service startup sequence within an existing | ||
95 | * initialized system. | ||
96 | * | ||
97 | * @param serviceName our service name | ||
98 | * @param sched scheduler to use | ||
99 | * @param cfg configuration to use | ||
100 | * @return NULL on error, service handle | ||
101 | */ | ||
102 | struct GNUNET_SERVICE_Context *GNUNET_SERVICE_start (const char *serviceName, | ||
103 | struct | ||
104 | GNUNET_SCHEDULER_Handle | ||
105 | *sched, | ||
106 | struct | ||
107 | GNUNET_CONFIGURATION_Handle | ||
108 | *cfg); | ||
109 | |||
110 | |||
111 | /** | ||
112 | * Obtain the server used by a service. Note that the server must NOT | ||
113 | * be destroyed by the caller. | ||
114 | * | ||
115 | * @param ctx the service context returned from the start function | ||
116 | * @return handle to the server for this service, NULL if there is none | ||
117 | */ | ||
118 | struct GNUNET_SERVER_Handle *GNUNET_SERVICE_get_server (struct | ||
119 | GNUNET_SERVICE_Context | ||
120 | *ctx); | ||
121 | |||
122 | |||
123 | /** | ||
124 | * Stop a service that was started with "GNUNET_SERVICE_start". | ||
125 | * | ||
126 | * @param ctx the service context returned from the start function | ||
127 | */ | ||
128 | void GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *ctx); | ||
129 | |||
130 | |||
131 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
132 | { | ||
133 | #endif | ||
134 | #ifdef __cplusplus | ||
135 | } | ||
136 | #endif | ||
137 | |||
138 | /* ifndef GNUNET_SERVICE_LIB_H */ | ||
139 | #endif | ||
140 | /* end of gnunet_service_lib.h */ | ||
diff --git a/src/include/gnunet_signal_lib.h b/src/include/gnunet_signal_lib.h new file mode 100644 index 000000000..af1ec0de4 --- /dev/null +++ b/src/include/gnunet_signal_lib.h | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_signal_lib.h | ||
23 | * @brief functions related to signals | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_SIGNAL_LIB_H | ||
28 | #define GNUNET_SIGNAL_LIB_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | struct GNUNET_SIGNAL_Context; | ||
39 | |||
40 | /** | ||
41 | * A signal handler. Since different OSes have different signatures | ||
42 | * for their handlers, the API only gives the most restrictive | ||
43 | * signature -- no arguments, no return value. Note that this will | ||
44 | * work even if the OS expects a function with arguments. However, | ||
45 | * the implementation must guarantee that this handler is not called | ||
46 | * for signals other than the one that it has been registered for. | ||
47 | */ | ||
48 | typedef void (*GNUNET_SIGNAL_Handler) (void); | ||
49 | |||
50 | /** | ||
51 | * Install a signal handler that will be run if the | ||
52 | * given signal is received. | ||
53 | */ | ||
54 | struct GNUNET_SIGNAL_Context *GNUNET_SIGNAL_handler_install (int signal, | ||
55 | GNUNET_SIGNAL_Handler | ||
56 | handler); | ||
57 | |||
58 | /** | ||
59 | * Uninstall a previously installed signal hander. | ||
60 | */ | ||
61 | void GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx); | ||
62 | |||
63 | |||
64 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
65 | { | ||
66 | #endif | ||
67 | #ifdef __cplusplus | ||
68 | } | ||
69 | #endif | ||
70 | |||
71 | /* ifndef GNUNET_SIGNAL_LIB_H */ | ||
72 | #endif | ||
73 | /* end of gnunet_signal_lib.h */ | ||
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h new file mode 100644 index 000000000..adb00c1ac --- /dev/null +++ b/src/include/gnunet_signatures.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 2, 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 include/gnunet_signatures.h | ||
23 | * @brief constants for network signatures | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_SIGNATURES_H | ||
28 | #define GNUNET_SIGNATURES_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | /** | ||
39 | * Test signature, not valid for anything other than writing | ||
40 | * a test. (Note that the signature verification code will | ||
41 | * accept this value). | ||
42 | */ | ||
43 | #define GNUNET_SIGNATURE_PURPOSE_TEST 0 | ||
44 | |||
45 | /** | ||
46 | * Signature for confirming HELLOs. | ||
47 | */ | ||
48 | #define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_HELLO 1 | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Purpose is to set a session key. | ||
53 | */ | ||
54 | #define GNUNET_SIGNATURE_PURPOSE_SET_KEY 2 | ||
55 | |||
56 | /** | ||
57 | * Signature for a namespace/pseudonym advertisement (by | ||
58 | * the namespace owner). | ||
59 | */ | ||
60 | #define GNUNET_SIGNATURE_PURPOSE_NAMESPACE_ADVERTISEMENT 3 | ||
61 | |||
62 | /** | ||
63 | * | ||
64 | */ | ||
65 | #define GNUNET_SIGNATURE_PURPOSE_RESOLVER_RESPONSE 3 | ||
66 | |||
67 | |||
68 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
69 | { | ||
70 | #endif | ||
71 | #ifdef __cplusplus | ||
72 | } | ||
73 | #endif | ||
74 | |||
75 | /* ifndef GNUNET_SIGNATURES_H */ | ||
76 | #endif | ||
77 | /* end of gnunet_signatures.h */ | ||
diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h new file mode 100644 index 000000000..8dd11094c --- /dev/null +++ b/src/include/gnunet_statistics_service.h | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 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 2, 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 include/gnunet_statistics_service.h | ||
23 | * @brief API to create, modify and access statistics about | ||
24 | * the operation of GNUnet; all statistical values | ||
25 | * must be of type "unsigned long long". | ||
26 | * @author Christian Grothoff | ||
27 | */ | ||
28 | |||
29 | #ifndef GNUNET_STATISTICS_SERVICE_H | ||
30 | #define GNUNET_STATISTICS_SERVICE_H | ||
31 | |||
32 | #ifdef __cplusplus | ||
33 | extern "C" | ||
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | #include "gnunet_common.h" | ||
41 | #include "gnunet_configuration_lib.h" | ||
42 | #include "gnunet_scheduler_lib.h" | ||
43 | |||
44 | /** | ||
45 | * Version of the statistics API. | ||
46 | */ | ||
47 | #define GNUNET_STATISTICS_VERSION 0x00000000 | ||
48 | |||
49 | /** | ||
50 | * Opaque handle for the statistics service. | ||
51 | */ | ||
52 | struct GNUNET_STATISTICS_Handle; | ||
53 | |||
54 | /** | ||
55 | * Callback function to process statistic values. | ||
56 | * | ||
57 | * @param cls closure | ||
58 | * @param subsystem name of subsystem that created the statistic | ||
59 | * @param name the name of the datum | ||
60 | * @param value the current value | ||
61 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | ||
62 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | ||
63 | */ | ||
64 | typedef int (*GNUNET_STATISTICS_Iterator) (void *cls, | ||
65 | const char *subsystem, | ||
66 | const char *name, | ||
67 | unsigned long long value, | ||
68 | int is_persistent); | ||
69 | |||
70 | /** | ||
71 | * Get handle for the statistics service. | ||
72 | * | ||
73 | * @param sched scheduler to use | ||
74 | * @param subsystem name of subsystem using the service | ||
75 | * @param cfg services configuration in use | ||
76 | * @return handle to use | ||
77 | */ | ||
78 | struct GNUNET_STATISTICS_Handle | ||
79 | *GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched, | ||
80 | const char *subsystem, | ||
81 | struct GNUNET_CONFIGURATION_Handle *cfg); | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Destroy a handle (free all state associated with | ||
86 | * it). | ||
87 | */ | ||
88 | void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *handle); | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Continuation called by the "get_all" and "get" functions. | ||
93 | * | ||
94 | * @param cls closure | ||
95 | * @param success GNUNET_OK if statistics were | ||
96 | * successfully obtained, GNUNET_SYSERR if not. | ||
97 | */ | ||
98 | typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success); | ||
99 | |||
100 | /** | ||
101 | * Get statistic from the peer. | ||
102 | * | ||
103 | * @param handle identification of the statistics service | ||
104 | * @param subsystem limit to the specified subsystem, NULL for our subsystem | ||
105 | * @param name name of the statistic value, NULL for all values | ||
106 | * @param timeout after how long should we give up (and call | ||
107 | * notify with buf NULL and size 0)? | ||
108 | * @param cont continuation to call when done (can be NULL) | ||
109 | * @param proc function to call on each value | ||
110 | * @param cls closure for proc and cont | ||
111 | */ | ||
112 | void | ||
113 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | ||
114 | const char *subsystem, | ||
115 | const char *name, | ||
116 | struct GNUNET_TIME_Relative timeout, | ||
117 | GNUNET_STATISTICS_Callback cont, | ||
118 | GNUNET_STATISTICS_Iterator proc, void *cls); | ||
119 | |||
120 | /** | ||
121 | * Set statistic value for the peer. Will always use our | ||
122 | * subsystem (the argument used when "handle" was created). | ||
123 | * | ||
124 | * @param handle identification of the statistics service | ||
125 | * @param name name of the statistic value | ||
126 | * @param value new value to set | ||
127 | * @param make_persistent should the value be kept across restarts? | ||
128 | */ | ||
129 | void | ||
130 | GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, | ||
131 | const char *name, | ||
132 | unsigned long long value, int make_persistent); | ||
133 | |||
134 | /** | ||
135 | * Set statistic value for the peer. Will always use our | ||
136 | * subsystem (the argument used when "handle" was created). | ||
137 | * | ||
138 | * @param handle identification of the statistics service | ||
139 | * @param name name of the statistic value | ||
140 | * @param delta change in value (added to existing value) | ||
141 | * @param make_persistent should the value be kept across restarts? | ||
142 | */ | ||
143 | void | ||
144 | GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, | ||
145 | const char *name, | ||
146 | long long delta, int make_persistent); | ||
147 | |||
148 | |||
149 | |||
150 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
151 | { | ||
152 | #endif | ||
153 | #ifdef __cplusplus | ||
154 | } | ||
155 | #endif | ||
156 | |||
157 | #endif | ||
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h new file mode 100644 index 000000000..98d2ed396 --- /dev/null +++ b/src/include/gnunet_strings_lib.h | |||
@@ -0,0 +1,139 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_strings_lib.h | ||
23 | * @brief strings and string handling functions (including malloc | ||
24 | * and string tokenizing) | ||
25 | * | ||
26 | * @author Christian Grothoff | ||
27 | * @author Krista Bennett | ||
28 | * @author Gerd Knorr <kraxel@bytesex.org> | ||
29 | * @author Ioana Patrascu | ||
30 | * @author Tzvetan Horozov | ||
31 | */ | ||
32 | |||
33 | #ifndef GNUNET_STRINGS_LIB_H | ||
34 | #define GNUNET_STRINGS_LIB_H | ||
35 | |||
36 | /* we need size_t, and since it can be both unsigned int | ||
37 | or unsigned long long, this IS platform dependent; | ||
38 | but "stdlib.h" should be portable 'enough' to be | ||
39 | unconditionally available... */ | ||
40 | #include <stdlib.h> | ||
41 | |||
42 | #ifdef __cplusplus | ||
43 | extern "C" | ||
44 | { | ||
45 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
46 | } | ||
47 | #endif | ||
48 | #endif | ||
49 | |||
50 | #include "gnunet_time_lib.h" | ||
51 | |||
52 | |||
53 | /** | ||
54 | * Convert a given filesize into a fancy human-readable format. | ||
55 | */ | ||
56 | char *GNUNET_STRINGS_byte_size_fancy (unsigned long long size); | ||
57 | |||
58 | /** | ||
59 | * Convert the len characters long character sequence | ||
60 | * given in input that is in the given charset | ||
61 | * to UTF-8. | ||
62 | * | ||
63 | * @return the converted string (0-terminated) | ||
64 | */ | ||
65 | char *GNUNET_STRINGS_to_utf8 (const char *input, | ||
66 | size_t len, const char *charset); | ||
67 | |||
68 | /** | ||
69 | * Complete filename (a la shell) from abbrevition. | ||
70 | * | ||
71 | * @param fil the name of the file, may contain ~/ or | ||
72 | * be relative to the current directory | ||
73 | * @returns the full file name, | ||
74 | * NULL is returned on error | ||
75 | */ | ||
76 | char *GNUNET_STRINGS_filename_expand (const char *fil); | ||
77 | |||
78 | /** | ||
79 | * Fill a buffer of the given size with | ||
80 | * count 0-terminated strings (given as varargs). | ||
81 | * If "buffer" is NULL, only compute the amount of | ||
82 | * space required (sum of "strlen(arg)+1"). | ||
83 | * | ||
84 | * Unlike using "snprintf" with "%s", this function | ||
85 | * will add 0-terminators after each string. The | ||
86 | * "GNUNET_string_buffer_tokenize" function can be | ||
87 | * used to parse the buffer back into individual | ||
88 | * strings. | ||
89 | * | ||
90 | * @return number of bytes written to the buffer | ||
91 | * (or number of bytes that would have been written) | ||
92 | */ | ||
93 | unsigned int GNUNET_STRINGS_buffer_fill (char *buffer, | ||
94 | unsigned int size, | ||
95 | unsigned int count, ...); | ||
96 | |||
97 | /** | ||
98 | * Given a buffer of a given size, find "count" | ||
99 | * 0-terminated strings in the buffer and assign | ||
100 | * the count (varargs) of type "const char**" to the | ||
101 | * locations of the respective strings in the | ||
102 | * buffer. | ||
103 | * | ||
104 | * @param buffer the buffer to parse | ||
105 | * @param size size of the buffer | ||
106 | * @param count number of strings to locate | ||
107 | * @return offset of the character after the last 0-termination | ||
108 | * in the buffer, or 0 on error. | ||
109 | */ | ||
110 | unsigned int GNUNET_STRINGS_buffer_tokenize (const char *buffer, | ||
111 | unsigned int size, | ||
112 | unsigned int count, ...); | ||
113 | |||
114 | |||
115 | |||
116 | /** | ||
117 | * "man ctime_r", except for GNUnet time; also, unlike ctime, the | ||
118 | * return value does not include the newline character. | ||
119 | */ | ||
120 | char *GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t); | ||
121 | |||
122 | |||
123 | /** | ||
124 | * Give relative time in human-readable fancy format. | ||
125 | * @param delta time in milli seconds | ||
126 | */ | ||
127 | char *GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative | ||
128 | delta); | ||
129 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
130 | { | ||
131 | #endif | ||
132 | #ifdef __cplusplus | ||
133 | } | ||
134 | #endif | ||
135 | |||
136 | |||
137 | /* ifndef GNUNET_UTIL_STRING_H */ | ||
138 | #endif | ||
139 | /* end of gnunet_util_string.h */ | ||
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h new file mode 100644 index 000000000..4ce1e3f1e --- /dev/null +++ b/src/include/gnunet_time_lib.h | |||
@@ -0,0 +1,246 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/gnunet_time_lib.h | ||
23 | * @brief functions related to time | ||
24 | * | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_TIME_LIB_H | ||
29 | #define GNUNET_TIME_LIB_H | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" | ||
33 | { | ||
34 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
35 | } | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | #include "gnunet_common.h" | ||
40 | |||
41 | /** | ||
42 | * Time for absolute times used by GNUnet, in milliseconds. | ||
43 | */ | ||
44 | struct GNUNET_TIME_Absolute | ||
45 | { | ||
46 | uint64_t value; | ||
47 | }; | ||
48 | |||
49 | /** | ||
50 | * Time for relative time used by GNUnet, in milliseconds. | ||
51 | * Always positive, so we can only refer to future time. | ||
52 | */ | ||
53 | struct GNUNET_TIME_Relative | ||
54 | { | ||
55 | uint64_t value; | ||
56 | }; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Time for relative time used by GNUnet, in milliseconds and in network byte order. | ||
61 | */ | ||
62 | struct GNUNET_TIME_RelativeNBO | ||
63 | { | ||
64 | uint64_t value GNUNET_PACKED; | ||
65 | }; | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Time for absolute time used by GNUnet, in milliseconds and in network byte order. | ||
70 | */ | ||
71 | struct GNUNET_TIME_AbsoluteNBO | ||
72 | { | ||
73 | uint64_t value GNUNET_PACKED; | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * @brief constants to specify time | ||
78 | */ | ||
79 | #define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero() | ||
80 | #define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_unit() | ||
81 | #define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1000) | ||
82 | #define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | ||
83 | #define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) | ||
84 | #define GNUNET_TIME_UNIT_DAYS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 24) | ||
85 | #define GNUNET_TIME_UNIT_WEEKS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 7) | ||
86 | #define GNUNET_TIME_UNIT_MONTHS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 30) | ||
87 | #define GNUNET_TIME_UNIT_YEARS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 365) | ||
88 | |||
89 | /** | ||
90 | * Constant used to specify "forever". This constant | ||
91 | * will be treated specially in all time operations. | ||
92 | */ | ||
93 | #define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever () | ||
94 | |||
95 | /** | ||
96 | * Constant used to specify "forever". This constant | ||
97 | * will be treated specially in all time operations. | ||
98 | */ | ||
99 | #define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever () | ||
100 | |||
101 | /** | ||
102 | * Return relative time of 0ms. | ||
103 | */ | ||
104 | struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero (void); | ||
105 | |||
106 | /** | ||
107 | * Return relative time of 1ms. | ||
108 | */ | ||
109 | struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit (void); | ||
110 | |||
111 | /** | ||
112 | * Return "forever". | ||
113 | */ | ||
114 | struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever (void); | ||
115 | |||
116 | /** | ||
117 | * Return "forever". | ||
118 | */ | ||
119 | struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever (void); | ||
120 | |||
121 | /** | ||
122 | * Get the current time. | ||
123 | * | ||
124 | * @return the current time | ||
125 | */ | ||
126 | struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get (void); | ||
127 | |||
128 | /** | ||
129 | * Convert relative time to an absolute time in the | ||
130 | * future. | ||
131 | * | ||
132 | * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow) | ||
133 | */ | ||
134 | struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct | ||
135 | GNUNET_TIME_Relative | ||
136 | rel); | ||
137 | |||
138 | /** | ||
139 | * Given a timestamp in the future, how much time | ||
140 | * remains until then? | ||
141 | * | ||
142 | * @return future - now, or 0 if now >= future, or FOREVER if future==FOREVER. | ||
143 | */ | ||
144 | struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct | ||
145 | GNUNET_TIME_Absolute | ||
146 | future); | ||
147 | |||
148 | /** | ||
149 | * Compute the time difference between the given start and end times. | ||
150 | * Use this function instead of actual subtraction to ensure that | ||
151 | * "FOREVER" and overflows are handeled correctly. | ||
152 | * | ||
153 | * @return 0 if start >= end; FOREVER if end==FOREVER; otherwise end - start | ||
154 | */ | ||
155 | struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct | ||
156 | GNUNET_TIME_Absolute | ||
157 | start, | ||
158 | struct | ||
159 | GNUNET_TIME_Absolute | ||
160 | end); | ||
161 | |||
162 | /** | ||
163 | * Get the duration of an operation as the | ||
164 | * difference of the current time and the given start time "hence". | ||
165 | * | ||
166 | * @return aborts if hence==FOREVER, 0 if hence > now, otherwise now-hence. | ||
167 | */ | ||
168 | struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration (struct | ||
169 | GNUNET_TIME_Absolute | ||
170 | hence); | ||
171 | |||
172 | |||
173 | /** | ||
174 | * Add a given relative duration to the | ||
175 | * given start time. | ||
176 | * | ||
177 | * @return FOREVER if either argument is FOREVER or on overflow; start+duration otherwise | ||
178 | */ | ||
179 | struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct | ||
180 | GNUNET_TIME_Absolute | ||
181 | start, | ||
182 | struct | ||
183 | GNUNET_TIME_Relative | ||
184 | duration); | ||
185 | |||
186 | /** | ||
187 | * Multiply relative time by a given factor. | ||
188 | * | ||
189 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor | ||
190 | */ | ||
191 | struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct | ||
192 | GNUNET_TIME_Relative | ||
193 | rel, | ||
194 | unsigned int | ||
195 | factor); | ||
196 | |||
197 | /** | ||
198 | * Add relative times together. | ||
199 | * | ||
200 | * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise | ||
201 | */ | ||
202 | struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct | ||
203 | GNUNET_TIME_Relative a1, | ||
204 | struct | ||
205 | GNUNET_TIME_Relative | ||
206 | a2); | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Convert relative time to network byte order. | ||
211 | */ | ||
212 | struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct | ||
213 | GNUNET_TIME_Relative | ||
214 | a); | ||
215 | |||
216 | /** | ||
217 | * Convert relative time from network byte order. | ||
218 | */ | ||
219 | struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct | ||
220 | GNUNET_TIME_RelativeNBO | ||
221 | a); | ||
222 | |||
223 | /** | ||
224 | * Convert relative time to network byte order. | ||
225 | */ | ||
226 | struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct | ||
227 | GNUNET_TIME_Absolute | ||
228 | a); | ||
229 | |||
230 | /** | ||
231 | * Convert relative time from network byte order. | ||
232 | */ | ||
233 | struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct | ||
234 | GNUNET_TIME_AbsoluteNBO | ||
235 | a); | ||
236 | |||
237 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
238 | { | ||
239 | #endif | ||
240 | #ifdef __cplusplus | ||
241 | } | ||
242 | #endif | ||
243 | |||
244 | /* ifndef GNUNET_TIME_LIB_H */ | ||
245 | #endif | ||
246 | /* end of gnunet_time_lib.h */ | ||
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h new file mode 100644 index 000000000..25ca388a7 --- /dev/null +++ b/src/include/gnunet_transport_service.h | |||
@@ -0,0 +1,241 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 2, 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 include/gnunet_transport_service.h | ||
23 | * @brief low-level P2P IO | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_TRANSPORT_SERVICE_H | ||
28 | #define GNUNET_TRANSPORT_SERVICE_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_configuration_lib.h" | ||
39 | #include "gnunet_crypto_lib.h" | ||
40 | #include "gnunet_network_lib.h" | ||
41 | #include "gnunet_scheduler_lib.h" | ||
42 | #include "gnunet_time_lib.h" | ||
43 | |||
44 | /** | ||
45 | * Version number of the transport API. | ||
46 | */ | ||
47 | #define GNUNET_TRANSPORT_VERSION 0x00000000 | ||
48 | |||
49 | /** | ||
50 | * Function called by the transport for each received message. | ||
51 | * | ||
52 | * @param cls closure | ||
53 | * @param latency estimated latency for communicating with the | ||
54 | * given peer | ||
55 | * @param peer (claimed) identity of the other peer | ||
56 | * @param message the message | ||
57 | */ | ||
58 | typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, | ||
59 | struct GNUNET_TIME_Relative | ||
60 | latency, | ||
61 | const struct | ||
62 | GNUNET_PeerIdentity * peer, | ||
63 | const struct | ||
64 | GNUNET_MessageHeader * | ||
65 | message); | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Opaque handle to the service. | ||
70 | */ | ||
71 | struct GNUNET_TRANSPORT_Handle; | ||
72 | |||
73 | |||
74 | /** | ||
75 | * Function called to notify transport users that another | ||
76 | * peer connected to us. | ||
77 | * | ||
78 | * @param cls closure | ||
79 | * @param peer the peer that connected | ||
80 | * @param latency current latency of the connection | ||
81 | */ | ||
82 | typedef void | ||
83 | (*GNUNET_TRANSPORT_NotifyConnect) (void *cls, | ||
84 | const struct GNUNET_PeerIdentity * peer, | ||
85 | struct GNUNET_TIME_Relative latency); | ||
86 | |||
87 | /** | ||
88 | * Function called to notify transport users that another | ||
89 | * peer disconnected from us. | ||
90 | * | ||
91 | * @param cls closure | ||
92 | * @param peer the peer that disconnected | ||
93 | */ | ||
94 | typedef void | ||
95 | (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls, | ||
96 | const struct GNUNET_PeerIdentity * | ||
97 | peer); | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Connect to the transport service. Note that the connection may | ||
102 | * complete (or fail) asynchronously. | ||
103 | * | ||
104 | * @param sched scheduler to use | ||
105 | * @param cfg configuration to use | ||
106 | * @param cls closure for the callbacks | ||
107 | * @param rec receive function to call | ||
108 | * @param nc function to call on connect events | ||
109 | * @param dc function to call on disconnect events | ||
110 | */ | ||
111 | struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct | ||
112 | GNUNET_SCHEDULER_Handle | ||
113 | *sched, | ||
114 | struct | ||
115 | GNUNET_CONFIGURATION_Handle | ||
116 | *cfg, void *cls, | ||
117 | GNUNET_TRANSPORT_ReceiveCallback | ||
118 | rec, | ||
119 | GNUNET_TRANSPORT_NotifyConnect | ||
120 | nc, | ||
121 | GNUNET_TRANSPORT_NotifyDisconnect | ||
122 | nd); | ||
123 | |||
124 | |||
125 | /** | ||
126 | * Disconnect from the transport service. | ||
127 | */ | ||
128 | void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle); | ||
129 | |||
130 | |||
131 | /** | ||
132 | * Set the share of incoming/outgoing bandwidth for the given | ||
133 | * peer to the specified amount. | ||
134 | * | ||
135 | * @param handle connection to transport service | ||
136 | * @param target who's bandwidth quota is being changed | ||
137 | * @param quota_in incoming bandwidth quota in bytes per ms; 0 can | ||
138 | * be used to force all traffic to be discarded | ||
139 | * @param quota_out outgoing bandwidth quota in bytes per ms; 0 can | ||
140 | * be used to force all traffic to be discarded | ||
141 | * @param timeout how long to wait until signaling failure if | ||
142 | * we can not communicate the quota change | ||
143 | * @param cont continuation to call when done, will be called | ||
144 | * either with reason "TIMEOUT" or with reason "PREREQ_DONE" | ||
145 | * @param cont_cls closure for continuation | ||
146 | */ | ||
147 | void | ||
148 | GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle, | ||
149 | const struct GNUNET_PeerIdentity *target, | ||
150 | uint32_t quota_in, | ||
151 | uint32_t quota_out, | ||
152 | struct GNUNET_TIME_Relative timeout, | ||
153 | GNUNET_SCHEDULER_Task cont, void *cont_cls); | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Opaque handle for a transmission-ready request. | ||
158 | */ | ||
159 | struct GNUNET_TRANSPORT_TransmitHandle; | ||
160 | |||
161 | |||
162 | /** | ||
163 | * Check if we could queue a message of the given size for | ||
164 | * transmission. The transport service will take both its | ||
165 | * internal buffers and bandwidth limits imposed by the | ||
166 | * other peer into consideration when answering this query. | ||
167 | * | ||
168 | * @param handle connection to transport service | ||
169 | * @param target who should receive the message | ||
170 | * @param size how big is the message we want to transmit? | ||
171 | * @param timeout after how long should we give up (and call | ||
172 | * notify with buf NULL and size 0)? | ||
173 | * @param notify function to call when we are ready to | ||
174 | * send such a message | ||
175 | * @param notify_cls closure for notify | ||
176 | * @return NULL if someone else is already waiting to be notified | ||
177 | * non-NULL if the notify callback was queued (can be used to cancel | ||
178 | * using GNUNET_TRANSPORT_notify_transmit_ready_cancel) | ||
179 | */ | ||
180 | struct GNUNET_TRANSPORT_TransmitHandle | ||
181 | *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle | ||
182 | *handle, | ||
183 | const struct GNUNET_PeerIdentity | ||
184 | *target, size_t size, | ||
185 | struct GNUNET_TIME_Relative | ||
186 | timeout, | ||
187 | GNUNET_NETWORK_TransmitReadyNotify | ||
188 | notify, void *notify_cls); | ||
189 | |||
190 | |||
191 | /** | ||
192 | * Cancel the specified transmission-ready | ||
193 | * notification. | ||
194 | */ | ||
195 | void | ||
196 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct | ||
197 | GNUNET_TRANSPORT_TransmitHandle | ||
198 | *h); | ||
199 | |||
200 | |||
201 | /** | ||
202 | * Obtain the HELLO message for this peer. | ||
203 | * | ||
204 | * @param handle connection to transport service | ||
205 | * @param timeout how long to wait for the HELLO | ||
206 | * @param rec function to call with the HELLO, sender will be our peer | ||
207 | * identity; message and sender will be NULL on timeout | ||
208 | * (handshake with transport service pending/failed). | ||
209 | * cost estimate will be 0. | ||
210 | * @param rec_cls closure for rec | ||
211 | */ | ||
212 | void | ||
213 | GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, | ||
214 | struct GNUNET_TIME_Relative timeout, | ||
215 | GNUNET_TRANSPORT_ReceiveCallback rec, | ||
216 | void *rec_cls); | ||
217 | |||
218 | |||
219 | /** | ||
220 | * Offer the transport service the HELLO of another peer. Note that | ||
221 | * the transport service may just ignore this message if the HELLO is | ||
222 | * malformed or useless due to our local configuration. | ||
223 | * | ||
224 | * @param handle connection to transport service | ||
225 | * @param hello the hello message | ||
226 | */ | ||
227 | void | ||
228 | GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | ||
229 | const struct GNUNET_MessageHeader *hello); | ||
230 | |||
231 | |||
232 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
233 | { | ||
234 | #endif | ||
235 | #ifdef __cplusplus | ||
236 | } | ||
237 | #endif | ||
238 | |||
239 | /* ifndef GNUNET_TRANSPORT_SERVICE_H */ | ||
240 | #endif | ||
241 | /* end of gnunet_transport_service.h */ | ||
diff --git a/src/include/gnunet_upnp_service.h b/src/include/gnunet_upnp_service.h new file mode 100644 index 000000000..758d5c598 --- /dev/null +++ b/src/include/gnunet_upnp_service.h | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2006 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 2, 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 include/gnunet_upnp_service.h | ||
23 | * @brief API for UPnP access | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_UPNP_SERVICE_H | ||
28 | #define GNUNET_UPNP_SERVICE_H | ||
29 | |||
30 | #include "gnunet_resolver_service.h" | ||
31 | |||
32 | #ifdef __cplusplus | ||
33 | extern "C" | ||
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Get the external IP address for the local machine and | ||
43 | * install a port mapping if possible. The external port | ||
44 | * will be returned as part of the address. | ||
45 | * | ||
46 | * @param sched scheduler to use | ||
47 | * @param cfg configuration to use | ||
48 | * @param domain communication domain (i.e. PF_INET or PF_INET6) | ||
49 | * @param type communication semantics (SOCK_STREAM, SOCK_DGRAM) | ||
50 | * @param protocol protocol to use, 0 for default (see protocols(5)) | ||
51 | * @param port port to map | ||
52 | * @param timeout after how long should we give up (and call | ||
53 | * notify with buf NULL and size 0)? | ||
54 | * @param callback function to call with the external address; | ||
55 | * function will be called with NULL on error | ||
56 | * @param cls closure for callback | ||
57 | */ | ||
58 | int GNUNET_UPNP_get_ip (struct GNUNET_SCHEDULER_Handle *sched, | ||
59 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
60 | int domain, | ||
61 | int type, | ||
62 | int protocol, | ||
63 | uint16_t port, | ||
64 | struct GNUNET_TIME_Relative timeout, | ||
65 | GNUNET_RESOLVER_AddressCallback callback, void *cls); | ||
66 | |||
67 | |||
68 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
69 | { | ||
70 | #endif | ||
71 | #ifdef __cplusplus | ||
72 | } | ||
73 | #endif | ||
74 | |||
75 | #endif | ||
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h new file mode 100644 index 000000000..c152377c3 --- /dev/null +++ b/src/include/gnunet_util_lib.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 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 2, 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 include/gnunet_util_lib.h | ||
23 | * @brief convenience header including all headers of subsystems in | ||
24 | * gnunet_util library | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #ifndef GNUNET_UTIL_LIB_H | ||
29 | #define GNUNET_UTIL_LIB_H | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" | ||
33 | { | ||
34 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
35 | } | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | #include "gnunet_common.h" | ||
40 | #include "gnunet_client_lib.h" | ||
41 | #include "gnunet_configuration_lib.h" | ||
42 | #include "gnunet_container_lib.h" | ||
43 | #include "gnunet_crypto_lib.h" | ||
44 | #include "gnunet_disk_lib.h" | ||
45 | #include "gnunet_getopt_lib.h" | ||
46 | #include "gnunet_network_lib.h" | ||
47 | #include "gnunet_program_lib.h" | ||
48 | #include "gnunet_protocols.h" | ||
49 | #include "gnunet_pseudonym_lib.h" | ||
50 | #include "gnunet_scheduler_lib.h" | ||
51 | #include "gnunet_server_lib.h" | ||
52 | #include "gnunet_service_lib.h" | ||
53 | #include "gnunet_signal_lib.h" | ||
54 | #include "gnunet_strings_lib.h" | ||
55 | #include "gnunet_time_lib.h" | ||
56 | |||
57 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
58 | { | ||
59 | #endif | ||
60 | #ifdef __cplusplus | ||
61 | } | ||
62 | #endif | ||
63 | |||
64 | #endif | ||
diff --git a/src/include/platform.h b/src/include/platform.h new file mode 100644 index 000000000..07fbe0ee7 --- /dev/null +++ b/src/include/platform.h | |||
@@ -0,0 +1,221 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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 include/platform.h | ||
23 | * @brief plaform specifics | ||
24 | * | ||
25 | * @author Nils Durner | ||
26 | * | ||
27 | * This file should never be included by installed | ||
28 | * header files (thos starting with "gnunet_"). | ||
29 | */ | ||
30 | |||
31 | #ifndef PLATFORM_H | ||
32 | #define PLATFORM_H | ||
33 | |||
34 | #ifndef HAVE_USED_CONFIG_H | ||
35 | #define HAVE_USED_CONFIG_H | ||
36 | #if HAVE_CONFIG_H | ||
37 | #include "gnunet_config.h" | ||
38 | #endif | ||
39 | #endif | ||
40 | |||
41 | #ifdef WINDOWS | ||
42 | #define BREAKPOINT asm("int $3;"); | ||
43 | #else | ||
44 | #define BREAKPOINT | ||
45 | #endif | ||
46 | |||
47 | #ifdef HAVE_SYS_TYPES_H | ||
48 | #include <sys/types.h> | ||
49 | #endif | ||
50 | |||
51 | #define ALLOW_EXTRA_CHECKS GNUNET_NO | ||
52 | |||
53 | /** | ||
54 | * For strptime (glibc2 needs this). | ||
55 | */ | ||
56 | #ifndef _XOPEN_SOURCE | ||
57 | #define _XOPEN_SOURCE | ||
58 | #endif | ||
59 | |||
60 | #ifndef _REENTRANT | ||
61 | #define _REENTRANT | ||
62 | #endif | ||
63 | |||
64 | /* configuration options */ | ||
65 | |||
66 | #define VERBOSE_STATS 0 | ||
67 | |||
68 | #ifdef CYGWIN | ||
69 | #include <sys/reent.h> | ||
70 | #define _REENT_ONLY | ||
71 | #endif | ||
72 | |||
73 | #ifdef CYGWIN | ||
74 | #undef _REENT_ONLY | ||
75 | #endif | ||
76 | |||
77 | #ifdef _MSC_VER | ||
78 | #include <Winsock2.h> | ||
79 | #else | ||
80 | #ifndef MINGW | ||
81 | #include <netdb.h> | ||
82 | #include <sys/socket.h> | ||
83 | #include <netinet/in.h> | ||
84 | #include <arpa/inet.h> | ||
85 | #include <netinet/tcp.h> | ||
86 | #include <pwd.h> | ||
87 | #include <sys/ioctl.h> | ||
88 | #include <sys/wait.h> | ||
89 | #include <grp.h> | ||
90 | #else | ||
91 | #include "winproc.h" | ||
92 | #endif | ||
93 | #endif | ||
94 | |||
95 | #include <string.h> | ||
96 | #include <stdio.h> | ||
97 | #include <stdlib.h> | ||
98 | #include <stdarg.h> | ||
99 | #include <errno.h> | ||
100 | #include <signal.h> | ||
101 | #ifndef _MSC_VER | ||
102 | #include <unistd.h> /* KLB_FIX */ | ||
103 | #endif | ||
104 | #include <sys/stat.h> | ||
105 | #include <sys/types.h> | ||
106 | #ifndef _MSC_VER | ||
107 | #include <dirent.h> /* KLB_FIX */ | ||
108 | #endif | ||
109 | #include <fcntl.h> | ||
110 | #include <math.h> | ||
111 | #if HAVE_SYS_PARAM_H | ||
112 | #include <sys/param.h> | ||
113 | #endif | ||
114 | #if TIME_WITH_SYS_TIME | ||
115 | #include <sys/time.h> | ||
116 | #include <time.h> | ||
117 | #else | ||
118 | #if HAVE_SYS_TIME_H | ||
119 | #include <sys/time.h> | ||
120 | #else | ||
121 | #include <time.h> | ||
122 | #endif | ||
123 | #endif | ||
124 | |||
125 | #ifdef SOMEBSD | ||
126 | #include <net/if.h> | ||
127 | #endif | ||
128 | #ifdef GNUNET_freeBSD | ||
129 | #include <semaphore.h> | ||
130 | #endif | ||
131 | #ifdef OSX | ||
132 | #include <dlfcn.h> | ||
133 | #include <semaphore.h> | ||
134 | #include <net/if.h> | ||
135 | #endif | ||
136 | #ifdef LINUX | ||
137 | #include <net/if.h> | ||
138 | #endif | ||
139 | #ifdef SOLARIS | ||
140 | #include <sys/sockio.h> | ||
141 | #include <sys/loadavg.h> | ||
142 | #include <semaphore.h> | ||
143 | #endif | ||
144 | #ifdef CYGWIN | ||
145 | #include <windows.h> | ||
146 | #include <cygwin/if.h> | ||
147 | #endif | ||
148 | #if HAVE_IFADDRS_H | ||
149 | #include <ifaddrs.h> | ||
150 | #endif | ||
151 | #include <errno.h> | ||
152 | #include <limits.h> | ||
153 | |||
154 | #if HAVE_CTYPE_H | ||
155 | #include <ctype.h> | ||
156 | #endif | ||
157 | #if HAVE_SYS_RESOURCE_H | ||
158 | #include <sys/resource.h> | ||
159 | #endif | ||
160 | |||
161 | #include "plibc.h" | ||
162 | |||
163 | #include <pthread.h> | ||
164 | #include <locale.h> | ||
165 | #ifndef FRAMEWORK_BUILD | ||
166 | #include "gettext.h" | ||
167 | /** | ||
168 | * GNU gettext support macro. | ||
169 | */ | ||
170 | #define _(String) dgettext("gnunet",String) | ||
171 | #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor" | ||
172 | #else | ||
173 | #include "libintlemu.h" | ||
174 | #define _(String) dgettext("org.gnunet.gnunet",String) | ||
175 | #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor" | ||
176 | #endif | ||
177 | |||
178 | #ifdef CYGWIN | ||
179 | #define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */ | ||
180 | #define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */ | ||
181 | #define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */ | ||
182 | #endif | ||
183 | |||
184 | #ifndef MINGW | ||
185 | #include <sys/mman.h> | ||
186 | #endif | ||
187 | |||
188 | #ifdef FREEBSD | ||
189 | #define __BYTE_ORDER BYTE_ORDER | ||
190 | #define __BIG_ENDIAN BIG_ENDIAN | ||
191 | #endif | ||
192 | |||
193 | #ifdef OSX | ||
194 | #define socklen_t unsigned int | ||
195 | #define __BYTE_ORDER BYTE_ORDER | ||
196 | #define __BIG_ENDIAN BIG_ENDIAN | ||
197 | /* not available on OS X, override configure */ | ||
198 | #undef HAVE_STAT64 | ||
199 | #undef HAVE_MREMAP | ||
200 | #endif | ||
201 | |||
202 | |||
203 | #if !HAVE_ATOLL | ||
204 | long long atoll (const char *nptr); | ||
205 | #endif | ||
206 | |||
207 | #if ENABLE_NLS | ||
208 | #include "langinfo.h" | ||
209 | #endif | ||
210 | |||
211 | #ifndef O_LARGEFILE | ||
212 | #define O_LARGEFILE 0 | ||
213 | #endif | ||
214 | |||
215 | #if defined(__sparc__) | ||
216 | #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; }) | ||
217 | #else | ||
218 | #define MAKE_UNALIGNED(val) val | ||
219 | #endif | ||
220 | |||
221 | #endif | ||
diff --git a/src/include/plibc.h b/src/include/plibc.h new file mode 100644 index 000000000..93ca012e1 --- /dev/null +++ b/src/include/plibc.h | |||
@@ -0,0 +1,582 @@ | |||
1 | /* | ||
2 | This file is part of PlibC. | ||
3 | (C) 2005, 2006, 2007, 2008 Nils Durner (and other contributing authors) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file include/plibc.h | ||
22 | * @brief PlibC header | ||
23 | * @attention This file is usually not installed under Unix, | ||
24 | * so ship it with your application | ||
25 | * @version $Revision: 1.46 $ | ||
26 | */ | ||
27 | |||
28 | #ifndef _PLIBC_H_ | ||
29 | #define _PLIBC_H_ | ||
30 | |||
31 | #ifndef SIGALRM | ||
32 | #define SIGALRM 14 | ||
33 | #endif /* */ | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" | ||
37 | { | ||
38 | |||
39 | #endif /* */ | ||
40 | |||
41 | #ifdef Q_OS_WIN32 | ||
42 | #define WINDOWS 1 | ||
43 | #endif /* */ | ||
44 | |||
45 | #define HAVE_PLIBC_FD 0 | ||
46 | |||
47 | #ifdef WINDOWS | ||
48 | |||
49 | #if ENABLE_NLS | ||
50 | #include "langinfo.h" | ||
51 | #endif /* */ | ||
52 | |||
53 | #include <windows.h> | ||
54 | #include <Ws2tcpip.h> | ||
55 | #include <time.h> | ||
56 | #include <stdio.h> | ||
57 | #include <sys/types.h> | ||
58 | #include <sys/stat.h> | ||
59 | #include <dirent.h> | ||
60 | #include <errno.h> | ||
61 | #include <stdarg.h> | ||
62 | |||
63 | #define __BYTE_ORDER BYTE_ORDER | ||
64 | #define __BIG_ENDIAN BIG_ENDIAN | ||
65 | |||
66 | /* Conflicts with our definitions */ | ||
67 | #define __G_WIN32_H__ | ||
68 | |||
69 | /* Convert LARGE_INTEGER to double */ | ||
70 | #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ | ||
71 | (double) ((x).LowPart)) | ||
72 | #define socklen_t int | ||
73 | #define ssize_t int | ||
74 | #define off_t int | ||
75 | #define int64_t long long | ||
76 | #define int32_t long | ||
77 | struct stat64 | ||
78 | { | ||
79 | _dev_t st_dev; | ||
80 | _ino_t st_ino; | ||
81 | _mode_t st_mode; | ||
82 | short st_nlink; | ||
83 | short st_uid; | ||
84 | short st_gid; | ||
85 | _dev_t st_rdev; | ||
86 | __int64 st_size; | ||
87 | __time64_t st_atime; | ||
88 | __time64_t st_mtime; | ||
89 | __time64_t st_ctime; | ||
90 | }; | ||
91 | |||
92 | #ifndef pid_t | ||
93 | #define pid_t int | ||
94 | #endif /* */ | ||
95 | |||
96 | #ifndef WEXITSTATUS | ||
97 | #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) | ||
98 | #endif /* */ | ||
99 | |||
100 | /* Thanks to the Cygwin project */ | ||
101 | #define ENOCSI 43 /* No CSI structure available */ | ||
102 | #define EL2HLT 44 /* Level 2 halted */ | ||
103 | #ifndef EDEADLK | ||
104 | #define EDEADLK 45 /* Deadlock condition */ | ||
105 | #endif /* */ | ||
106 | #ifndef ENOLCK | ||
107 | #define ENOLCK 46 /* No record locks available */ | ||
108 | #endif /* */ | ||
109 | #define EBADE 50 /* Invalid exchange */ | ||
110 | #define EBADR 51 /* Invalid request descriptor */ | ||
111 | #define EXFULL 52 /* Exchange full */ | ||
112 | #define ENOANO 53 /* No anode */ | ||
113 | #define EBADRQC 54 /* Invalid request code */ | ||
114 | #define EBADSLT 55 /* Invalid slot */ | ||
115 | #ifndef EDEADLOCK | ||
116 | #define EDEADLOCK EDEADLK /* File locking deadlock error */ | ||
117 | #endif /* */ | ||
118 | #define EBFONT 57 /* Bad font file fmt */ | ||
119 | #define ENOSTR 60 /* Device not a stream */ | ||
120 | #define ENODATA 61 /* No data (for no delay io) */ | ||
121 | #define ETIME 62 /* Timer expired */ | ||
122 | #define ENOSR 63 /* Out of streams resources */ | ||
123 | #define ENONET 64 /* Machine is not on the network */ | ||
124 | #define ENOPKG 65 /* Package not installed */ | ||
125 | #define EREMOTE 66 /* The object is remote */ | ||
126 | #define ENOLINK 67 /* The link has been severed */ | ||
127 | #define EADV 68 /* Advertise error */ | ||
128 | #define ESRMNT 69 /* Srmount error */ | ||
129 | #define ECOMM 70 /* Communication error on send */ | ||
130 | #define EPROTO 71 /* Protocol error */ | ||
131 | #define EMULTIHOP 74 /* Multihop attempted */ | ||
132 | #define ELBIN 75 /* Inode is remote (not really error) */ | ||
133 | #define EDOTDOT 76 /* Cross mount point (not really error) */ | ||
134 | #define EBADMSG 77 /* Trying to read unreadable message */ | ||
135 | #define ENOTUNIQ 80 /* Given log. name not unique */ | ||
136 | #define EBADFD 81 /* f.d. invalid for this operation */ | ||
137 | #define EREMCHG 82 /* Remote address changed */ | ||
138 | #define ELIBACC 83 /* Can't access a needed shared lib */ | ||
139 | #define ELIBBAD 84 /* Accessing a corrupted shared lib */ | ||
140 | #define ELIBSCN 85 /* .lib section in a.out corrupted */ | ||
141 | #define ELIBMAX 86 /* Attempting to link in too many libs */ | ||
142 | #define ELIBEXEC 87 /* Attempting to exec a shared library */ | ||
143 | #ifndef ENOSYS | ||
144 | #define ENOSYS 88 /* Function not implemented */ | ||
145 | #endif /* */ | ||
146 | #define ENMFILE 89 /* No more files */ | ||
147 | #ifndef ENOTEMPTY | ||
148 | #define ENOTEMPTY 90 /* Directory not empty */ | ||
149 | #endif /* */ | ||
150 | #ifndef ENAMETOOLONG | ||
151 | #define ENAMETOOLONG 91 /* File or path name too long */ | ||
152 | #endif /* */ | ||
153 | #define ELOOP 92 /* Too many symbolic links */ | ||
154 | #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ | ||
155 | #define EPFNOSUPPORT 96 /* Protocol family not supported */ | ||
156 | #define ECONNRESET 104 /* Connection reset by peer */ | ||
157 | #define ENOBUFS 105 /* No buffer space available */ | ||
158 | #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ | ||
159 | #define EPROTOTYPE 107 /* Protocol wrong type for socket */ | ||
160 | #define ENOTSOCK 108 /* Socket operation on non-socket */ | ||
161 | #define ENOPROTOOPT 109 /* Protocol not available */ | ||
162 | #define ESHUTDOWN 110 /* Can't send after socket shutdown */ | ||
163 | #define ECONNREFUSED 111 /* Connection refused */ | ||
164 | #define EADDRINUSE 112 /* Address already in use */ | ||
165 | #define ECONNABORTED 113 /* Connection aborted */ | ||
166 | #define ENETUNREACH 114 /* Network is unreachable */ | ||
167 | #define ENETDOWN 115 /* Network interface is not configured */ | ||
168 | #ifndef ETIMEDOUT | ||
169 | #define ETIMEDOUT 116 /* Connection timed out */ | ||
170 | #endif /* */ | ||
171 | #define EHOSTDOWN 117 /* Host is down */ | ||
172 | #define EHOSTUNREACH 118 /* Host is unreachable */ | ||
173 | #define EINPROGRESS 119 /* Connection already in progress */ | ||
174 | #define EALREADY 120 /* Socket already connected */ | ||
175 | #define EDESTADDRREQ 121 /* Destination address required */ | ||
176 | #define EMSGSIZE 122 /* Message too long */ | ||
177 | #define EPROTONOSUPPORT 123 /* Unknown protocol */ | ||
178 | #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ | ||
179 | #define EADDRNOTAVAIL 125 /* Address not available */ | ||
180 | #define ENETRESET 126 /* Connection aborted by network */ | ||
181 | #define EISCONN 127 /* Socket is already connected */ | ||
182 | #define ENOTCONN 128 /* Socket is not connected */ | ||
183 | #define ETOOMANYREFS 129 /* Too many references: cannot splice */ | ||
184 | #define EPROCLIM 130 /* Too many processes */ | ||
185 | #define EUSERS 131 /* Too many users */ | ||
186 | #define EDQUOT 132 /* Disk quota exceeded */ | ||
187 | #define ESTALE 133 /* Unknown error */ | ||
188 | #ifndef ENOTSUP | ||
189 | #define ENOTSUP 134 /* Not supported */ | ||
190 | #endif /* */ | ||
191 | #define ENOMEDIUM 135 /* No medium (in tape drive) */ | ||
192 | #define ENOSHARE 136 /* No such host or network path */ | ||
193 | #define ECASECLASH 137 /* Filename exists with different case */ | ||
194 | #define EWOULDBLOCK EAGAIN /* Operation would block */ | ||
195 | #define EOVERFLOW 139 /* Value too large for defined data type */ | ||
196 | |||
197 | #undef HOST_NOT_FOUND | ||
198 | #define HOST_NOT_FOUND 1 | ||
199 | #undef TRY_AGAIN | ||
200 | #define TRY_AGAIN 2 | ||
201 | #undef NO_RECOVERY | ||
202 | #define NO_RECOVERY 3 | ||
203 | #undef NO_ADDRESS | ||
204 | #define NO_ADDRESS 4 | ||
205 | |||
206 | #define PROT_READ 0x1 | ||
207 | #define PROT_WRITE 0x2 | ||
208 | #define MAP_SHARED 0x1 | ||
209 | #define MAP_PRIVATE 0x2 /* unsupported */ | ||
210 | #define MAP_FIXED 0x10 | ||
211 | #define MAP_FAILED ((void *)-1) | ||
212 | struct statfs | ||
213 | { | ||
214 | long f_type; /* type of filesystem (see below) */ | ||
215 | long f_bsize; /* optimal transfer block size */ | ||
216 | long f_blocks; /* total data blocks in file system */ | ||
217 | long f_bfree; /* free blocks in fs */ | ||
218 | long f_bavail; /* free blocks avail to non-superuser */ | ||
219 | long f_files; /* total file nodes in file system */ | ||
220 | long f_ffree; /* free file nodes in fs */ | ||
221 | long f_fsid; /* file system id */ | ||
222 | long f_namelen; /* maximum length of filenames */ | ||
223 | long f_spare[6]; /* spare for later */ | ||
224 | }; | ||
225 | extern const struct in6_addr in6addr_any; /* :: */ | ||
226 | extern const struct in6_addr in6addr_loopback; /* ::1 */ | ||
227 | |||
228 | /* Taken from the Wine project <http://www.winehq.org> | ||
229 | /wine/include/winternl.h */ | ||
230 | enum SYSTEM_INFORMATION_CLASS | ||
231 | { SystemBasicInformation = 0, Unknown1, SystemPerformanceInformation = 2, SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */ | ||
232 | Unknown4, SystemProcessInformation = | ||
233 | 5, Unknown6, Unknown7, SystemProcessorPerformanceInformation = | ||
234 | 8, Unknown9, Unknown10, SystemDriverInformation, Unknown12, | ||
235 | Unknown13, Unknown14, Unknown15, SystemHandleList, Unknown17, | ||
236 | Unknown18, Unknown19, Unknown20, SystemCacheInformation, | ||
237 | Unknown22, SystemInterruptInformation = | ||
238 | 23, SystemExceptionInformation = | ||
239 | 33, SystemRegistryQuotaInformation = 37, SystemLookasideInformation = 45 | ||
240 | }; | ||
241 | typedef struct | ||
242 | { | ||
243 | LARGE_INTEGER IdleTime; | ||
244 | LARGE_INTEGER KernelTime; | ||
245 | LARGE_INTEGER UserTime; | ||
246 | LARGE_INTEGER Reserved1[2]; | ||
247 | ULONG Reserved2; | ||
248 | } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; | ||
249 | |||
250 | #define sleep(secs) (Sleep(secs * 1000)) | ||
251 | |||
252 | /*********************** statfs *****************************/ | ||
253 | /* fake block size */ | ||
254 | #define FAKED_BLOCK_SIZE 512 | ||
255 | |||
256 | /* linux-compatible values for fs type */ | ||
257 | #define MSDOS_SUPER_MAGIC 0x4d44 | ||
258 | #define NTFS_SUPER_MAGIC 0x5346544E | ||
259 | |||
260 | /*********************** End of statfs ***********************/ | ||
261 | |||
262 | #define SHUT_RDWR SD_BOTH | ||
263 | |||
264 | /* Operations for flock() */ | ||
265 | #define LOCK_SH 1 /* shared lock */ | ||
266 | #define LOCK_EX 2 /* exclusive lock */ | ||
267 | #define LOCK_NB 4 /* or'd with one of the above to prevent | ||
268 | blocking */ | ||
269 | #define LOCK_UN 8 /* remove lock */ | ||
270 | |||
271 | /* Not supported under MinGW */ | ||
272 | #define S_IRGRP 0 | ||
273 | #define S_IWGRP 0 | ||
274 | #define S_IROTH 0 | ||
275 | #define S_IXGRP 0 | ||
276 | #define S_IWOTH 0 | ||
277 | #define S_IXOTH 0 | ||
278 | #define S_ISUID 0 | ||
279 | #define S_ISGID 0 | ||
280 | #define S_ISVTX 0 | ||
281 | #define S_IRWXG 0 | ||
282 | #define S_IRWXO 0 | ||
283 | |||
284 | #define SHUT_WR SD_SEND | ||
285 | #define SHUT_RD SD_RECEIVE | ||
286 | #define SHUT_RDWR SD_BOTH | ||
287 | |||
288 | #define SIGKILL 9 | ||
289 | #define SIGTERM 15 | ||
290 | |||
291 | #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__) | ||
292 | BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest); | ||
293 | BOOL _plibc_DereferenceShortcut (char *pszShortcut); | ||
294 | char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags); | ||
295 | char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags); | ||
296 | long QueryRegistry (HKEY hMainKey, char *pszKey, char *pszSubKey, | ||
297 | char *pszBuffer, long *pdLength); | ||
298 | BOOL __win_IsHandleMarkedAsBlocking (SOCKET hHandle); | ||
299 | void __win_SetHandleBlockingMode (SOCKET s, BOOL bBlocking); | ||
300 | void __win_DiscardHandleBlockingMode (SOCKET s); | ||
301 | int _win_isSocketValid (int s); | ||
302 | int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows); | ||
303 | unsigned plibc_get_handle_count (); | ||
304 | typedef void (*TPanicProc) (int, char *); | ||
305 | void plibc_set_panic_proc (TPanicProc proc); | ||
306 | int flock (int fd, int operation); | ||
307 | int fsync (int fildes); | ||
308 | int inet_pton (int af, const char *src, void *dst); | ||
309 | int inet_pton4 (const char *src, u_char * dst, int pton); | ||
310 | |||
311 | #if USE_IPV6 | ||
312 | int inet_pton6 (const char *src, u_char * dst); | ||
313 | |||
314 | #endif /* */ | ||
315 | int truncate (const char *fname, int distance); | ||
316 | int statfs (const char *path, struct statfs *buf); | ||
317 | const char *hstrerror (int err); | ||
318 | void gettimeofday (struct timeval *tp, void *tzp); | ||
319 | int mkstemp (char *tmplate); | ||
320 | char *strptime (const char *buf, const char *format, struct tm *tm); | ||
321 | char *ctime (const time_t * clock); | ||
322 | char *ctime_r (const time_t * clock, char *buf); | ||
323 | const char *inet_ntop (int af, const void *src, char *dst, size_t size); | ||
324 | int plibc_init (char *pszOrg, char *pszApp); | ||
325 | void plibc_shutdown (); | ||
326 | int plibc_initialized (); | ||
327 | int plibc_conv_to_win_path_ex (const char *pszUnix, char *pszWindows, | ||
328 | int derefLinks); | ||
329 | void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine); | ||
330 | void SetErrnoFromWinsockError (long lWinError); | ||
331 | void SetHErrnoFromWinError (long lWinError); | ||
332 | void SetErrnoFromHRESULT (HRESULT hRes); | ||
333 | FILE *_win_fopen (const char *filename, const char *mode); | ||
334 | DIR *_win_opendir (const char *dirname); | ||
335 | int _win_open (const char *filename, int oflag, ...); | ||
336 | |||
337 | #ifdef ENABLE_NLS | ||
338 | char *_win_bindtextdomain (const char *domainname, const char *dirname); | ||
339 | |||
340 | #endif /* */ | ||
341 | int _win_chdir (const char *path); | ||
342 | int _win_close (int fd); | ||
343 | int _win_creat (const char *path, mode_t mode); | ||
344 | int _win_fstat (int handle, struct stat *buffer); | ||
345 | int _win_ftruncate (int fildes, off_t length); | ||
346 | int _win_kill (pid_t pid, int sig); | ||
347 | int _win_pipe (int *phandles); | ||
348 | int _win_rmdir (const char *path); | ||
349 | int _win_access (const char *path, int mode); | ||
350 | int _win_chmod (const char *filename, int pmode); | ||
351 | char *realpath (const char *file_name, char *resolved_name); | ||
352 | long _win_random (void); | ||
353 | int _win_remove (const char *path); | ||
354 | int _win_rename (const char *oldname, const char *newname); | ||
355 | int _win_stat (const char *path, struct stat *buffer); | ||
356 | int _win_stat64 (const char *path, struct stat64 *buffer); | ||
357 | int _win_unlink (const char *filename); | ||
358 | int _win_write (int fildes, const void *buf, size_t nbyte); | ||
359 | int _win_read (int fildes, void *buf, size_t nbyte); | ||
360 | size_t _win_fwrite (const void *buffer, size_t size, size_t count, | ||
361 | FILE * stream); | ||
362 | size_t _win_fread (void *buffer, size_t size, size_t count, FILE * stream); | ||
363 | int _win_symlink (const char *path1, const char *path2); | ||
364 | void *_win_mmap (void *start, size_t len, int access, int flags, int fd, | ||
365 | unsigned long long offset); | ||
366 | int _win_munmap (void *start, size_t length); | ||
367 | int _win_lstat (const char *path, struct stat *buf); | ||
368 | int _win_lstat64 (const char *path, struct stat64 *buf); | ||
369 | int _win_readlink (const char *path, char *buf, size_t bufsize); | ||
370 | int _win_accept (SOCKET s, struct sockaddr *addr, int *addrlen); | ||
371 | int _win_printf (const char *format, ...); | ||
372 | int _win_fprintf (FILE * f, const char *format, ...); | ||
373 | int _win_vprintf (const char *format, va_list ap); | ||
374 | int _win_vfprintf (FILE * stream, const char *format, va_list arg_ptr); | ||
375 | int _win_vsprintf (char *dest, const char *format, va_list arg_ptr); | ||
376 | int _win_vsnprintf (char *str, size_t size, const char *format, | ||
377 | va_list arg_ptr); | ||
378 | int _win_snprintf (char *str, size_t size, const char *format, ...); | ||
379 | int _win_sprintf (char *dest, const char *format, ...); | ||
380 | int _win_vsscanf (const char *str, const char *format, va_list arg_ptr); | ||
381 | int _win_sscanf (const char *str, const char *format, ...); | ||
382 | int _win_vfscanf (FILE * stream, const char *format, va_list arg_ptr); | ||
383 | int _win_vscanf (const char *format, va_list arg_ptr); | ||
384 | int _win_scanf (const char *format, ...); | ||
385 | int _win_fscanf (FILE * stream, const char *format, ...); | ||
386 | pid_t _win_waitpid (pid_t pid, int *stat_loc, int options); | ||
387 | int _win_bind (SOCKET s, const struct sockaddr *name, int namelen); | ||
388 | int _win_connect (SOCKET s, const struct sockaddr *name, int namelen); | ||
389 | int _win_getpeername (SOCKET s, struct sockaddr *name, int *namelen); | ||
390 | int _win_getsockname (SOCKET s, struct sockaddr *name, int *namelen); | ||
391 | int _win_getsockopt (SOCKET s, int level, int optname, char *optval, | ||
392 | int *optlen); | ||
393 | int _win_listen (SOCKET s, int backlog); | ||
394 | int _win_recv (SOCKET s, char *buf, int len, int flags); | ||
395 | int _win_recvfrom (SOCKET s, void *buf, int len, int flags, | ||
396 | struct sockaddr *from, int *fromlen); | ||
397 | int _win_select (int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, | ||
398 | const struct timeval *tv); | ||
399 | int _win_send (SOCKET s, const char *buf, int len, int flags); | ||
400 | int _win_sendto (SOCKET s, const char *buf, int len, int flags, | ||
401 | const struct sockaddr *to, int tolen); | ||
402 | int _win_setsockopt (SOCKET s, int level, int optname, const void *optval, | ||
403 | int optlen); | ||
404 | int _win_shutdown (SOCKET s, int how); | ||
405 | SOCKET _win_socket (int af, int type, int protocol); | ||
406 | struct hostent *_win_gethostbyaddr (const char *addr, int len, int type); | ||
407 | struct hostent *_win_gethostbyname (const char *name); | ||
408 | struct hostent *gethostbyname2 (const char *name, int af); | ||
409 | char *_win_strerror (int errnum); | ||
410 | int IsWinNT (); | ||
411 | char *index (const char *s, int c); | ||
412 | |||
413 | #if !HAVE_STRNDUP | ||
414 | char *strndup (const char *s, size_t n); | ||
415 | |||
416 | #endif /* */ | ||
417 | #if !HAVE_STRNLEN | ||
418 | size_t strnlen (const char *str, size_t maxlen); | ||
419 | |||
420 | #endif /* */ | ||
421 | |||
422 | #define strcasecmp(a, b) stricmp(a, b) | ||
423 | #define strncasecmp(a, b, c) strnicmp(a, b, c) | ||
424 | |||
425 | #endif /* WINDOWS */ | ||
426 | |||
427 | #ifndef WINDOWS | ||
428 | #define DIR_SEPARATOR '/' | ||
429 | #define DIR_SEPARATOR_STR "/" | ||
430 | #define PATH_SEPARATOR ';' | ||
431 | #define PATH_SEPARATOR_STR ";" | ||
432 | #define NEWLINE "\n" | ||
433 | |||
434 | #ifdef ENABLE_NLS | ||
435 | #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) | ||
436 | #endif /* */ | ||
437 | #define CREAT(p, m) creat(p, m) | ||
438 | #undef FOPEN | ||
439 | #define FOPEN(f, m) fopen(f, m) | ||
440 | #define FTRUNCATE(f, l) ftruncate(f, l) | ||
441 | #define OPENDIR(d) opendir(d) | ||
442 | #define OPEN open | ||
443 | #define CHDIR(d) chdir(d) | ||
444 | #define CLOSE(f) close(f) | ||
445 | #define LSEEK(f, o, w) lseek(f, o, w) | ||
446 | #define RMDIR(f) rmdir(f) | ||
447 | #define ACCESS(p, m) access(p, m) | ||
448 | #define CHMOD(f, p) chmod(f, p) | ||
449 | #define FSTAT(h, b) fstat(h, b) | ||
450 | #define PLIBC_KILL(p, s) kill(p, s) | ||
451 | #define PIPE(h) pipe(h) | ||
452 | #define REMOVE(p) remove(p) | ||
453 | #define RENAME(o, n) rename(o, n) | ||
454 | #define STAT(p, b) stat(p, b) | ||
455 | #define STAT64(p, b) stat64(p, b) | ||
456 | #define UNLINK(f) unlink(f) | ||
457 | #define WRITE(f, b, n) write(f, b, n) | ||
458 | #define READ(f, b, n) read(f, b, n) | ||
459 | #define GN_FREAD(b, s, c, f) fread(b, s, c, f) | ||
460 | #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) | ||
461 | #define SYMLINK(a, b) symlink(a, b) | ||
462 | #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) | ||
463 | #define MUNMAP(s, l) munmap(s, l) | ||
464 | #define STRERROR(i) strerror(i) | ||
465 | #define RANDOM() random() | ||
466 | #define READLINK(p, b, s) readlink(p, b, s) | ||
467 | #define LSTAT(p, b) lstat(p, b) | ||
468 | #define LSTAT64(p, b) lstat64(p, b) | ||
469 | #define PRINTF printf | ||
470 | #define FPRINTF fprintf | ||
471 | #define VPRINTF(f, a) vprintf(f, a) | ||
472 | #define VFPRINTF(s, f, a) vfprintf(s, f, a) | ||
473 | #define VSPRINTF(d, f, a) vsprintf(d, f, a) | ||
474 | #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) | ||
475 | #define _REAL_SNPRINTF snprintf | ||
476 | #define SPRINTF sprintf | ||
477 | #define VSSCANF(s, f, a) vsscanf(s, f, a) | ||
478 | #define SSCANF sscanf | ||
479 | #define VFSCANF(s, f, a) vfscanf(s, f, a) | ||
480 | #define VSCANF(f, a) vscanf(f, a) | ||
481 | #define SCANF scanf | ||
482 | #define FSCANF fscanf | ||
483 | #define WAITPID(p, s, o) waitpid(p, s, o) | ||
484 | #define ACCEPT(s, a, l) accept(s, a, l) | ||
485 | #define BIND(s, n, l) bind(s, n, l) | ||
486 | #define CONNECT(s, n, l) connect(s, n, l) | ||
487 | #define GETPEERNAME(s, n, l) getpeername(s, n, l) | ||
488 | #define GETSOCKNAME(s, n, l) getsockname(s, n, l) | ||
489 | #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) | ||
490 | #define LISTEN(s, b) listen(s, b) | ||
491 | #define RECV(s, b, l, f) recv(s, b, l, f) | ||
492 | #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) | ||
493 | #define SELECT(n, r, w, e, t) select(n, r, w, e, t) | ||
494 | #define SEND(s, b, l, f) send(s, b, l, f) | ||
495 | #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) | ||
496 | #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) | ||
497 | #define SHUTDOWN(s, h) shutdown(s, h) | ||
498 | #define SOCKET(a, t, p) socket(a, t, p) | ||
499 | #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t) | ||
500 | #define GETHOSTBYNAME(n) gethostbyname(n) | ||
501 | #else /* */ | ||
502 | #define DIR_SEPARATOR '\\' | ||
503 | #define DIR_SEPARATOR_STR "\\" | ||
504 | #define PATH_SEPARATOR ':' | ||
505 | #define PATH_SEPARATOR_STR ":" | ||
506 | #define NEWLINE "\r\n" | ||
507 | |||
508 | #ifdef ENABLE_NLS | ||
509 | #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) | ||
510 | #endif /* */ | ||
511 | #define CREAT(p, m) _win_creat(p, m) | ||
512 | #define FOPEN(f, m) _win_fopen(f, m) | ||
513 | #define FTRUNCATE(f, l) _win_ftruncate(f, l) | ||
514 | #define OPENDIR(d) _win_opendir(d) | ||
515 | #define OPEN _win_open | ||
516 | #define CHDIR(d) _win_chdir(d) | ||
517 | #define CLOSE(f) _win_close(f) | ||
518 | #define PLIBC_KILL(p, s) _win_kill(p, s) | ||
519 | #define LSEEK(f, o, w) _win_lseek(f, o, w) | ||
520 | #define FSTAT(h, b) _win_fstat(h, b) | ||
521 | #define RMDIR(f) _win_rmdir(f) | ||
522 | #define ACCESS(p, m) _win_access(p, m) | ||
523 | #define CHMOD(f, p) _win_chmod(f, p) | ||
524 | #define PIPE(h) _win_pipe(h) | ||
525 | #define RANDOM() _win_random() | ||
526 | #define REMOVE(p) _win_remove(p) | ||
527 | #define RENAME(o, n) _win_rename(o, n) | ||
528 | #define STAT(p, b) _win_stat(p, b) | ||
529 | #define STAT64(p, b) _win_stat64(p, b) | ||
530 | #define UNLINK(f) _win_unlink(f) | ||
531 | #define WRITE(f, b, n) _win_write(f, b, n) | ||
532 | #define READ(f, b, n) _win_read(f, b, n) | ||
533 | #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) | ||
534 | #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) | ||
535 | #define SYMLINK(a, b) _win_symlink(a, b) | ||
536 | #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) | ||
537 | #define MUNMAP(s, l) _win_munmap(s, l) | ||
538 | #define STRERROR(i) _win_strerror(i) | ||
539 | #define READLINK(p, b, s) _win_readlink(p, b, s) | ||
540 | #define LSTAT(p, b) _win_lstat(p, b) | ||
541 | #define LSTAT64(p, b) _win_lstat64(p, b) | ||
542 | #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__) | ||
543 | #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__) | ||
544 | #define VPRINTF(f, a) _win_vprintf(f, a) | ||
545 | #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a) | ||
546 | #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a) | ||
547 | #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a) | ||
548 | #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__) | ||
549 | #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__) | ||
550 | #define VSSCANF(s, f, a) _win_vsscanf(s, f, a) | ||
551 | #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__) | ||
552 | #define VFSCANF(s, f, a) _win_vfscanf(s, f, a) | ||
553 | #define VSCANF(f, a) _win_vscanf(f, a) | ||
554 | #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__) | ||
555 | #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__) | ||
556 | #define WAITPID(p, s, o) _win_waitpid(p, s, o) | ||
557 | #define ACCEPT(s, a, l) _win_accept(s, a, l) | ||
558 | #define BIND(s, n, l) _win_bind(s, n, l) | ||
559 | #define CONNECT(s, n, l) _win_connect(s, n, l) | ||
560 | #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) | ||
561 | #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) | ||
562 | #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) | ||
563 | #define LISTEN(s, b) _win_listen(s, b) | ||
564 | #define RECV(s, b, l, f) _win_recv(s, b, l, f) | ||
565 | #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) | ||
566 | #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) | ||
567 | #define SEND(s, b, l, f) _win_send(s, b, l, f) | ||
568 | #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) | ||
569 | #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) | ||
570 | #define SHUTDOWN(s, h) _win_shutdown(s, h) | ||
571 | #define SOCKET(a, t, p) _win_socket(a, t, p) | ||
572 | #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t) | ||
573 | #define GETHOSTBYNAME(n) _win_gethostbyname(n) | ||
574 | #endif /* */ | ||
575 | |||
576 | #ifdef __cplusplus | ||
577 | } | ||
578 | #endif /* */ | ||
579 | |||
580 | #endif //_PLIBC_H_ | ||
581 | |||
582 | /* end of plibc.h */ | ||
diff --git a/src/include/winproc.h b/src/include/winproc.h new file mode 100644 index 000000000..a4a173a13 --- /dev/null +++ b/src/include/winproc.h | |||
@@ -0,0 +1,216 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005 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 2, 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 util/winproc.h | ||
23 | * @brief Definitions for MS Windows | ||
24 | * @author Nils Durner | ||
25 | **/ | ||
26 | |||
27 | #ifndef _WINPROC_H | ||
28 | #define _WINPROC_H | ||
29 | |||
30 | #include <io.h> | ||
31 | #include <stdio.h> | ||
32 | #include <sys/types.h> | ||
33 | #include <sys/stat.h> | ||
34 | #include <sys/timeb.h> | ||
35 | #include <time.h> | ||
36 | #include <dirent.h> | ||
37 | #include <windows.h> | ||
38 | #include <winsock.h> | ||
39 | #include <winerror.h> | ||
40 | #include <iphlpapi.h> | ||
41 | #include <shlobj.h> | ||
42 | #include <objbase.h> | ||
43 | #include <sys/param.h> /* #define BYTE_ORDER */ | ||
44 | #include <Ntsecapi.h> | ||
45 | #include <lm.h> | ||
46 | #include <Aclapi.h> | ||
47 | #include "gnunet_util.h" | ||
48 | #include "platform.h" | ||
49 | |||
50 | #ifdef __cplusplus | ||
51 | extern "C" | ||
52 | { | ||
53 | #endif | ||
54 | |||
55 | #ifndef MAX_NAME_LENGTH | ||
56 | #define MAX_NAME_LENGTH 25 | ||
57 | #endif | ||
58 | |||
59 | typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG, | ||
60 | PULONG); | ||
61 | typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow); | ||
62 | typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable, | ||
63 | PULONG pdwSize, BOOL bOrder); | ||
64 | typedef DWORD WINAPI (*TGetIfTable) (PMIB_IFTABLE pIfTable, PULONG pdwSize, | ||
65 | BOOL bOrder); | ||
66 | typedef DWORD WINAPI (*TCreateHardLink) (LPCTSTR lpFileName, | ||
67 | LPCTSTR lpExistingFileName, | ||
68 | LPSECURITY_ATTRIBUTES | ||
69 | lpSecurityAttributes); | ||
70 | typedef SC_HANDLE WINAPI (*TOpenSCManager) (LPCTSTR lpMachineName, | ||
71 | LPCTSTR lpDatabaseName, | ||
72 | DWORD dwDesiredAccess); | ||
73 | typedef SC_HANDLE WINAPI (*TCreateService) (SC_HANDLE hSCManager, | ||
74 | LPCTSTR lpServiceName, | ||
75 | LPCTSTR lpDisplayName, | ||
76 | DWORD dwDesiredAccess, | ||
77 | DWORD dwServiceType, | ||
78 | DWORD dwStartType, | ||
79 | DWORD dwErrorControl, | ||
80 | LPCTSTR lpBinaryPathName, | ||
81 | LPCTSTR lpLoadOrderGroup, | ||
82 | LPDWORD lpdwTagId, | ||
83 | LPCTSTR lpDependencies, | ||
84 | LPCTSTR lpServiceStartName, | ||
85 | LPCTSTR lpPassword); | ||
86 | typedef BOOL WINAPI (*TCloseServiceHandle) (SC_HANDLE hSCObject); | ||
87 | typedef BOOL WINAPI (*TDeleteService) (SC_HANDLE hService); | ||
88 | typedef SERVICE_STATUS_HANDLE WINAPI (*TRegisterServiceCtrlHandler) (LPCTSTR | ||
89 | lpServiceName, | ||
90 | LPHANDLER_FUNCTION | ||
91 | lpHandlerProc); | ||
92 | typedef BOOL WINAPI (*TSetServiceStatus) (SERVICE_STATUS_HANDLE | ||
93 | hServiceStatus, | ||
94 | LPSERVICE_STATUS lpServiceStatus); | ||
95 | typedef BOOL WINAPI (*TStartServiceCtrlDispatcher) (const | ||
96 | LPSERVICE_TABLE_ENTRY | ||
97 | lpServiceTable); | ||
98 | typedef BOOL WINAPI (*TControlService) (SC_HANDLE hService, DWORD dwControl, | ||
99 | LPSERVICE_STATUS lpServiceStatus); | ||
100 | typedef SC_HANDLE WINAPI (*TOpenService) (SC_HANDLE hSCManager, | ||
101 | LPCTSTR lpServiceName, | ||
102 | DWORD dwDesiredAccess); | ||
103 | typedef DWORD WINAPI (*TGetBestInterface) (IPAddr dwDestAddr, | ||
104 | PDWORD pdwBestIfIndex); | ||
105 | typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo, | ||
106 | PULONG pOutBufLen); | ||
107 | typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE, | ||
108 | PDWORD); | ||
109 | typedef NET_API_STATUS WINAPI (*TNetUserSetInfo) (LPCWSTR servername, | ||
110 | LPCWSTR username, | ||
111 | DWORD level, LPBYTE buf, | ||
112 | LPDWORD parm_err); | ||
113 | typedef NTSTATUS NTAPI (*TLsaOpenPolicy) (PLSA_UNICODE_STRING, | ||
114 | PLSA_OBJECT_ATTRIBUTES, | ||
115 | ACCESS_MASK, PLSA_HANDLE); | ||
116 | typedef NTSTATUS NTAPI (*TLsaAddAccountRights) (LSA_HANDLE, PSID, | ||
117 | PLSA_UNICODE_STRING, ULONG); | ||
118 | typedef NTSTATUS NTAPI (*TLsaRemoveAccountRights) (LSA_HANDLE, PSID, | ||
119 | BOOLEAN, | ||
120 | PLSA_UNICODE_STRING, | ||
121 | ULONG); | ||
122 | typedef NTSTATUS NTAPI (*TLsaClose) (LSA_HANDLE); | ||
123 | typedef BOOL WINAPI (*TLookupAccountName) (LPCTSTR lpSystemName, | ||
124 | LPCTSTR lpAccountName, PSID Sid, | ||
125 | LPDWORD cbSid, | ||
126 | LPTSTR ReferencedDomainName, | ||
127 | LPDWORD cchReferencedDomainName, | ||
128 | PSID_NAME_USE peUse); | ||
129 | |||
130 | typedef BOOL WINAPI (*TGetFileSecurity) (LPCTSTR lpFileName, | ||
131 | SECURITY_INFORMATION | ||
132 | RequestedInformation, | ||
133 | PSECURITY_DESCRIPTOR | ||
134 | pSecurityDescriptor, DWORD nLength, | ||
135 | LPDWORD lpnLengthNeeded); | ||
136 | typedef BOOL WINAPI (*TInitializeSecurityDescriptor) (PSECURITY_DESCRIPTOR | ||
137 | pSecurityDescriptor, | ||
138 | DWORD dwRevision); | ||
139 | typedef BOOL WINAPI (*TGetSecurityDescriptorDacl) (PSECURITY_DESCRIPTOR | ||
140 | pSecurityDescriptor, | ||
141 | LPBOOL lpbDaclPresent, | ||
142 | PACL * pDacl, | ||
143 | LPBOOL lpbDaclDefaulted); | ||
144 | typedef BOOL WINAPI (*TGetAclInformation) (PACL pAcl, | ||
145 | LPVOID pAclInformation, | ||
146 | DWORD nAclInformationLength, | ||
147 | ACL_INFORMATION_CLASS | ||
148 | dwAclInformationClass); | ||
149 | typedef BOOL WINAPI (*TInitializeAcl) (PACL pAcl, DWORD nAclLength, | ||
150 | DWORD dwAclRevision); | ||
151 | typedef BOOL WINAPI (*TGetAce) (PACL pAcl, DWORD dwAceIndex, LPVOID * pAce); | ||
152 | typedef BOOL WINAPI (*TEqualSid) (PSID pSid1, PSID pSid2); | ||
153 | typedef BOOL WINAPI (*TAddAce) (PACL pAcl, DWORD dwAceRevision, | ||
154 | DWORD dwStartingAceIndex, LPVOID pAceList, | ||
155 | DWORD nAceListLength); | ||
156 | typedef BOOL WINAPI (*TAddAccessAllowedAce) (PACL pAcl, DWORD dwAceRevision, | ||
157 | DWORD AccessMask, PSID pSid); | ||
158 | typedef BOOL WINAPI (*TSetNamedSecurityInfo) (LPTSTR pObjectName, | ||
159 | SE_OBJECT_TYPE ObjectType, | ||
160 | SECURITY_INFORMATION | ||
161 | SecurityInfo, PSID psidOwner, | ||
162 | PSID psidGroup, PACL pDacl, | ||
163 | PACL pSacl); | ||
164 | |||
165 | extern TNtQuerySystemInformation GNNtQuerySystemInformation; | ||
166 | extern TGetIfEntry GNGetIfEntry; | ||
167 | extern TGetIpAddrTable GNGetIpAddrTable; | ||
168 | extern TGetIfTable GNGetIfTable; | ||
169 | extern TCreateHardLink GNCreateHardLink; | ||
170 | extern TOpenSCManager GNOpenSCManager; | ||
171 | extern TCreateService GNCreateService; | ||
172 | extern TCloseServiceHandle GNCloseServiceHandle; | ||
173 | extern TDeleteService GNDeleteService; | ||
174 | extern TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler; | ||
175 | extern TSetServiceStatus GNSetServiceStatus; | ||
176 | extern TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher; | ||
177 | extern TControlService GNControlService; | ||
178 | extern TOpenService GNOpenService; | ||
179 | extern TGetBestInterface GNGetBestInterface; | ||
180 | extern TGetAdaptersInfo GGetAdaptersInfo; | ||
181 | extern TNetUserAdd GNNetUserAdd; | ||
182 | extern TNetUserSetInfo GNNetUserSetInfo; | ||
183 | extern TLsaOpenPolicy GNLsaOpenPolicy; | ||
184 | extern TLsaAddAccountRights GNLsaAddAccountRights; | ||
185 | extern TLsaRemoveAccountRights GNLsaRemoveAccountRights; | ||
186 | extern TLsaClose GNLsaClose; | ||
187 | extern TLookupAccountName GNLookupAccountName; | ||
188 | extern TGetFileSecurity GNGetFileSecurity; | ||
189 | extern TInitializeSecurityDescriptor GNInitializeSecurityDescriptor; | ||
190 | extern TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl; | ||
191 | extern TGetAclInformation GNGetAclInformation; | ||
192 | extern TInitializeAcl GNInitializeAcl; | ||
193 | extern TGetAce GNGetAce; | ||
194 | extern TEqualSid GNEqualSid; | ||
195 | extern TAddAce GNAddAce; | ||
196 | extern TAddAccessAllowedAce GNAddAccessAllowedAce; | ||
197 | extern TSetNamedSecurityInfo GNSetNamedSecurityInfo; | ||
198 | |||
199 | |||
200 | BOOL CreateShortcut (const char *pszSrc, const char *pszDest); | ||
201 | BOOL DereferenceShortcut (char *pszShortcut); | ||
202 | long QueryRegistry (HKEY hMainKey, char *pszKey, char *pszSubKey, | ||
203 | char *pszBuffer, long *pdLength); | ||
204 | int ListNICs (void (*callback) (const char *, int, void *), void *cls); | ||
205 | BOOL AddPathAccessRights (char *lpszFileName, char *lpszAccountName, | ||
206 | DWORD dwAccessMask); | ||
207 | char *winErrorStr (const char *prefix, int dwErr); | ||
208 | |||
209 | void GNInitWinEnv (); | ||
210 | void GNShutdownWinEnv (); | ||
211 | |||
212 | #ifdef __cplusplus | ||
213 | } | ||
214 | #endif | ||
215 | |||
216 | #endif | ||