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