merge
[oweals/gnunet.git] / src / core / gnunet-service-core_typemap.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2011 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file core/gnunet-service-core_typemap.h
21  * @brief management of map that specifies which message types this peer supports
22  * @author Christian Grothoff
23  */
24 #ifndef GNUNET_SERVICE_CORE_TYPEMAP_H
25 #define GNUNET_SERVICE_CORE_TYPEMAP_H
26
27 #include "gnunet_util_lib.h"
28 #include "gnunet_transport_service.h"
29
30 /**
31  * Map specifying which message types a peer supports.
32  */
33 struct GSC_TypeMap;
34
35
36 /**
37  * Add a set of types to our type map.
38  *
39  * @param types array of message types supported by this peer
40  * @param tlen number of entries in @a types
41  */
42 void
43 GSC_TYPEMAP_add (const uint16_t *types,
44                  unsigned int tlen);
45
46
47 /**
48  * Remove a set of message types from our type map.
49  *
50  * @param types array of message types no longer supported by this peer
51  * @param tlen number of entries in @a types
52  */
53 void
54 GSC_TYPEMAP_remove (const uint16_t *types,
55                     unsigned int tlen);
56
57
58 /**
59  * Compute a type map message for this peer.
60  *
61  * @return this peers current type map message.
62  */
63 struct GNUNET_MessageHeader *
64 GSC_TYPEMAP_compute_type_map_message (void);
65
66
67 /**
68  * Check if the given hash matches our current type map.
69  *
70  * @param hc hash code to check if it matches our type map
71  * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not
72  */
73 int
74 GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc);
75
76
77 /**
78  * Hash the contents of a type map.
79  *
80  * @param tm map to hash
81  * @param hc where to store the hash code
82  */
83 void
84 GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm,
85                   struct GNUNET_HashCode *hc);
86
87
88 /**
89  * Extract a type map from a
90  * #GNUNET_MESSAGE_TYPE_CORE_COMRESSED_TYPE_MAP or
91  * #GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP message.
92  *
93  * @param msg a type map message
94  * @return NULL on error
95  */
96 struct GSC_TypeMap *
97 GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg);
98
99
100 /**
101  * Test if any of the types from the types array is in the
102  * given type map.
103  *
104  * @param tmap map to test
105  * @param types array of types
106  * @param tcnt number of entries in @a types
107  * @return #GNUNET_YES if a type is in the map, #GNUNET_NO if not
108  */
109 int
110 GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
111                         const uint16_t *types,
112                         unsigned int tcnt);
113
114
115 /**
116  * Add additional types to a given typemap.
117  *
118  * @param tmap map to extend (not changed)
119  * @param types array of types to add
120  * @param tcnt number of entries in @a types
121  * @return updated type map (fresh copy)
122  */
123 struct GSC_TypeMap *
124 GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
125                     const uint16_t *types,
126                     unsigned int tcnt);
127
128
129 /**
130  * Create an empty type map.
131  *
132  * @return an empty type map
133  */
134 struct GSC_TypeMap *
135 GSC_TYPEMAP_create (void);
136
137
138 /**
139  * Free the given type map.
140  *
141  * @param tmap a type map
142  */
143 void
144 GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap);
145
146
147 /**
148  * Initialize typemap subsystem.
149  */
150 void
151 GSC_TYPEMAP_init (void);
152
153
154 /**
155  * Shutdown typemap subsystem.
156  */
157 void
158 GSC_TYPEMAP_done (void);
159
160 #endif
161 /* end of gnunet-service-core_typemap.h */