aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-03-09 19:07:13 +0000
committerChristian Grothoff <christian@grothoff.org>2011-03-09 19:07:13 +0000
commit073c4a9ae448041fdc9a0683fed49d55ae61803e (patch)
tree9bf2bacde4723ea25f70a0cdb324a1d76be763de /src
parentfafacaa77732d1dadcfcb10e4901dda76840a76d (diff)
downloadgnunet-073c4a9ae448041fdc9a0683fed49d55ae61803e.tar.gz
gnunet-073c4a9ae448041fdc9a0683fed49d55ae61803e.zip
hxing
Diffstat (limited to 'src')
-rw-r--r--src/fs/Makefile.am24
-rw-r--r--src/fs/gnunet-service-fs.h28
-rw-r--r--src/fs/gnunet-service-fs_cp.c28
-rw-r--r--src/fs/gnunet-service-fs_cp.h13
-rw-r--r--src/fs/gnunet-service-fs_indexing.h2
-rw-r--r--src/fs/gnunet-service-fs_lc.c3
-rw-r--r--src/fs/gnunet-service-fs_lc.h2
-rw-r--r--src/fs/gnunet-service-fs_new.c555
-rw-r--r--src/fs/gnunet-service-fs_pr.c24
-rw-r--r--src/fs/gnunet-service-fs_pr.h5
-rw-r--r--src/fs/gnunet-service-fs_push.c8
-rw-r--r--src/fs/gnunet-service-fs_push.h4
-rw-r--r--src/fs/gnunet-service-fs_put.c4
-rw-r--r--src/fs/gnunet-service-fs_put.h4
14 files changed, 667 insertions, 37 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 5aa3b7f2b..49d424825 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -54,6 +54,7 @@ bin_PROGRAMS = \
54 gnunet-pseudonym \ 54 gnunet-pseudonym \
55 gnunet-search \ 55 gnunet-search \
56 gnunet-service-fs \ 56 gnunet-service-fs \
57 gnunet-service-fs-new \
57 gnunet-unindex 58 gnunet-unindex
58 59
59gnunet_directory_SOURCES = \ 60gnunet_directory_SOURCES = \
@@ -105,8 +106,29 @@ gnunet_search_LDADD = \
105gnunet_search_DEPENDENCIES = \ 106gnunet_search_DEPENDENCIES = \
106 libgnunetfs.la 107 libgnunetfs.la
107 108
109gnunet_service_fs_new_SOURCES = \
110 gnunet-service-fs_new.c gnunet-service-fs.h \
111 gnunet-service-fs_cp.c gnunet-service-fs_cp.h \
112 gnunet-service-fs_indexing.c gnunet-service-fs_indexing.h \
113 gnunet-service-fs_lc.c gnunet-service-fs_lc.h \
114 gnunet-service-fs_pe.c gnunet-service-fs_pe.h \
115 gnunet-service-fs_pr.c gnunet-service-fs_pr.h \
116 gnunet-service-fs_push.c gnunet-service-fs_push.h \
117 gnunet-service-fs_put.c gnunet-service-fs_put.h
118gnunet_service_fs_new_LDADD = \
119 $(top_builddir)/src/fs/libgnunetfs.la \
120 $(top_builddir)/src/dht/libgnunetdht.la \
121 $(top_builddir)/src/block/libgnunetblock.la \
122 $(top_builddir)/src/datastore/libgnunetdatastore.la \
123 $(top_builddir)/src/statistics/libgnunetstatistics.la \
124 $(top_builddir)/src/core/libgnunetcore.la \
125 $(top_builddir)/src/util/libgnunetutil.la \
126 $(GN_LIBINTL)
127gnunet_service_fs_new_DEPENDENCIES = \
128 libgnunetfs.la
129
108gnunet_service_fs_SOURCES = \ 130gnunet_service_fs_SOURCES = \
109 gnunet-service-fs.c \ 131 gnunet-service-fs.c gnunet-service-fs.h \
110 gnunet-service-fs_indexing.c gnunet-service-fs_indexing.h 132 gnunet-service-fs_indexing.c gnunet-service-fs_indexing.h
111gnunet_service_fs_LDADD = \ 133gnunet_service_fs_LDADD = \
112 $(top_builddir)/src/fs/libgnunetfs.la \ 134 $(top_builddir)/src/fs/libgnunetfs.la \
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h
index d16b1a856..db9de3cb8 100644
--- a/src/fs/gnunet-service-fs.h
+++ b/src/fs/gnunet-service-fs.h
@@ -33,6 +33,28 @@
33#include "gnunet_block_lib.h" 33#include "gnunet_block_lib.h"
34#include "fs.h" 34#include "fs.h"
35 35
36
37/**
38 * Should we introduce random latency in processing? Required for proper
39 * implementation of GAP, but can be disabled for performance evaluation of
40 * the basic routing algorithm.
41 *
42 * Note that with delays enabled, performance can be significantly lower
43 * (several orders of magnitude in 2-peer test runs); if you want to
44 * measure throughput of other components, set this to NO. Also, you
45 * might want to consider changing 'RETRY_PROBABILITY_INV' to 1 for
46 * a rather wasteful mode of operation (that might still get the highest
47 * throughput overall).
48 *
49 * Performance measurements (for 50 MB file, 2 peers):
50 *
51 * - Without delays: 3300 kb/s
52 * - With delays: 101 kb/s
53 */
54#define SUPPORT_DELAYS GNUNET_NO
55
56
57
36/** 58/**
37 * A connected peer. 59 * A connected peer.
38 */ 60 */
@@ -98,6 +120,12 @@ extern double GSF_current_priorities;
98 */ 120 */
99extern unsigned int GSF_cover_query_count; 121extern unsigned int GSF_cover_query_count;
100 122
123/**
124 * How many content messages have we received 'recently' that
125 * have not yet been claimed as cover traffic?
126 */
127extern unsigned int GSF_cover_content_count;
128
101 129
102/** 130/**
103 * Our block context. 131 * Our block context.
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index 80ca8de9c..407c9f7fe 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -452,6 +452,19 @@ revive_migration (void *cls,
452 452
453 453
454/** 454/**
455 * Get a handle for a connected peer.
456 *
457 * @param peer peer's identity
458 */
459struct GSF_ConnectedPeer *
460GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
461{
462 return GNUNET_CONTAINER_multihashmap_get (cp_map,
463 &peer->hashPubKey);
464}
465
466
467/**
455 * Handle P2P "MIGRATION_STOP" message. 468 * Handle P2P "MIGRATION_STOP" message.
456 * 469 *
457 * @param cls closure, always NULL 470 * @param cls closure, always NULL
@@ -793,7 +806,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
793 int32_t priority; 806 int32_t priority;
794 int32_t ttl; 807 int32_t ttl;
795 enum GNUNET_BLOCK_Type type; 808 enum GNUNET_BLOCK_Type type;
796 809 GNUNET_PEER_Id spid;
797 810
798 msize = ntohs(message->size); 811 msize = ntohs(message->size);
799 if (msize < sizeof (struct GetMessage)) 812 if (msize < sizeof (struct GetMessage))
@@ -891,6 +904,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
891 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL; 904 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL;
892 target = (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity*) &opt[bits++]) : NULL; 905 target = (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity*) &opt[bits++]) : NULL;
893 options = 0; 906 options = 0;
907 spid = 0;
894 if ( (GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority)) || 908 if ( (GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority)) ||
895 (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) > 909 (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) >
896 GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 + GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)) ) 910 GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 + GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)) )
@@ -899,6 +913,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
899 so at best indirect the query */ 913 so at best indirect the query */
900 priority = 0; 914 priority = 0;
901 options |= GSF_PRO_FORWARD_ONLY; 915 options |= GSF_PRO_FORWARD_ONLY;
916 spid = GNUNET_PEER_intern (other);
902 } 917 }
903 ttl = bound_ttl (ntohl (gm->ttl), priority); 918 ttl = bound_ttl (ntohl (gm->ttl), priority);
904 /* decrement ttl (always) */ 919 /* decrement ttl (always) */
@@ -972,6 +987,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
972 1 /* anonymity */, 987 1 /* anonymity */,
973 (uint32_t) priority, 988 (uint32_t) priority,
974 ttl, 989 ttl,
990 spid,
975 NULL, 0, /* replies_seen */ 991 NULL, 0, /* replies_seen */
976 &handle_p2p_reply, 992 &handle_p2p_reply,
977 cp); 993 cp);
@@ -1290,7 +1306,9 @@ GSF_peer_disconnect_handler_ (void *cls,
1290 1306
1291 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 1307 cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
1292 &peer->hashPubKey); 1308 &peer->hashPubKey);
1293 GNUNET_assert (NULL != cp); 1309 if (NULL == cp)
1310 return; /* must have been disconnect from core with
1311 'peer' == my_id, ignore */
1294 GNUNET_CONTAINER_multihashmap_remove (cp_map, 1312 GNUNET_CONTAINER_multihashmap_remove (cp_map,
1295 &peer->hashPubKey, 1313 &peer->hashPubKey,
1296 cp); 1314 cp);
@@ -1553,15 +1571,13 @@ cron_flush_trust (void *cls,
1553 1571
1554/** 1572/**
1555 * Initialize peer management subsystem. 1573 * Initialize peer management subsystem.
1556 *
1557 * @param cfg configuration to use
1558 */ 1574 */
1559void 1575void
1560GSF_connected_peer_init_ (struct GNUNET_CONFIGURATION_Handle *cfg) 1576GSF_connected_peer_init_ ()
1561{ 1577{
1562 cp_map = GNUNET_CONTAINER_multihashmap_create (128); 1578 cp_map = GNUNET_CONTAINER_multihashmap_create (128);
1563 GNUNET_assert (GNUNET_OK == 1579 GNUNET_assert (GNUNET_OK ==
1564 GNUNET_CONFIGURATION_get_value_filename (cfg, 1580 GNUNET_CONFIGURATION_get_value_filename (GSF_cfg,
1565 "fs", 1581 "fs",
1566 "TRUST", 1582 "TRUST",
1567 &trustDirectory)); 1583 &trustDirectory));
diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h
index 95b2033db..7b8cf40ab 100644
--- a/src/fs/gnunet-service-fs_cp.h
+++ b/src/fs/gnunet-service-fs_cp.h
@@ -172,6 +172,15 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
172 172
173 173
174/** 174/**
175 * Get a handle for a connected peer.
176 *
177 * @param peer peer's identity
178 */
179struct GSF_ConnectedPeer *
180GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer);
181
182
183/**
175 * Transmit a message to the given peer as soon as possible. 184 * Transmit a message to the given peer as soon as possible.
176 * If the peer disconnects before the transmission can happen, 185 * If the peer disconnects before the transmission can happen,
177 * the callback is invoked with a 'NULL' buffer. 186 * the callback is invoked with a 'NULL' buffer.
@@ -377,11 +386,9 @@ GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
377 386
378/** 387/**
379 * Initialize peer management subsystem. 388 * Initialize peer management subsystem.
380 *
381 * @param cfg configuration to use
382 */ 389 */
383void 390void
384GSF_connected_peer_init_ (struct GNUNET_CONFIGURATION_Handle *cfg); 391GSF_connected_peer_init_ (void);
385 392
386 393
387/** 394/**
diff --git a/src/fs/gnunet-service-fs_indexing.h b/src/fs/gnunet-service-fs_indexing.h
index 885e141e2..e606f30b1 100644
--- a/src/fs/gnunet-service-fs_indexing.h
+++ b/src/fs/gnunet-service-fs_indexing.h
@@ -105,8 +105,6 @@ GNUNET_FS_handle_unindex (void *cls,
105 const struct GNUNET_MessageHeader *message); 105 const struct GNUNET_MessageHeader *message);
106 106
107 107
108
109
110/** 108/**
111 * Initialize the indexing submodule. 109 * Initialize the indexing submodule.
112 * 110 *
diff --git a/src/fs/gnunet-service-fs_lc.c b/src/fs/gnunet-service-fs_lc.c
index cb57e871f..f284ba0f8 100644
--- a/src/fs/gnunet-service-fs_lc.c
+++ b/src/fs/gnunet-service-fs_lc.c
@@ -349,6 +349,7 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
349 ntohl (sm->anonymity_level), 349 ntohl (sm->anonymity_level),
350 0 /* priority */, 350 0 /* priority */,
351 0 /* ttl */, 351 0 /* ttl */,
352 0 /* sender PID */,
352 (const GNUNET_HashCode*) &sm[1], sc, 353 (const GNUNET_HashCode*) &sm[1], sc,
353 &client_response_handler, 354 &client_response_handler,
354 cr); 355 cr);
@@ -445,7 +446,7 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
445 */ 446 */
446void 447void
447GSF_client_disconnect_handler_ (void *cls, 448GSF_client_disconnect_handler_ (void *cls,
448 const struct GNUNET_SERVER_Client *client) 449 struct GNUNET_SERVER_Client *client)
449{ 450{
450 struct GSF_LocalClient *pos; 451 struct GSF_LocalClient *pos;
451 struct ClientRequest *cr; 452 struct ClientRequest *cr;
diff --git a/src/fs/gnunet-service-fs_lc.h b/src/fs/gnunet-service-fs_lc.h
index 35d8a839a..87eb14198 100644
--- a/src/fs/gnunet-service-fs_lc.h
+++ b/src/fs/gnunet-service-fs_lc.h
@@ -76,7 +76,7 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
76 */ 76 */
77void 77void
78GSF_client_disconnect_handler_ (void *cls, 78GSF_client_disconnect_handler_ (void *cls,
79 const struct GNUNET_SERVER_Client *client); 79 struct GNUNET_SERVER_Client *client);
80 80
81 81
82#endif 82#endif
diff --git a/src/fs/gnunet-service-fs_new.c b/src/fs/gnunet-service-fs_new.c
new file mode 100644
index 000000000..f0a1513c3
--- /dev/null
+++ b/src/fs/gnunet-service-fs_new.c
@@ -0,0 +1,555 @@
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 fs/gnunet-service-fs.c
23 * @brief gnunet anonymity protocol implementation
24 * @author Christian Grothoff
25 *
26 * To use:
27 * - GSF_plan_get_ (!)
28 * - GSF_plan_size_ (?)
29 * - GSF_plan_notify_request_done (!)
30 * -
31 *
32 *
33 */
34#include "platform.h"
35#include <float.h>
36#include "gnunet_constants.h"
37#include "gnunet_core_service.h"
38#include "gnunet_dht_service.h"
39#include "gnunet_datastore_service.h"
40#include "gnunet_load_lib.h"
41#include "gnunet_peer_lib.h"
42#include "gnunet_protocols.h"
43#include "gnunet_signatures.h"
44#include "gnunet_statistics_service.h"
45#include "gnunet_transport_service.h"
46#include "gnunet_util_lib.h"
47#include "gnunet-service-fs_cp.h"
48#include "gnunet-service-fs_indexing.h"
49#include "gnunet-service-fs_lc.h"
50#include "gnunet-service-fs_pe.h"
51#include "gnunet-service-fs_pr.h"
52#include "gnunet-service-fs_push.h"
53#include "gnunet-service-fs_put.h"
54#include "fs.h"
55
56#define DEBUG_FS GNUNET_YES
57
58/**
59 * Size for the hash map for DHT requests from the FS
60 * service. Should be about the number of concurrent
61 * DHT requests we plan to make.
62 */
63#define FS_DHT_HT_SIZE 1024
64
65
66/**
67 * How quickly do we age cover traffic? At the given
68 * time interval, remaining cover traffic counters are
69 * decremented by 1/16th.
70 */
71#define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
72
73
74/* ****************************** globals ****************************** */
75
76/**
77 * Our connection to the datastore.
78 */
79struct GNUNET_DATASTORE_Handle *GSF_dsh;
80
81/**
82 * Our configuration.
83 */
84const struct GNUNET_CONFIGURATION_Handle *GSF_cfg;
85
86/**
87 * Handle for reporting statistics.
88 */
89struct GNUNET_STATISTICS_Handle *GSF_stats;
90
91/**
92 * Pointer to handle to the core service (points to NULL until we've
93 * connected to it).
94 */
95struct GNUNET_CORE_Handle *GSF_core;
96
97/**
98 * Handle for DHT operations.
99 */
100struct GNUNET_DHT_Handle *GSF_dht;
101
102/**
103 * How long do requests typically stay in the routing table?
104 */
105struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
106
107/**
108 * Typical priorities we're seeing from other peers right now. Since
109 * most priorities will be zero, this value is the weighted average of
110 * non-zero priorities seen "recently". In order to ensure that new
111 * values do not dramatically change the ratio, values are first
112 * "capped" to a reasonable range (+N of the current value) and then
113 * averaged into the existing value by a ratio of 1:N. Hence
114 * receiving the largest possible priority can still only raise our
115 * "current_priorities" by at most 1.
116 */
117double GSF_current_priorities;
118
119/**
120 * How many query messages have we received 'recently' that
121 * have not yet been claimed as cover traffic?
122 */
123unsigned int GSF_cover_query_count;
124
125/**
126 * How many content messages have we received 'recently' that
127 * have not yet been claimed as cover traffic?
128 */
129unsigned int GSF_cover_content_count;
130
131/**
132 * Our block context.
133 */
134struct GNUNET_BLOCK_Context *GSF_block_ctx;
135
136
137/* ***************************** locals ******************************* */
138
139/**
140 * Configuration for block library.
141 */
142static struct GNUNET_CONFIGURATION_Handle *block_cfg;
143
144/**
145 * ID of our task that we use to age the cover counters.
146 */
147static GNUNET_SCHEDULER_TaskIdentifier cover_age_task;
148
149/**
150 * Pointer to handle to the core service (points to NULL until we've
151 * connected to it).
152 */
153static struct GNUNET_CORE_Handle *core;
154
155/**
156 * Identity of this peer.
157 */
158static struct GNUNET_PeerIdentity my_id;
159
160/**
161 * Task that periodically ages our cover traffic statistics.
162 *
163 * @param cls unused closure
164 * @param tc task context
165 */
166static void
167age_cover_counters (void *cls,
168 const struct GNUNET_SCHEDULER_TaskContext *tc)
169{
170 GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
171 GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
172 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
173 &age_cover_counters,
174 NULL);
175}
176
177
178/**
179 * Handle P2P "PUT" message.
180 *
181 * @param cls closure, always NULL
182 * @param other the other peer involved (sender or receiver, NULL
183 * for loopback messages where we are both sender and receiver)
184 * @param message the actual message
185 * @param atsi performance information
186 * @return GNUNET_OK to keep the connection open,
187 * GNUNET_SYSERR to close it (signal serious error)
188 */
189static int
190handle_p2p_put (void *cls,
191 const struct GNUNET_PeerIdentity *other,
192 const struct GNUNET_MessageHeader *message,
193 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
194{
195 struct GSF_ConnectedPeer *cp;
196
197 cp = GSF_peer_get_ (other);
198 if (NULL == cp)
199 {
200 GNUNET_break (0);
201 return GNUNET_OK;
202 }
203 return GSF_handle_p2p_content_ (cp, message);
204}
205
206
207/**
208 * Decide with what weight we should forward the given
209 * request to the given peer.
210 *
211 * @param cp target peer
212 * @param pr request
213 */
214static void
215plan (struct GSF_ConnectedPeer *cp,
216 struct GSF_PendingRequest *pr)
217{
218 GNUNET_CONTAINER_HeapCostType weight;
219
220 weight = 0;
221 /* FIXME: calculate weight properly... */
222 GSF_plan_add_ (cp, pr, weight);
223}
224
225
226/**
227 * Handle P2P "GET" request.
228 *
229 * @param cls closure, always NULL
230 * @param other the other peer involved (sender or receiver, NULL
231 * for loopback messages where we are both sender and receiver)
232 * @param message the actual message
233 * @param atsi performance information
234 * @return GNUNET_OK to keep the connection open,
235 * GNUNET_SYSERR to close it (signal serious error)
236 */
237static int
238handle_p2p_get (void *cls,
239 const struct GNUNET_PeerIdentity *other,
240 const struct GNUNET_MessageHeader *message,
241 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
242{
243 struct GSF_PendingRequest *pr;
244
245 pr = GSF_handle_p2p_query_ (other, message);
246 if (NULL == pr)
247 return GNUNET_SYSERR;
248 /* FIXME: local lookup! */
249 /* FIXME: after local lookup, trigger forwarding/routing! */
250 return GNUNET_OK;
251}
252
253
254/**
255 * We have a new request, consider forwarding it to the given
256 * peer.
257 *
258 * @param cls the 'struct GSF_PendingRequest'
259 * @param peer identity of the peer
260 * @param cp handle to the connected peer record
261 * @param perf peer performance data
262 */
263static void
264consider_request_for_forwarding (void *cls,
265 const struct GNUNET_PeerIdentity *peer,
266 struct GSF_ConnectedPeer *cp,
267 const struct GSF_PeerPerformanceData *ppd)
268{
269 struct GSF_PendingRequest *pr = cls;
270
271 plan (cp, pr);
272}
273
274
275/**
276 * Handle START_SEARCH-message (search request from client).
277 *
278 * @param cls closure
279 * @param client identification of the client
280 * @param message the actual message
281 */
282static void
283handle_start_search (void *cls,
284 struct GNUNET_SERVER_Client *client,
285 const struct GNUNET_MessageHeader *message)
286{
287 struct GSF_PendingRequest *pr;
288
289 pr = GSF_local_client_start_search_handler_ (client, message);
290 if (NULL == pr)
291 {
292 /* 'GNUNET_SERVER_receive_done was already called! */
293 return;
294 }
295 /* FIXME: local lookup, then (after DB done!) receive_done: */
296 GNUNET_SERVER_receive_done (client,
297 GNUNET_OK);
298#if 0
299 /* FIXME: also do DHT lookup */
300 struct GNUNET_DHT_GetHandle *gh;
301 /* store 'gh' with 'pr', cancel it on pr destruction, etc. */
302 gh = GNUNET_DHT_get_start (GSF_dht,
303 timeout,
304 type,
305 key,
306 des_repl_level,
307 options,
308 bf,
309 bf_mutator,
310 xquery,
311 xquery_size,
312 &GSF_handle_dht_reply_,
313 pr);
314#endif
315 GSF_iterate_connected_peers_ (&consider_request_for_forwarding,
316 pr);
317}
318
319
320/**
321 * Task run during shutdown.
322 *
323 * @param cls unused
324 * @param tc unused
325 */
326static void
327shutdown_task (void *cls,
328 const struct GNUNET_SCHEDULER_TaskContext *tc)
329{
330 if (NULL != core)
331 {
332 GNUNET_CORE_disconnect (core);
333 core = NULL;
334 }
335 GSF_put_done_ ();
336 GSF_push_done_ ();
337 GSF_pending_request_done_ ();
338 GSF_plan_done ();
339 GSF_connected_peer_done_ ();
340 GNUNET_DATASTORE_disconnect (GSF_dsh, GNUNET_NO);
341 GSF_dsh = NULL;
342 GNUNET_DHT_disconnect (GSF_dht);
343 GSF_dht = NULL;
344 GNUNET_BLOCK_context_destroy (GSF_block_ctx);
345 GSF_block_ctx = NULL;
346 GNUNET_CONFIGURATION_destroy (block_cfg);
347 block_cfg = NULL;
348 GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO);
349 if (GNUNET_SCHEDULER_NO_TASK != cover_age_task)
350 {
351 GNUNET_SCHEDULER_cancel (cover_age_task);
352 cover_age_task = GNUNET_SCHEDULER_NO_TASK;
353 }
354}
355
356
357/**
358 * Function called for each pending request whenever a new
359 * peer connects, giving us a chance to decide about submitting
360 * the existing request to the new peer.
361 *
362 * @param cls the 'struct GSF_ConnectedPeer' of the new peer
363 * @param key query for the request
364 * @param pr handle to the pending request
365 * @return GNUNET_YES to continue to iterate
366 */
367static int
368consider_peer_for_forwarding (void *cls,
369 const GNUNET_HashCode *key,
370 struct GSF_PendingRequest *pr)
371{
372 struct GSF_ConnectedPeer *cp = cls;
373
374 plan (cp, pr);
375 return GNUNET_YES;
376}
377
378
379/**
380 * Method called whenever a given peer connects.
381 *
382 * @param cls closure, not used
383 * @param peer peer identity this notification is about
384 * @param atsi performance information
385 */
386static void
387peer_connect_handler (void *cls,
388 const struct GNUNET_PeerIdentity *peer,
389 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
390{
391 struct GSF_ConnectedPeer *cp;
392
393 if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
394 return;
395 cp = GSF_peer_connect_handler_ (peer, atsi);
396 if (NULL == cp)
397 return;
398 GSF_iterate_pending_requests_ (&consider_peer_for_forwarding,
399 cp);
400}
401
402
403/**
404 * Function called after GNUNET_CORE_connect has succeeded
405 * (or failed for good). Note that the private key of the
406 * peer is intentionally not exposed here; if you need it,
407 * your process should try to read the private key file
408 * directly (which should work if you are authorized...).
409 *
410 * @param cls closure
411 * @param server handle to the server, NULL if we failed
412 * @param my_identity ID of this peer, NULL if we failed
413 * @param publicKey public key of this peer, NULL if we failed
414 */
415static void
416peer_init_handler (void *cls,
417 struct GNUNET_CORE_Handle * server,
418 const struct GNUNET_PeerIdentity *
419 my_identity,
420 const struct
421 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
422 publicKey)
423{
424 my_id = *my_identity;
425}
426
427
428/**
429 * Process fs requests.
430 *
431 * @param server the initialized server
432 * @param c configuration to use
433 */
434static int
435main_init (struct GNUNET_SERVER_Handle *server,
436 const struct GNUNET_CONFIGURATION_Handle *c)
437{
438 static const struct GNUNET_CORE_MessageHandler p2p_handlers[] =
439 {
440 { &handle_p2p_get,
441 GNUNET_MESSAGE_TYPE_FS_GET, 0 },
442 { &handle_p2p_put,
443 GNUNET_MESSAGE_TYPE_FS_PUT, 0 },
444 { &GSF_handle_p2p_migration_stop_,
445 GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
446 sizeof (struct MigrationStopMessage) },
447 { NULL, 0, 0 }
448 };
449 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
450 {&GNUNET_FS_handle_index_start, NULL,
451 GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
452 {&GNUNET_FS_handle_index_list_get, NULL,
453 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct GNUNET_MessageHeader) },
454 {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
455 sizeof (struct UnindexMessage) },
456 {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
457 0 },
458 {NULL, NULL, 0, 0}
459 };
460
461 core = GNUNET_CORE_connect (GSF_cfg,
462 1, /* larger? */
463 NULL,
464 &peer_init_handler,
465 &peer_connect_handler,
466 &GSF_peer_disconnect_handler_,
467 &GSF_peer_status_handler_,
468 NULL, GNUNET_NO,
469 NULL, GNUNET_NO,
470 p2p_handlers);
471 if (NULL == core)
472 {
473 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
474 _("Failed to connect to `%s' service.\n"),
475 "core");
476 return GNUNET_SYSERR;
477 }
478 GNUNET_SERVER_disconnect_notify (server,
479 &GSF_client_disconnect_handler_,
480 NULL);
481 GNUNET_SERVER_add_handlers (server, handlers);
482 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
483 &age_cover_counters,
484 NULL);
485 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
486 &shutdown_task,
487 NULL);
488 return GNUNET_OK;
489}
490
491
492/**
493 * Process fs requests.
494 *
495 * @param cls closure
496 * @param server the initialized server
497 * @param cfg configuration to use
498 */
499static void
500run (void *cls,
501 struct GNUNET_SERVER_Handle *server,
502 const struct GNUNET_CONFIGURATION_Handle *cfg)
503{
504 GSF_cfg = cfg;
505 GSF_dsh = GNUNET_DATASTORE_connect (cfg);
506 if (GSF_dsh == NULL)
507 {
508 GNUNET_SCHEDULER_shutdown ();
509 return;
510 }
511 GSF_stats = GNUNET_STATISTICS_create ("fs", cfg);
512 block_cfg = GNUNET_CONFIGURATION_create ();
513 GNUNET_CONFIGURATION_set_value_string (block_cfg,
514 "block",
515 "PLUGINS",
516 "fs");
517 GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg);
518 GNUNET_assert (NULL != GSF_block_ctx);
519 GSF_dht = GNUNET_DHT_connect (cfg,
520 FS_DHT_HT_SIZE);
521 GSF_plan_init ();
522 GSF_pending_request_init_ ();
523 GSF_connected_peer_init_ ();
524 GSF_push_init_ ();
525 GSF_put_init_ ();
526 if ( (GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
527
528 (GNUNET_OK != main_init (server, cfg)) )
529 {
530 GNUNET_SCHEDULER_shutdown ();
531 shutdown_task (NULL, NULL);
532 return;
533 }
534}
535
536
537/**
538 * The main function for the fs service.
539 *
540 * @param argc number of arguments from the command line
541 * @param argv command line arguments
542 * @return 0 ok, 1 on error
543 */
544int
545main (int argc, char *const *argv)
546{
547 return (GNUNET_OK ==
548 GNUNET_SERVICE_run (argc,
549 argv,
550 "fs",
551 GNUNET_SERVICE_OPTION_NONE,
552 &run, NULL)) ? 0 : 1;
553}
554
555/* end of gnunet-service-fs.c */
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index 3c291cfc9..45767f204 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -65,6 +65,12 @@ struct GSF_PendingRequest
65 struct GNUNET_CONTAINER_HeapNode *hnode; 65 struct GNUNET_CONTAINER_HeapNode *hnode;
66 66
67 /** 67 /**
68 * Identity of the peer that we should use for the 'sender'
69 * (recipient of the response) when forwarding (0 for none).
70 */
71 GNUNET_PEER_Id sender_pid;
72
73 /**
68 * Number of valid entries in the 'replies_seen' array. 74 * Number of valid entries in the 'replies_seen' array.
69 */ 75 */
70 unsigned int replies_seen_count; 76 unsigned int replies_seen_count;
@@ -203,6 +209,7 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
203 * @param anonymity_level desired anonymity level 209 * @param anonymity_level desired anonymity level
204 * @param priority maximum outgoing cummulative request priority to use 210 * @param priority maximum outgoing cummulative request priority to use
205 * @param ttl current time-to-live for the request 211 * @param ttl current time-to-live for the request
212 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none
206 * @param replies_seen hash codes of known local replies 213 * @param replies_seen hash codes of known local replies
207 * @param replies_seen_count size of the 'replies_seen' array 214 * @param replies_seen_count size of the 'replies_seen' array
208 * @param rh handle to call when we get a reply 215 * @param rh handle to call when we get a reply
@@ -221,6 +228,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
221 uint32_t anonymity_level, 228 uint32_t anonymity_level,
222 uint32_t priority, 229 uint32_t priority,
223 int32_t ttl, 230 int32_t ttl,
231 GNUNET_PEER_Id sender_pid,
224 const GNUNET_HashCode *replies_seen, 232 const GNUNET_HashCode *replies_seen,
225 unsigned int replies_seen_count, 233 unsigned int replies_seen_count,
226 GSF_PendingRequestReplyHandler rh, 234 GSF_PendingRequestReplyHandler rh,
@@ -247,6 +255,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
247 pr->public_data.options = options; 255 pr->public_data.options = options;
248 pr->public_data.type = type; 256 pr->public_data.type = type;
249 pr->public_data.start_time = GNUNET_TIME_absolute_get (); 257 pr->public_data.start_time = GNUNET_TIME_absolute_get ();
258 pr->sender_pid = sender_pid;
250 pr->rh = rh; 259 pr->rh = rh;
251 pr->rh_cls = rh_cls; 260 pr->rh_cls = rh_cls;
252 if (ttl >= 0) 261 if (ttl >= 0)
@@ -451,14 +460,14 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
451 ext = (GNUNET_HashCode*) &gm[1]; 460 ext = (GNUNET_HashCode*) &gm[1];
452 k = 0; 461 k = 0;
453 if (GNUNET_YES != do_route) 462 if (GNUNET_YES != do_route)
454 GNUNET_PEER_resolve (pr->cp->pid, 463 GNUNET_PEER_resolve (pr->sender_pid,
455 (struct GNUNET_PeerIdentity*) &ext[k++]); 464 (struct GNUNET_PeerIdentity*) &ext[k++]);
456 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type) 465 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
457 memcpy (&ext[k++], 466 memcpy (&ext[k++],
458 &pr->public_data.namespace, 467 &pr->public_data.namespace,
459 sizeof (GNUNET_HashCode)); 468 sizeof (GNUNET_HashCode));
460 if (GNUNET_YES == pr->public_data.has_target) 469 if (GNUNET_YES == pr->public_data.has_target)
461 GNUNET_PEER_resolve (pr->public_data.target_pid, 470 GNUNET_PEER_resolve (pr->sender_pid,
462 (struct GNUNET_PeerIdentity*) &ext[k++]); 471 (struct GNUNET_PeerIdentity*) &ext[k++]);
463 if (pr->bf != NULL) 472 if (pr->bf != NULL)
464 GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf, 473 GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf,
@@ -487,6 +496,7 @@ clean_request (void *cls,
487 GNUNET_free_non_null (pr->replies_seen); 496 GNUNET_free_non_null (pr->replies_seen);
488 if (NULL != pr->bf) 497 if (NULL != pr->bf)
489 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 498 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
499 GNUNET_PEER_change_rc (pr->sender_pid, -1);
490 if (NULL != pr->hnode) 500 if (NULL != pr->hnode)
491 GNUNET_CONTAINER_heap_remove_node (requests_by_expiration_heap, 501 GNUNET_CONTAINER_heap_remove_node (requests_by_expiration_heap,
492 pr->hnode); 502 pr->hnode);
@@ -519,8 +529,8 @@ GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr)
519 * @param cls closure for it 529 * @param cls closure for it
520 */ 530 */
521void 531void
522GSF_iterate_pending_pr_map_ (GSF_PendingRequestIterator it, 532GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
523 void *cls) 533 void *cls)
524{ 534{
525 GNUNET_CONTAINER_multihashmap_iterate (pr_map, 535 GNUNET_CONTAINER_multihashmap_iterate (pr_map,
526 (GNUNET_CONTAINER_HashMapIterator) it, 536 (GNUNET_CONTAINER_HashMapIterator) it,
@@ -943,14 +953,12 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
943 953
944/** 954/**
945 * Setup the subsystem. 955 * Setup the subsystem.
946 *
947 * @param cfg configuration to use
948 */ 956 */
949void 957void
950GSF_pending_request_init_ (struct GNUNET_CONFIGURATION_Handle *cfg) 958GSF_pending_request_init_ ()
951{ 959{
952 if (GNUNET_OK != 960 if (GNUNET_OK !=
953 GNUNET_CONFIGURATION_get_value_number (cfg, 961 GNUNET_CONFIGURATION_get_value_number (GSF_cfg,
954 "fs", 962 "fs",
955 "MAX_PENDING_REQUESTS", 963 "MAX_PENDING_REQUESTS",
956 &max_pending_requests)) 964 &max_pending_requests))
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h
index 4af4f36ee..b59cbc541 100644
--- a/src/fs/gnunet-service-fs_pr.h
+++ b/src/fs/gnunet-service-fs_pr.h
@@ -178,6 +178,8 @@ typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
178 * @param anonymity_level desired anonymity level 178 * @param anonymity_level desired anonymity level
179 * @param priority maximum outgoing cummulative request priority to use 179 * @param priority maximum outgoing cummulative request priority to use
180 * @param ttl current time-to-live for the request 180 * @param ttl current time-to-live for the request
181 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
182 * reference counter is taken over by this function
181 * @param replies_seen hash codes of known local replies 183 * @param replies_seen hash codes of known local replies
182 * @param replies_seen_count size of the 'replies_seen' array 184 * @param replies_seen_count size of the 'replies_seen' array
183 * @param rh handle to call when we get a reply 185 * @param rh handle to call when we get a reply
@@ -196,6 +198,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
196 uint32_t anonymity_level, 198 uint32_t anonymity_level,
197 uint32_t priority, 199 uint32_t priority,
198 int32_t ttl, 200 int32_t ttl,
201 GNUNET_PEER_Id sender_pid,
199 const GNUNET_HashCode *replies_seen, 202 const GNUNET_HashCode *replies_seen,
200 unsigned int replies_seen_count, 203 unsigned int replies_seen_count,
201 GSF_PendingRequestReplyHandler rh, 204 GSF_PendingRequestReplyHandler rh,
@@ -327,7 +330,7 @@ GSF_handle_dht_reply_ (void *cls,
327 * @param cfg configuration to use 330 * @param cfg configuration to use
328 */ 331 */
329void 332void
330GSF_pending_request_init_ (struct GNUNET_CONFIGURATION_Handle *cfg); 333GSF_pending_request_init_ (void);
331 334
332 335
333/** 336/**
diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c
index c1f520510..1a29b7837 100644
--- a/src/fs/gnunet-service-fs_push.c
+++ b/src/fs/gnunet-service-fs_push.c
@@ -601,22 +601,20 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer)
601 601
602/** 602/**
603 * Setup the module. 603 * Setup the module.
604 *
605 * @param cfg configuration to use
606 */ 604 */
607void 605void
608GSF_push_init_ (struct GNUNET_CONFIGURATION_Handle *cfg) 606GSF_push_init_ ()
609{ 607{
610 int enabled; 608 int enabled;
611 609
612 enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, 610 enabled = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
613 "FS", 611 "FS",
614 "CONTENT_PUSHING"); 612 "CONTENT_PUSHING");
615 if (GNUNET_YES != enabled) 613 if (GNUNET_YES != enabled)
616 return; 614 return;
617 615
618 if (GNUNET_OK != 616 if (GNUNET_OK !=
619 GNUNET_CONFIGURATION_get_value_time (cfg, 617 GNUNET_CONFIGURATION_get_value_time (GSF_cfg,
620 "fs", 618 "fs",
621 "MIN_MIGRATION_DELAY", 619 "MIN_MIGRATION_DELAY",
622 &min_migration_delay)) 620 &min_migration_delay))
diff --git a/src/fs/gnunet-service-fs_push.h b/src/fs/gnunet-service-fs_push.h
index 5f7a0030c..7967b04cd 100644
--- a/src/fs/gnunet-service-fs_push.h
+++ b/src/fs/gnunet-service-fs_push.h
@@ -31,11 +31,9 @@
31 31
32/** 32/**
33 * Setup the module. 33 * Setup the module.
34 *
35 * @param cfg configuration to use
36 */ 34 */
37void 35void
38GSF_push_init_ (struct GNUNET_CONFIGURATION_Handle *cfg); 36GSF_push_init_ (void);
39 37
40 38
41/** 39/**
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c
index 6afeb4faa..97a7a90b5 100644
--- a/src/fs/gnunet-service-fs_put.c
+++ b/src/fs/gnunet-service-fs_put.c
@@ -209,11 +209,9 @@ gather_dht_put_blocks (void *cls,
209 209
210/** 210/**
211 * Setup the module. 211 * Setup the module.
212 *
213 * @param cfg configuration to use
214 */ 212 */
215void 213void
216GSF_put_init_ (struct GNUNET_CONFIGURATION_Handle *cfg) 214GSF_put_init_ ()
217{ 215{
218 dht_task = GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, NULL); 216 dht_task = GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, NULL);
219} 217}
diff --git a/src/fs/gnunet-service-fs_put.h b/src/fs/gnunet-service-fs_put.h
index ebec818b2..59b1f83e3 100644
--- a/src/fs/gnunet-service-fs_put.h
+++ b/src/fs/gnunet-service-fs_put.h
@@ -31,11 +31,9 @@
31 31
32/** 32/**
33 * Setup the module. 33 * Setup the module.
34 *
35 * @param cfg configuration to use
36 */ 34 */
37void 35void
38GSF_put_init_ (struct GNUNET_CONFIGURATION_Handle *cfg); 36GSF_put_init_ (void);
39 37
40 38
41/** 39/**