diff options
Diffstat (limited to 'src/dht/dht_api_find_peer.c')
-rw-r--r-- | src/dht/dht_api_find_peer.c | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/src/dht/dht_api_find_peer.c b/src/dht/dht_api_find_peer.c deleted file mode 100644 index a9ecc7b59..000000000 --- a/src/dht/dht_api_find_peer.c +++ /dev/null | |||
@@ -1,150 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010 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 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., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file dht/dht_api_find_peer.c | ||
23 | * @brief library to access the DHT to find peers | ||
24 | * @author Christian Grothoff | ||
25 | * @author Nathan Evans | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_constants.h" | ||
30 | #include "gnunet_arm_service.h" | ||
31 | #include "gnunet_protocols.h" | ||
32 | #include "gnunet_util_lib.h" | ||
33 | #include "gnunet_dht_service.h" | ||
34 | #include "dht.h" | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Handle to control a find peer operation. | ||
39 | */ | ||
40 | struct GNUNET_DHT_FindPeerHandle | ||
41 | { | ||
42 | |||
43 | /** | ||
44 | * Handle to the actual route operation for the request | ||
45 | */ | ||
46 | struct GNUNET_DHT_RouteHandle *route_handle; | ||
47 | |||
48 | /** | ||
49 | * Iterator to call on data receipt | ||
50 | */ | ||
51 | GNUNET_DHT_FindPeerProcessor proc; | ||
52 | |||
53 | /** | ||
54 | * Closure for the iterator callback | ||
55 | */ | ||
56 | void *proc_cls; | ||
57 | |||
58 | }; | ||
59 | |||
60 | |||
61 | |||
62 | /** | ||
63 | * Iterator called on each result obtained from a generic route | ||
64 | * operation | ||
65 | * | ||
66 | * @param cls closure | ||
67 | * @param key key that was used | ||
68 | * @param outgoing_path NULL-terminated array of pointers | ||
69 | * to the peers on reverse path | ||
70 | * (or NULL if not recorded) | ||
71 | * @param reply response | ||
72 | */ | ||
73 | static void | ||
74 | find_peer_reply_iterator (void *cls, const GNUNET_HashCode * key, | ||
75 | const struct GNUNET_PeerIdentity *const | ||
76 | *outgoing_path, | ||
77 | const struct GNUNET_MessageHeader *reply) | ||
78 | { | ||
79 | struct GNUNET_DHT_FindPeerHandle *find_peer_handle = cls; | ||
80 | const struct GNUNET_MessageHeader *hello; | ||
81 | |||
82 | if (ntohs (reply->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT) | ||
83 | { | ||
84 | GNUNET_break (0); | ||
85 | return; | ||
86 | } | ||
87 | GNUNET_assert (ntohs (reply->size) >= sizeof (struct GNUNET_MessageHeader)); | ||
88 | hello = (const struct GNUNET_MessageHeader *) &reply[1]; | ||
89 | if (ntohs (hello->type) != GNUNET_MESSAGE_TYPE_HELLO) | ||
90 | { | ||
91 | GNUNET_break (0); | ||
92 | return; | ||
93 | } | ||
94 | find_peer_handle->proc (find_peer_handle->proc_cls, | ||
95 | (const struct GNUNET_HELLO_Message *) hello); | ||
96 | } | ||
97 | |||
98 | |||
99 | |||
100 | /** | ||
101 | * Perform an asynchronous FIND PEER operation on the DHT. | ||
102 | * | ||
103 | * @param handle handle to the DHT service | ||
104 | * @param timeout timeout for this request to be sent to the | ||
105 | * service | ||
106 | * @param options routing options for this message | ||
107 | * @param key the key to look up | ||
108 | * @param proc function to call on each result | ||
109 | * @param proc_cls closure for proc | ||
110 | * @return handle to stop the async get, NULL on error | ||
111 | */ | ||
112 | struct GNUNET_DHT_FindPeerHandle * | ||
113 | GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle, | ||
114 | struct GNUNET_TIME_Relative timeout, | ||
115 | const GNUNET_HashCode * key, | ||
116 | enum GNUNET_DHT_RouteOption options, | ||
117 | GNUNET_DHT_FindPeerProcessor proc, void *proc_cls) | ||
118 | { | ||
119 | struct GNUNET_DHT_FindPeerHandle *find_peer_handle; | ||
120 | struct GNUNET_DHT_FindPeerMessage find_peer_msg; | ||
121 | |||
122 | find_peer_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_FindPeerHandle)); | ||
123 | find_peer_handle->proc = proc; | ||
124 | find_peer_handle->proc_cls = proc_cls; | ||
125 | find_peer_msg.header.size = | ||
126 | htons (sizeof (struct GNUNET_DHT_FindPeerMessage)); | ||
127 | find_peer_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); | ||
128 | find_peer_handle->route_handle = | ||
129 | GNUNET_DHT_route_start (handle, key, 0, options, &find_peer_msg.header, | ||
130 | timeout, &find_peer_reply_iterator, | ||
131 | find_peer_handle, NULL, NULL); | ||
132 | GNUNET_break (find_peer_handle->route_handle != NULL); | ||
133 | return find_peer_handle; | ||
134 | } | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Stop async find peer. Frees associated resources. | ||
139 | * | ||
140 | * @param find_peer_handle GET operation to stop. | ||
141 | */ | ||
142 | void | ||
143 | GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle) | ||
144 | { | ||
145 | GNUNET_DHT_route_stop (find_peer_handle->route_handle); | ||
146 | GNUNET_free (find_peer_handle); | ||
147 | } | ||
148 | |||
149 | |||
150 | /* end of dht_api_find_peer.c */ | ||