d6ce3de633f03ac0f35acf9e17c21d63136dc735
[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 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 fs/gnunet-service-fs_cadet.h
21  * @brief non-anonymous file-transfer
22  * @author Christian Grothoff
23  */
24 #ifndef GNUNET_SERVICE_FS_CADET_H
25 #define GNUNET_SERVICE_FS_CADET_H
26
27 /**
28  * Handle for a request that is going out via cadet API.
29  */
30 struct GSF_CadetRequest;
31
32
33 /**
34  * Function called with a reply from the cadet.
35  *
36  * @param cls closure
37  * @param type type of the block, ANY on error
38  * @param expiration expiration time for the block
39  * @param data_size number of bytes in @a data, 0 on error
40  * @param data reply block data, NULL on error
41  */
42 typedef void
43 (*GSF_CadetReplyProcessor)(void *cls,
44                            enum GNUNET_BLOCK_Type type,
45                            struct GNUNET_TIME_Absolute expiration,
46                            size_t data_size,
47                            const void *data);
48
49
50 /**
51  * Look for a block by directly contacting a particular peer.
52  *
53  * @param target peer that should have the block
54  * @param query hash to query for the block
55  * @param type desired type for the block
56  * @param proc function to call with result
57  * @param proc_cls closure for @a proc
58  * @return handle to cancel the operation
59  */
60 struct GSF_CadetRequest *
61 GSF_cadet_query (const struct GNUNET_PeerIdentity *target,
62                  const struct GNUNET_HashCode *query,
63                  enum GNUNET_BLOCK_Type type,
64                  GSF_CadetReplyProcessor proc,
65                  void *proc_cls);
66
67 /**
68  * Function called on each active cadets to shut them down.
69  *
70  * @param cls NULL
71  * @param key target peer, unused
72  * @param value the `struct CadetHandle` to destroy
73  * @return #GNUNET_YES (continue to iterate)
74  */
75 int
76 GSF_cadet_release_clients (void *cls,
77                            const struct GNUNET_PeerIdentity *key,
78                            void *value);
79
80
81 /**
82  * Cancel an active request; must not be called after 'proc'
83  * was calld.
84  *
85  * @param sr request to cancel
86  */
87 void
88 GSF_cadet_query_cancel (struct GSF_CadetRequest *sr);
89
90
91 /**
92  * Initialize subsystem for non-anonymous file-sharing.
93  */
94 void
95 GSF_cadet_start_server (void);
96
97
98 /**
99  * Shutdown subsystem for non-anonymous file-sharing.
100  */
101 void
102 GSF_cadet_stop_server (void);
103
104 /**
105  * Cadet channel for creating outbound channels.
106  */
107 extern struct GNUNET_CADET_Handle *cadet_handle;
108
109 /**
110  * Map from peer identities to 'struct CadetHandles' with cadet
111  * channels to those peers.
112  */
113 extern struct GNUNET_CONTAINER_MultiPeerMap *cadet_map;
114
115
116 GNUNET_NETWORK_STRUCT_BEGIN
117
118 /**
119  * Query from one peer, asking the other for CHK-data.
120  */
121 struct CadetQueryMessage
122 {
123
124   /**
125    * Type is GNUNET_MESSAGE_TYPE_FS_CADET_QUERY.
126    */
127   struct GNUNET_MessageHeader header;
128
129   /**
130    * Block type must be DBLOCK or IBLOCK.
131    */
132   uint32_t type GNUNET_PACKED;
133
134   /**
135    * Query hash from CHK (hash of encrypted block).
136    */
137   struct GNUNET_HashCode query;
138
139 };
140
141
142 /**
143  * Reply to a CadetQueryMessage.
144  */
145 struct CadetReplyMessage
146 {
147
148   /**
149    * Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY.
150    */
151   struct GNUNET_MessageHeader header;
152
153   /**
154    * Block type must be DBLOCK or IBLOCK.
155    */
156   uint32_t type GNUNET_PACKED;
157
158   /**
159    * Expiration time for the block.
160    */
161   struct GNUNET_TIME_AbsoluteNBO expiration;
162
163   /* followed by the encrypted block */
164
165 };
166
167 GNUNET_NETWORK_STRUCT_END
168
169
170 #endif