aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-01-18 09:00:05 +0000
committerChristian Grothoff <christian@grothoff.org>2010-01-18 09:00:05 +0000
commit53840e9a81994acd8dc4c0cb1c54a0d4764667c3 (patch)
tree317eb98e7e6ab6472d5700c0db2de84913489bce /src
parente67ade17fc2bf555af625863dab525f909b310f2 (diff)
downloadgnunet-53840e9a81994acd8dc4c0cb1c54a0d4764667c3.tar.gz
gnunet-53840e9a81994acd8dc4c0cb1c54a0d4764667c3.zip
making peer_configure API cancellable
Diffstat (limited to 'src')
-rw-r--r--src/core/Makefile.am3
-rw-r--r--src/core/core.h40
-rw-r--r--src/core/core_api.c216
-rw-r--r--src/core/core_api_peer_get_info.c177
-rw-r--r--src/core/gnunet-service-core.c16
-rw-r--r--src/fs/gnunet-service-fs.c40
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c1
-rw-r--r--src/include/gnunet_core_service.h58
-rw-r--r--src/include/gnunet_protocols.h13
-rw-r--r--src/testing/testing.c2
-rw-r--r--src/topology/gnunet-daemon-topology.c21
11 files changed, 260 insertions, 327 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 4c600c4fe..3dccb2dbd 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -14,7 +14,8 @@ lib_LTLIBRARIES = \
14 libgnunetcore.la 14 libgnunetcore.la
15 15
16libgnunetcore_la_SOURCES = \ 16libgnunetcore_la_SOURCES = \
17 core_api.c core.h 17 core_api.c core.h \
18 core_api_peer_get_info.c
18libgnunetcore_la_LIBADD = \ 19libgnunetcore_la_LIBADD = \
19 $(top_builddir)/src/arm/libgnunetarm.la \ 20 $(top_builddir)/src/arm/libgnunetarm.la \
20 $(top_builddir)/src/util/libgnunetutil.la \ 21 $(top_builddir)/src/util/libgnunetutil.la \
diff --git a/src/core/core.h b/src/core/core.h
index 19a090ea0..efa7bf1c9 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -45,11 +45,10 @@
45#define GNUNET_CORE_OPTION_NOTHING 0 45#define GNUNET_CORE_OPTION_NOTHING 0
46#define GNUNET_CORE_OPTION_SEND_CONNECT 1 46#define GNUNET_CORE_OPTION_SEND_CONNECT 1
47#define GNUNET_CORE_OPTION_SEND_DISCONNECT 2 47#define GNUNET_CORE_OPTION_SEND_DISCONNECT 2
48#define GNUNET_CORE_OPTION_SEND_BFC 4 48#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 4
49#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 8 49#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 8
50#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 16 50#define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 16
51#define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32 51#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 32
52#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 64
53 52
54 53
55/** 54/**
@@ -159,7 +158,7 @@ struct NotifyTrafficMessage
159 * Message sent to the core asking for configuration 158 * Message sent to the core asking for configuration
160 * information and possibly preference changes. 159 * information and possibly preference changes.
161 */ 160 */
162struct RequestConfigureMessage 161struct RequestInfoMessage
163{ 162{
164 /** 163 /**
165 * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE 164 * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
@@ -200,7 +199,7 @@ struct RequestConfigureMessage
200 199
201 200
202/** 201/**
203 * Response from the core to a "RequestConfigureMessage" 202 * Response from the core to a "RequestInfoMessage"
204 * providing traffic status information for a peer. 203 * providing traffic status information for a peer.
205 */ 204 */
206struct ConfigurationInfoMessage 205struct ConfigurationInfoMessage
@@ -239,32 +238,7 @@ struct ConfigurationInfoMessage
239 * Current traffic preference for the peer. 238 * Current traffic preference for the peer.
240 * 0 if we have been disconnected. 239 * 0 if we have been disconnected.
241 */ 240 */
242 double preference; 241 uint64_t preference;
243
244 /**
245 * Identity of the receiver or sender.
246 */
247 struct GNUNET_PeerIdentity peer;
248
249};
250
251
252/**
253 * Core asking a client to generate traffic for a particular
254 * target.
255 */
256struct SolicitTrafficMessage
257{
258 /**
259 * Header with type GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC
260 * or GNUNET_MESSAGE_TYPE_CORE_RECV_OK
261 */
262 struct GNUNET_MessageHeader header;
263
264 /**
265 * Number of bytes of traffic being solicited.
266 */
267 uint32_t solicit_size GNUNET_PACKED;
268 242
269 /** 243 /**
270 * Identity of the receiver or sender. 244 * Identity of the receiver or sender.
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 58ac3cc0e..21ce09aec 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -66,12 +66,6 @@ struct GNUNET_CORE_Handle
66 GNUNET_CORE_ClientEventHandler disconnects; 66 GNUNET_CORE_ClientEventHandler disconnects;
67 67
68 /** 68 /**
69 * Function to call whenever we're asked to generate traffic
70 * (data provided to be transmitted back to the service).
71 */
72 GNUNET_CORE_BufferFillCallback bfc;
73
74 /**
75 * Function to call whenever we receive an inbound message. 69 * Function to call whenever we receive an inbound message.
76 */ 70 */
77 GNUNET_CORE_MessageCallback inbound_notify; 71 GNUNET_CORE_MessageCallback inbound_notify;
@@ -365,86 +359,6 @@ trigger_next_request (struct GNUNET_CORE_Handle *h)
365 359
366 360
367/** 361/**
368 * cls is a pointer to a 32 bit number followed by that
369 * amount of data. If possible, copy to buf and return
370 * number of bytes copied. Always free the buffer.
371 */
372static size_t
373copy_and_free (void *cls, size_t size, void *buf)
374{
375 struct GNUNET_CORE_Handle *h = cls;
376 char *cbuf = h->solicit_buffer;
377 uint32_t have;
378
379 h->solicit_transmit_req = NULL;
380 h->solicit_buffer = NULL;
381 memcpy (&have, cbuf, sizeof (uint32_t));
382 if (have > size)
383 {
384 /* timeout / error case */
385 GNUNET_free (cbuf);
386 return 0;
387 }
388 memcpy (buf, cbuf + sizeof (uint32_t), have);
389 GNUNET_free (cbuf);
390 return have;
391}
392
393
394/**
395 * Call bfc callback to solicit traffic for the given peer.
396 *
397 * @param h our handle to the core service
398 * @param peer peer for which traffic is solicited
399 * @param amount number of bytes that are being solicited
400 */
401static void
402solicit_traffic (struct GNUNET_CORE_Handle *h,
403 const struct GNUNET_PeerIdentity *peer, uint32_t amount)
404{
405 char buf[amount];
406 size_t have;
407 char *cbuf;
408
409 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
410 "Core solicited %u bytes of traffic for `%s'!\n",
411 amount,
412 GNUNET_i2s (peer));
413 if (NULL != h->solicit_transmit_req)
414 {
415 /* more than one solicitation pending */
416 GNUNET_break (0);
417 return;
418 }
419 have = h->bfc (h->cls, peer, buf, amount);
420 if (have == 0)
421 {
422 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
423 "Can not help with traffic solicitation for `%s'!\n",
424 GNUNET_i2s (peer));
425 return;
426 }
427 GNUNET_assert (have >= sizeof (struct GNUNET_MessageHeader));
428 cbuf = GNUNET_malloc (have + sizeof (uint32_t));
429 memcpy (cbuf, &have, sizeof (uint32_t));
430 memcpy (cbuf + sizeof (uint32_t), buf, have);
431 h->solicit_buffer = cbuf;
432 h->solicit_transmit_req
433 = GNUNET_CORE_notify_transmit_ready (h,
434 0,
435 GNUNET_TIME_UNIT_SECONDS,
436 peer, have, &copy_and_free, h);
437 if (h->solicit_transmit_req == NULL)
438 {
439 /* this should not happen */
440 GNUNET_break (0);
441 GNUNET_free (cbuf);
442 h->solicit_buffer = NULL;
443 }
444}
445
446
447/**
448 * Handler for most messages received from the core. 362 * Handler for most messages received from the core.
449 * 363 *
450 * @param cls our "struct GNUNET_CORE_Handle" 364 * @param cls our "struct GNUNET_CORE_Handle"
@@ -458,11 +372,9 @@ main_handler (void *cls, const struct GNUNET_MessageHeader *msg)
458 const struct ConnectNotifyMessage *cnm; 372 const struct ConnectNotifyMessage *cnm;
459 const struct NotifyTrafficMessage *ntm; 373 const struct NotifyTrafficMessage *ntm;
460 const struct ConfigurationInfoMessage *cim; 374 const struct ConfigurationInfoMessage *cim;
461 const struct SolicitTrafficMessage *stm;
462 const struct GNUNET_MessageHeader *em; 375 const struct GNUNET_MessageHeader *em;
463 uint16_t msize; 376 uint16_t msize;
464 uint16_t et; 377 uint16_t et;
465 uint32_t ss;
466 const struct GNUNET_CORE_MessageHandler *mh; 378 const struct GNUNET_CORE_MessageHandler *mh;
467 379
468 if (msg == NULL) 380 if (msg == NULL)
@@ -601,27 +513,6 @@ main_handler (void *cls, const struct GNUNET_MessageHeader *msg)
601 GNUNET_CORE_notify_transmit_ready_cancel (h->submitted); // HUH? 513 GNUNET_CORE_notify_transmit_ready_cancel (h->submitted); // HUH?
602 trigger_next_request (h); 514 trigger_next_request (h);
603 break; 515 break;
604 case GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC:
605 if (msize != sizeof (struct SolicitTrafficMessage))
606 {
607 GNUNET_break (0);
608 break;
609 }
610 stm = (const struct SolicitTrafficMessage *) msg;
611 if (NULL == h->bfc)
612 {
613 GNUNET_break (0);
614 break;
615 }
616 ss = ntohl (stm->solicit_size);
617 if ((ss > GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
618 (ss + sizeof (struct SendMessage) > GNUNET_SERVER_MAX_MESSAGE_SIZE))
619 {
620 GNUNET_break (0);
621 break;
622 }
623 solicit_traffic (h, &stm->peer, ss);
624 break;
625 default: 516 default:
626 GNUNET_break (0); 517 GNUNET_break (0);
627 break; 518 break;
@@ -766,8 +657,6 @@ transmit_start (void *cls, size_t size, void *buf)
766 opt |= GNUNET_CORE_OPTION_SEND_CONNECT; 657 opt |= GNUNET_CORE_OPTION_SEND_CONNECT;
767 if (h->disconnects != NULL) 658 if (h->disconnects != NULL)
768 opt |= GNUNET_CORE_OPTION_SEND_DISCONNECT; 659 opt |= GNUNET_CORE_OPTION_SEND_DISCONNECT;
769 if (h->bfc != NULL)
770 opt |= GNUNET_CORE_OPTION_SEND_BFC;
771 if (h->inbound_notify != NULL) 660 if (h->inbound_notify != NULL)
772 { 661 {
773 if (h->inbound_hdr_only) 662 if (h->inbound_hdr_only)
@@ -807,7 +696,6 @@ transmit_start (void *cls, size_t size, void *buf)
807 * connected to the core service; note that timeout is only meaningful if init is not NULL 696 * connected to the core service; note that timeout is only meaningful if init is not NULL
808 * @param connects function to call on peer connect, can be NULL 697 * @param connects function to call on peer connect, can be NULL
809 * @param disconnects function to call on peer disconnect / timeout, can be NULL 698 * @param disconnects function to call on peer disconnect / timeout, can be NULL
810 * @param bfc function to call to fill up spare bandwidth, can be NULL
811 * @param inbound_notify function to call for all inbound messages, can be NULL 699 * @param inbound_notify function to call for all inbound messages, can be NULL
812 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the 700 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
813 * GNUNET_MessageHeader and hence we do not need to give it the full message; 701 * GNUNET_MessageHeader and hence we do not need to give it the full message;
@@ -828,7 +716,6 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
828 GNUNET_CORE_StartupCallback init, 716 GNUNET_CORE_StartupCallback init,
829 GNUNET_CORE_ClientEventHandler connects, 717 GNUNET_CORE_ClientEventHandler connects,
830 GNUNET_CORE_ClientEventHandler disconnects, 718 GNUNET_CORE_ClientEventHandler disconnects,
831 GNUNET_CORE_BufferFillCallback bfc,
832 GNUNET_CORE_MessageCallback inbound_notify, 719 GNUNET_CORE_MessageCallback inbound_notify,
833 int inbound_hdr_only, 720 int inbound_hdr_only,
834 GNUNET_CORE_MessageCallback outbound_notify, 721 GNUNET_CORE_MessageCallback outbound_notify,
@@ -844,7 +731,6 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
844 h->init = init; 731 h->init = init;
845 h->connects = connects; 732 h->connects = connects;
846 h->disconnects = disconnects; 733 h->disconnects = disconnects;
847 h->bfc = bfc;
848 h->inbound_notify = inbound_notify; 734 h->inbound_notify = inbound_notify;
849 h->outbound_notify = outbound_notify; 735 h->outbound_notify = outbound_notify;
850 h->inbound_hdr_only = inbound_hdr_only; 736 h->inbound_hdr_only = inbound_hdr_only;
@@ -899,108 +785,6 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
899 785
900 786
901/** 787/**
902 * Build the configure message.
903 */
904static size_t
905produce_configure_message (void *cls, size_t size, void *buf)
906{
907 struct GNUNET_CORE_TransmitHandle *th = cls;
908 struct GNUNET_CORE_Handle *ch = th->ch;
909
910 if (buf == NULL)
911 {
912 /* communicate handle timeout/error! */
913 if (th->info != NULL)
914 th->info (th->info_cls, NULL, 0, 0, GNUNET_TIME_UNIT_ZERO, 0, 0.0);
915 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
916 GNUNET_CORE_notify_transmit_ready_cancel (th);
917 if (ch->submitted == th)
918 ch->submitted = NULL;
919 trigger_next_request (ch);
920 return 0;
921 }
922 GNUNET_assert (size >= sizeof (struct RequestConfigureMessage));
923 memcpy (buf, &th[1], sizeof (struct RequestConfigureMessage));
924 if (th->prev == NULL)
925 ch->pending_head = th->next;
926 else
927 th->prev->next = th->next;
928 if (th->next == NULL)
929 ch->pending_tail = th->prev;
930 else
931 th->next->prev = th->prev;
932 return sizeof (struct RequestConfigureMessage);
933}
934
935
936/**
937 * Obtain statistics and/or change preferences for the given peer.
938 *
939 * @param handle connection to core to use
940 * @param peer identifies the peer
941 * @param timeout after how long should we give up (and call "info" with NULL
942 * for "peer" to signal an error)?
943 * @param bpm_out set to the current bandwidth limit (sending) for this peer,
944 * caller should set "bpm_out" to "-1" to avoid changing
945 * the current value; otherwise "bpm_out" will be lowered to
946 * the specified value; passing a pointer to "0" can be used to force
947 * us to disconnect from the peer; "bpm_out" might not increase
948 * as specified since the upper bound is generally
949 * determined by the other peer!
950 * @param amount reserve N bytes for receiving, negative
951 * amounts can be used to undo a (recent) reservation;
952 * @param preference increase incoming traffic share preference by this amount;
953 * in the absence of "amount" reservations, we use this
954 * preference value to assign proportional bandwidth shares
955 * to all connected peers
956 * @param info function to call with the resulting configuration information
957 * @param info_cls closure for info
958 */
959void
960GNUNET_CORE_peer_configure (struct GNUNET_CORE_Handle *handle,
961 const struct GNUNET_PeerIdentity *peer,
962 struct GNUNET_TIME_Relative timeout,
963 unsigned int bpm_out,
964 int amount,
965 unsigned long long preference,
966 GNUNET_CORE_PeerConfigurationInfoCallback info,
967 void *info_cls)
968{
969 struct RequestConfigureMessage *rcm;
970 struct GNUNET_CORE_TransmitHandle *th;
971
972 th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle) +
973 sizeof (struct RequestConfigureMessage));
974 /* append to list */
975 th->prev = handle->pending_tail;
976 if (handle->pending_tail == NULL)
977 handle->pending_head = th;
978 else
979 handle->pending_tail->next = th;
980 th->ch = handle;
981 th->get_message = &produce_configure_message;
982 th->get_message_cls = th;
983 th->info = info;
984 th->info_cls = info_cls;
985 th->timeout = GNUNET_TIME_relative_to_absolute (timeout);
986 th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched,
987 timeout,
988 &timeout_request, th);
989 th->msize = sizeof (struct RequestConfigureMessage);
990 rcm = (struct RequestConfigureMessage *) &th[1];
991 rcm->header.size = htons (sizeof (struct RequestConfigureMessage));
992 rcm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE);
993 rcm->reserved = htonl (0);
994 rcm->limit_outbound_bpm = htonl (bpm_out);
995 rcm->reserve_inbound = htonl (amount);
996 rcm->preference_change = GNUNET_htonll(preference);
997 rcm->peer = *peer;
998 if (handle->pending_head == th)
999 trigger_next_request (handle);
1000}
1001
1002
1003/**
1004 * Build the message requesting data transmission. 788 * Build the message requesting data transmission.
1005 */ 789 */
1006static size_t 790static size_t
diff --git a/src/core/core_api_peer_get_info.c b/src/core/core_api_peer_get_info.c
new file mode 100644
index 000000000..aa6aff040
--- /dev/null
+++ b/src/core/core_api_peer_get_info.c
@@ -0,0 +1,177 @@
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 2, 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 core/core_api_peer_get_info.c
23 * @brief implementation of the peer_get_info functions
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_core_service.h"
28#include "core.h"
29
30
31struct GNUNET_CORE_InformationRequestContext
32{
33
34 /**
35 * Our connection to the service.
36 */
37 struct GNUNET_CLIENT_Connection *client;
38
39 /**
40 * Function to call with the information.
41 */
42 GNUNET_CORE_PeerConfigurationInfoCallback info;
43
44 /**
45 * Closure for info.
46 */
47 void *info_cls;
48
49};
50
51
52/**
53 * Receive reply from core service with information about a peer.
54 *
55 * @param cls our 'struct GNUNET_CORE_InformationRequestContext *'
56 * @param msg NULL on error (i.e. timeout)
57 */
58static void
59receive_info (void *cls,
60 const struct GNUNET_MessageHeader *msg)
61{
62 struct GNUNET_CORE_InformationRequestContext *irc = cls;
63 const struct ConfigurationInfoMessage *cim;
64
65 if (msg == NULL)
66 {
67 if (irc != NULL)
68 irc->info (irc->info_cls,
69 NULL, 0, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0, 0);
70 GNUNET_CLIENT_disconnect (irc->client);
71 GNUNET_free (irc);
72 return;
73 }
74 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO) ||
75 (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage)) )
76 {
77 GNUNET_break (0);
78 if (irc != NULL)
79 irc->info (irc->info_cls,
80 NULL, 0, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0, 0);
81 GNUNET_CLIENT_disconnect (irc->client);
82 GNUNET_free (irc);
83 return;
84 }
85 cim = (const struct ConfigurationInfoMessage*) msg;
86 if (irc != NULL)
87 irc->info (irc->info_cls,
88 &cim->peer,
89 ntohl (cim->bpm_in),
90 ntohl (cim->bpm_out),
91 GNUNET_TIME_relative_ntoh (cim->latency),
92 ntohl (cim->reserved_amount),
93 GNUNET_ntohll (cim->preference));
94 GNUNET_CLIENT_disconnect (irc->client);
95 GNUNET_free (irc);
96}
97
98
99/**
100 * Obtain statistics and/or change preferences for the given peer.
101 *
102 * @param sched scheduler to use
103 * @param cfg configuration to use
104 * @param peer identifies the peer
105 * @param timeout after how long should we give up (and call "info" with NULL
106 * for "peer" to signal an error)?
107 * @param bpm_out set to the current bandwidth limit (sending) for this peer,
108 * caller should set "bpm_out" to "-1" to avoid changing
109 * the current value; otherwise "bpm_out" will be lowered to
110 * the specified value; passing a pointer to "0" can be used to force
111 * us to disconnect from the peer; "bpm_out" might not increase
112 * as specified since the upper bound is generally
113 * determined by the other peer!
114 * @param amount reserve N bytes for receiving, negative
115 * amounts can be used to undo a (recent) reservation;
116 * @param preference increase incoming traffic share preference by this amount;
117 * in the absence of "amount" reservations, we use this
118 * preference value to assign proportional bandwidth shares
119 * to all connected peers
120 * @param info function to call with the resulting configuration information
121 * @param info_cls closure for info
122 * @return NULL on error
123 */
124struct GNUNET_CORE_InformationRequestContext *
125GNUNET_CORE_peer_get_info (struct GNUNET_SCHEDULER_Handle *sched,
126 const struct GNUNET_CONFIGURATION_Handle *cfg,
127 const struct GNUNET_PeerIdentity *peer,
128 struct GNUNET_TIME_Relative timeout,
129 uint32_t bpm_out,
130 int32_t amount,
131 uint64_t preference,
132 GNUNET_CORE_PeerConfigurationInfoCallback info,
133 void *info_cls)
134{
135 struct GNUNET_CORE_InformationRequestContext *irc;
136 struct RequestInfoMessage rim;
137 struct GNUNET_CLIENT_Connection *client;
138 int retry;
139
140 client = GNUNET_CLIENT_connect (sched, "core", cfg);
141 if (client == NULL)
142 return NULL;
143 irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
144 irc->client = client;
145 irc->info = info;
146 irc->info_cls = info_cls;
147 rim.header.size = htons (sizeof (struct RequestInfoMessage));
148 rim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
149 rim.reserved = htonl (0);
150 rim.limit_outbound_bpm = htonl (bpm_out);
151 rim.reserve_inbound = htonl (amount);
152 rim.preference_change = GNUNET_htonll(preference);
153 rim.peer = *peer;
154 retry = ( (amount == 0) && (preference == 0) ) ? GNUNET_YES : GNUNET_NO;
155 GNUNET_assert (GNUNET_OK == GNUNET_CLIENT_transmit_and_get_response (client,
156 &rim.header,
157 timeout,
158 retry,
159 &receive_info,
160 irc));
161 return irc;
162}
163
164
165/**
166 * Cancel request for getting information about a peer.
167 *
168 * @param irc context returned by the original GNUNET_CORE_peer_get_info call
169 */
170void
171GNUNET_CORE_peer_get_info_cancel (struct GNUNET_CORE_InformationRequestContext *irc)
172{
173 GNUNET_CLIENT_disconnect (irc->client);
174 GNUNET_free (irc);
175}
176
177/* end of core_api_peer_get_info.c */
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 56ea6d30d..d1375dc45 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -1051,14 +1051,14 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
1051 1051
1052 1052
1053/** 1053/**
1054 * Handle REQUEST_CONFIGURE request. 1054 * Handle REQUEST_INFO request.
1055 */ 1055 */
1056static void 1056static void
1057handle_client_request_configure (void *cls, 1057handle_client_request_info (void *cls,
1058 struct GNUNET_SERVER_Client *client, 1058 struct GNUNET_SERVER_Client *client,
1059 const struct GNUNET_MessageHeader *message) 1059 const struct GNUNET_MessageHeader *message)
1060{ 1060{
1061 const struct RequestConfigureMessage *rcm; 1061 const struct RequestInfoMessage *rcm;
1062 struct Neighbour *n; 1062 struct Neighbour *n;
1063 struct ConfigurationInfoMessage cim; 1063 struct ConfigurationInfoMessage cim;
1064 struct Client *c; 1064 struct Client *c;
@@ -1067,9 +1067,9 @@ handle_client_request_configure (void *cls,
1067 1067
1068#if DEBUG_CORE_CLIENT 1068#if DEBUG_CORE_CLIENT
1069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1070 "Core service receives `%s' request.\n", "CONFIGURE"); 1070 "Core service receives `%s' request.\n", "REQUEST_INFO");
1071#endif 1071#endif
1072 rcm = (const struct RequestConfigureMessage *) message; 1072 rcm = (const struct RequestInfoMessage *) message;
1073 n = find_neighbour (&rcm->peer); 1073 n = find_neighbour (&rcm->peer);
1074 memset (&cim, 0, sizeof (cim)); 1074 memset (&cim, 0, sizeof (cim));
1075 if ((n != NULL) && (n->status == PEER_STATE_KEY_CONFIRMED)) 1075 if ((n != NULL) && (n->status == PEER_STATE_KEY_CONFIRMED))
@@ -1991,9 +1991,9 @@ handle_client_send (void *cls,
1991static struct GNUNET_SERVER_MessageHandler handlers[] = { 1991static struct GNUNET_SERVER_MessageHandler handlers[] = {
1992 {&handle_client_init, NULL, 1992 {&handle_client_init, NULL,
1993 GNUNET_MESSAGE_TYPE_CORE_INIT, 0}, 1993 GNUNET_MESSAGE_TYPE_CORE_INIT, 0},
1994 {&handle_client_request_configure, NULL, 1994 {&handle_client_request_info, NULL,
1995 GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE, 1995 GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO,
1996 sizeof (struct RequestConfigureMessage)}, 1996 sizeof (struct RequestInfoMessage)},
1997 {&handle_client_send, NULL, 1997 {&handle_client_send, NULL,
1998 GNUNET_MESSAGE_TYPE_CORE_SEND, 0}, 1998 GNUNET_MESSAGE_TYPE_CORE_SEND, 0},
1999 {NULL, NULL, 0, 0} 1999 {NULL, NULL, 0, 0}
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index ed68dcc4a..7a8c0ad33 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -417,6 +417,11 @@ struct PendingRequest
417 struct GNUNET_CONTAINER_BloomFilter *bf; 417 struct GNUNET_CONTAINER_BloomFilter *bf;
418 418
419 /** 419 /**
420 * Context of our GNUNET_CORE_peer_get_info call.
421 */
422 struct GNUNET_CORE_InformationRequestContext *irc;
423
424 /**
420 * Replies that we have received but were unable to forward yet 425 * Replies that we have received but were unable to forward yet
421 * (typically non-null only if we have a pending transmission 426 * (typically non-null only if we have a pending transmission
422 * request with the client or the respective peer). 427 * request with the client or the respective peer).
@@ -1787,6 +1792,7 @@ target_reservation_cb (void *cls,
1787 uint16_t size; 1792 uint16_t size;
1788 struct GNUNET_TIME_Relative maxdelay; 1793 struct GNUNET_TIME_Relative maxdelay;
1789 1794
1795 pr->irc = NULL;
1790 GNUNET_assert (peer != NULL); 1796 GNUNET_assert (peer != NULL);
1791 if ( (amount != DBLOCK_SIZE) || 1797 if ( (amount != DBLOCK_SIZE) ||
1792 (pr->cth != NULL) ) 1798 (pr->cth != NULL) )
@@ -1865,17 +1871,15 @@ forward_request_task (void *cls,
1865 return; 1871 return;
1866 } 1872 }
1867 /* (2) reserve reply bandwidth */ 1873 /* (2) reserve reply bandwidth */
1868 // FIXME: need a way to cancel; this 1874 GNUNET_assert (NULL == pr->irc);
1869 // async operation is problematic (segv-problematic) 1875 pr->irc = GNUNET_CORE_peer_get_info (sched, cfg,
1870 // if "pr" is destroyed while it happens! 1876 &psc.target,
1871 GNUNET_CORE_peer_configure (core, 1877 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1872 &psc.target, 1878 -1,
1873 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1879 DBLOCK_SIZE, // FIXME: make dependent on type?
1874 -1, 1880 0,
1875 DBLOCK_SIZE, // FIXME: make dependent on type? 1881 &target_reservation_cb,
1876 0, 1882 pr);
1877 &target_reservation_cb,
1878 pr);
1879} 1883}
1880 1884
1881 1885
@@ -2216,6 +2220,11 @@ destroy_pending_request (struct PendingRequest *pr)
2216 pr); 2220 pr);
2217 // FIXME: not sure how this can work (efficiently) 2221 // FIXME: not sure how this can work (efficiently)
2218 // also, what does the return value mean? 2222 // also, what does the return value mean?
2223 if (pr->irc != NULL)
2224 {
2225 GNUNET_CORE_peer_get_info_cancel (pr->irc);
2226 pr->irc = NULL;
2227 }
2219 if (pr->client == NULL) 2228 if (pr->client == NULL)
2220 { 2229 {
2221 GNUNET_CONTAINER_heap_remove_node (requests_by_expiration, 2230 GNUNET_CONTAINER_heap_remove_node (requests_by_expiration,
@@ -2914,10 +2923,10 @@ handle_p2p_get (void *cls,
2914 if (preference < QUERY_BANDWIDTH_VALUE) 2923 if (preference < QUERY_BANDWIDTH_VALUE)
2915 preference = QUERY_BANDWIDTH_VALUE; 2924 preference = QUERY_BANDWIDTH_VALUE;
2916 // FIXME: also reserve bandwidth for reply? 2925 // FIXME: also reserve bandwidth for reply?
2917 GNUNET_CORE_peer_configure (core, 2926 (void) GNUNET_CORE_peer_get_info (sched, cfg,
2918 other, 2927 other,
2919 GNUNET_TIME_UNIT_FOREVER_REL, 2928 GNUNET_TIME_UNIT_FOREVER_REL,
2920 0, 0, preference, NULL, NULL); 2929 0, 0, preference, NULL, NULL);
2921 if (0 != (pgc->policy & ROUTING_POLICY_ANSWER)) 2930 if (0 != (pgc->policy & ROUTING_POLICY_ANSWER))
2922 pgc->drq = queue_ds_request (BASIC_DATASTORE_REQUEST_DELAY, 2931 pgc->drq = queue_ds_request (BASIC_DATASTORE_REQUEST_DELAY,
2923 &ds_get_request, 2932 &ds_get_request,
@@ -3318,7 +3327,6 @@ run (void *cls,
3318 NULL, 3327 NULL,
3319 &peer_connect_handler, 3328 &peer_connect_handler,
3320 &peer_disconnect_handler, 3329 &peer_disconnect_handler,
3321 NULL,
3322 NULL, GNUNET_NO, 3330 NULL, GNUNET_NO,
3323 NULL, GNUNET_NO, 3331 NULL, GNUNET_NO,
3324 p2p_handlers); 3332 p2p_handlers);
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 14daa29a6..fd1068839 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -192,7 +192,6 @@ run (void *cls,
192 NULL, 192 NULL,
193 &core_init, 193 &core_init,
194 ch, dh, 194 ch, dh,
195 NULL,
196 NULL, GNUNET_NO, 195 NULL, GNUNET_NO,
197 NULL, GNUNET_NO, 196 NULL, GNUNET_NO,
198 handlers); 197 handlers);
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index dbe39d0d7..c520b5b7d 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -63,25 +63,6 @@ typedef void (*GNUNET_CORE_ClientEventHandler) (void *cls,
63 63
64 64
65/** 65/**
66 * Type of a send callback to fill up buffers.
67 *
68 * @param receiver the receiver of the message
69 * @param position is the reference to the
70 * first unused position in the buffer where GNUnet is building
71 * the message
72 * @param padding is the number of bytes left in that buffer.
73 * @return the number of bytes written to
74 * that buffer (must be a positive number).
75 */
76typedef unsigned int
77 (*GNUNET_CORE_BufferFillCallback) (void *cls,
78 const struct GNUNET_PeerIdentity *
79 receiver,
80 void *position,
81 size_t padding);
82
83
84/**
85 * Functions with this signature are called whenever a message is 66 * Functions with this signature are called whenever a message is
86 * received or transmitted. 67 * received or transmitted.
87 * 68 *
@@ -159,7 +140,6 @@ typedef void
159 * connected to the core service; note that timeout is only meaningful if init is not NULL 140 * connected to the core service; note that timeout is only meaningful if init is not NULL
160 * @param connects function to call on peer connect, can be NULL 141 * @param connects function to call on peer connect, can be NULL
161 * @param disconnects function to call on peer disconnect / timeout, can be NULL 142 * @param disconnects function to call on peer disconnect / timeout, can be NULL
162 * @param bfc function to call to fill up spare bandwidth, can be NULL
163 * @param inbound_notify function to call for all inbound messages, can be NULL 143 * @param inbound_notify function to call for all inbound messages, can be NULL
164 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the 144 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
165 * GNUNET_MessageHeader and hence we do not need to give it the full message; 145 * GNUNET_MessageHeader and hence we do not need to give it the full message;
@@ -180,7 +160,6 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
180 GNUNET_CORE_StartupCallback init, 160 GNUNET_CORE_StartupCallback init,
181 GNUNET_CORE_ClientEventHandler connects, 161 GNUNET_CORE_ClientEventHandler connects,
182 GNUNET_CORE_ClientEventHandler disconnects, 162 GNUNET_CORE_ClientEventHandler disconnects,
183 GNUNET_CORE_BufferFillCallback bfc,
184 GNUNET_CORE_MessageCallback inbound_notify, 163 GNUNET_CORE_MessageCallback inbound_notify,
185 int inbound_hdr_only, 164 int inbound_hdr_only,
186 GNUNET_CORE_MessageCallback outbound_notify, 165 GNUNET_CORE_MessageCallback outbound_notify,
@@ -219,10 +198,17 @@ typedef void
219 unsigned long long preference); 198 unsigned long long preference);
220 199
221 200
201
202/**
203 * Context that can be used to cancel a peer information request.
204 */
205struct GNUNET_CORE_InformationRequestContext;
206
222/** 207/**
223 * Obtain statistics and/or change preferences for the given peer. 208 * Obtain statistics and/or change preferences for the given peer.
224 * 209 *
225 * @param handle connection to core to use 210 * @param sched scheduler to use
211 * @param cfg configuration to use
226 * @param peer identifies the peer 212 * @param peer identifies the peer
227 * @param timeout after how long should we give up (and call "info" with NULL 213 * @param timeout after how long should we give up (and call "info" with NULL
228 * for "peer" to signal an error)? 214 * for "peer" to signal an error)?
@@ -241,17 +227,27 @@ typedef void
241 * to all connected peers 227 * to all connected peers
242 * @param info function to call with the resulting configuration information 228 * @param info function to call with the resulting configuration information
243 * @param info_cls closure for info 229 * @param info_cls closure for info
230 * @return NULL on error
231 */
232struct GNUNET_CORE_InformationRequestContext *
233GNUNET_CORE_peer_get_info (struct GNUNET_SCHEDULER_Handle *sched,
234 const struct GNUNET_CONFIGURATION_Handle *cfg,
235 const struct GNUNET_PeerIdentity *peer,
236 struct GNUNET_TIME_Relative timeout,
237 uint32_t bpm_out,
238 int32_t amount,
239 uint64_t preference,
240 GNUNET_CORE_PeerConfigurationInfoCallback info,
241 void *info_cls);
242
243
244/**
245 * Cancel request for getting information about a peer.
246 *
247 * @param irc context returned by the original GNUNET_CORE_peer_get_info call
244 */ 248 */
245// FIXME: should return handle for cancellation!
246void 249void
247GNUNET_CORE_peer_configure (struct GNUNET_CORE_Handle *handle, 250GNUNET_CORE_peer_get_info_cancel (struct GNUNET_CORE_InformationRequestContext *irc);
248 const struct GNUNET_PeerIdentity *peer,
249 struct GNUNET_TIME_Relative timeout,
250 unsigned int bpm_out,
251 int amount,
252 unsigned long long preference,
253 GNUNET_CORE_PeerConfigurationInfoCallback info,
254 void *info_cls);
255 251
256 252
257/** 253/**
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 8f966c737..51442958c 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -276,7 +276,7 @@ extern "C"
276/** 276/**
277 * Request from client to "configure" P2P connection. 277 * Request from client to "configure" P2P connection.
278 */ 278 */
279#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE 70 279#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO 70
280 280
281/** 281/**
282 * Response from server about (possibly updated) P2P 282 * Response from server about (possibly updated) P2P
@@ -285,16 +285,9 @@ extern "C"
285#define GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO 71 285#define GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO 71
286 286
287/** 287/**
288 * Solicitation from server for transmission (may have 288 * Request from client with message to transmit.
289 * been requested or also be transmitted without
290 * client's request).
291 */ 289 */
292#define GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC 72 290#define GNUNET_MESSAGE_TYPE_CORE_SEND 72
293
294/**
295 * Response from client with message to transmit.
296 */
297#define GNUNET_MESSAGE_TYPE_CORE_SEND 73
298 291
299 292
300/** 293/**
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 8604e90ed..cc584e74a 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -434,7 +434,7 @@ start_fsm (void *cls,
434 ARM_START_WAIT, 434 ARM_START_WAIT,
435 d, 435 d,
436 &testing_init, 436 &testing_init,
437 NULL, NULL, NULL, 437 NULL, NULL,
438 NULL, GNUNET_NO, 438 NULL, GNUNET_NO,
439 NULL, GNUNET_NO, 439 NULL, GNUNET_NO,
440 no_handlers); 440 no_handlers);
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 880f8603c..157e270ab 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -238,14 +238,15 @@ static struct GNUNET_PEERINFO_IteratorContext *pitr_more;
238static void 238static void
239force_disconnect (const struct GNUNET_PeerIdentity *peer) 239force_disconnect (const struct GNUNET_PeerIdentity *peer)
240{ 240{
241 GNUNET_CORE_peer_configure (handle, 241 // FIXME: do something with return value!
242 peer, 242 GNUNET_CORE_peer_get_info (sched, cfg,
243 GNUNET_TIME_UNIT_FOREVER_REL, 243 peer,
244 0, 244 GNUNET_TIME_UNIT_FOREVER_REL,
245 0, 245 0,
246 0, 246 0,
247 NULL, 247 0,
248 NULL); 248 NULL,
249 NULL);
249} 250}
250 251
251 252
@@ -1057,6 +1058,7 @@ gather_hello_callback (void *cls,
1057} 1058}
1058 1059
1059 1060
1061// FIXME: this no longer works (no solicitation!)
1060/** 1062/**
1061 * Function to fill send buffer with HELLO. 1063 * Function to fill send buffer with HELLO.
1062 * 1064 *
@@ -1069,7 +1071,7 @@ gather_hello_callback (void *cls,
1069 * @return the number of bytes written to 1071 * @return the number of bytes written to
1070 * that buffer (must be a positive number). 1072 * that buffer (must be a positive number).
1071 */ 1073 */
1072static unsigned int 1074/* static */ unsigned int
1073hello_advertising (void *cls, 1075hello_advertising (void *cls,
1074 const struct GNUNET_PeerIdentity * 1076 const struct GNUNET_PeerIdentity *
1075 receiver, 1077 receiver,
@@ -1275,7 +1277,6 @@ run (void *cls,
1275 &core_init, 1277 &core_init,
1276 &connect_notify, 1278 &connect_notify,
1277 &disconnect_notify, 1279 &disconnect_notify,
1278 &hello_advertising,
1279 NULL, GNUNET_NO, 1280 NULL, GNUNET_NO,
1280 NULL, GNUNET_NO, 1281 NULL, GNUNET_NO,
1281 handlers); 1282 handlers);