reduce loop counters to more practical levels
[oweals/gnunet.git] / src / fs / gnunet-service-fs_cadet.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2012, 2017 GNUnet e.V.
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file fs/gnunet-service-fs_cadet.h
23  * @brief non-anonymous file-transfer
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_FS_CADET_H
27 #define GNUNET_SERVICE_FS_CADET_H
28
29 /**
30  * Handle for a request that is going out via cadet API.
31  */
32 struct GSF_CadetRequest;
33
34
35 /**
36  * Function called with a reply from the cadet.
37  *
38  * @param cls closure
39  * @param type type of the block, ANY on error
40  * @param expiration expiration time for the block
41  * @param data_size number of bytes in @a data, 0 on error
42  * @param data reply block data, NULL on error
43  */
44 typedef void
45 (*GSF_CadetReplyProcessor)(void *cls,
46                            enum GNUNET_BLOCK_Type type,
47                            struct GNUNET_TIME_Absolute expiration,
48                            size_t data_size,
49                            const void *data);
50
51
52 /**
53  * Look for a block by directly contacting a particular peer.
54  *
55  * @param target peer that should have the block
56  * @param query hash to query for the block
57  * @param type desired type for the block
58  * @param proc function to call with result
59  * @param proc_cls closure for @a proc
60  * @return handle to cancel the operation
61  */
62 struct GSF_CadetRequest *
63 GSF_cadet_query (const struct GNUNET_PeerIdentity *target,
64                  const struct GNUNET_HashCode *query,
65                  enum GNUNET_BLOCK_Type type,
66                  GSF_CadetReplyProcessor proc,
67                  void *proc_cls);
68
69 /**
70  * Function called on each active cadets to shut them down.
71  *
72  * @param cls NULL
73  * @param key target peer, unused
74  * @param value the `struct CadetHandle` to destroy
75  * @return #GNUNET_YES (continue to iterate)
76  */
77 int
78 GSF_cadet_release_clients (void *cls,
79                            const struct GNUNET_PeerIdentity *key,
80                            void *value);
81
82
83 /**
84  * Cancel an active request; must not be called after 'proc'
85  * was calld.
86  *
87  * @param sr request to cancel
88  */
89 void
90 GSF_cadet_query_cancel (struct GSF_CadetRequest *sr);
91
92
93 /**
94  * Initialize subsystem for non-anonymous file-sharing.
95  */
96 void
97 GSF_cadet_start_server (void);
98
99
100 /**
101  * Shutdown subsystem for non-anonymous file-sharing.
102  */
103 void
104 GSF_cadet_stop_server (void);
105
106 /**
107  * Cadet channel for creating outbound channels.
108  */
109 extern struct GNUNET_CADET_Handle *cadet_handle;
110
111 /**
112  * Map from peer identities to 'struct CadetHandles' with cadet
113  * channels to those peers.
114  */
115 extern struct GNUNET_CONTAINER_MultiPeerMap *cadet_map;
116
117
118 GNUNET_NETWORK_STRUCT_BEGIN
119
120 /**
121  * Query from one peer, asking the other for CHK-data.
122  */
123 struct CadetQueryMessage
124 {
125
126   /**
127    * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY.
128    */
129   struct GNUNET_MessageHeader header;
130
131   /**
132    * Block type must be DBLOCK or IBLOCK.
133    */
134   uint32_t type GNUNET_PACKED;
135
136   /**
137    * Query hash from CHK (hash of encrypted block).
138    */
139   struct GNUNET_HashCode query;
140
141 };
142
143
144 /**
145  * Reply to a CadetQueryMessage.
146  */
147 struct CadetReplyMessage
148 {
149
150   /**
151    * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY.
152    */
153   struct GNUNET_MessageHeader header;
154
155   /**
156    * Block type must be DBLOCK or IBLOCK.
157    */
158   uint32_t type GNUNET_PACKED;
159
160   /**
161    * Expiration time for the block.
162    */
163   struct GNUNET_TIME_AbsoluteNBO expiration;
164
165   /* followed by the encrypted block */
166
167 };
168
169 GNUNET_NETWORK_STRUCT_END
170
171
172 #endif