aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-21 15:17:23 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-21 15:17:23 +0000
commit4440df3d5ddffe5038b0354075e85c18fee57f3a (patch)
tree62a40f8b837c732624cbe2808d4145a32242b012 /src/core
parent5a38c8f0d1826ea964e3e3452e1a3a2a24d7d35b (diff)
downloadgnunet-4440df3d5ddffe5038b0354075e85c18fee57f3a.tar.gz
gnunet-4440df3d5ddffe5038b0354075e85c18fee57f3a.zip
removing deprecated, dead test-connected API
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Makefile.am3
-rw-r--r--src/core/core_api_is_connected.c224
-rw-r--r--src/core/core_api_iterate_peers.c27
-rw-r--r--src/core/gnunet-service-core_clients.c4
-rw-r--r--src/core/gnunet-service-core_sessions.c31
-rw-r--r--src/core/gnunet-service-core_sessions.h18
6 files changed, 8 insertions, 299 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index ebe1ae1ce..b34cb5a44 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -22,8 +22,7 @@ lib_LTLIBRARIES = \
22 22
23libgnunetcore_la_SOURCES = \ 23libgnunetcore_la_SOURCES = \
24 core_api.c core.h \ 24 core_api.c core.h \
25 core_api_iterate_peers.c \ 25 core_api_iterate_peers.c
26 core_api_is_connected.c
27libgnunetcore_la_LIBADD = \ 26libgnunetcore_la_LIBADD = \
28 $(top_builddir)/src/util/libgnunetutil.la \ 27 $(top_builddir)/src/util/libgnunetutil.la \
29 $(GN_LIBINTL) $(XLIB) 28 $(GN_LIBINTL) $(XLIB)
diff --git a/src/core/core_api_is_connected.c b/src/core/core_api_is_connected.c
deleted file mode 100644
index 31edb94b4..000000000
--- a/src/core/core_api_is_connected.c
+++ /dev/null
@@ -1,224 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009, 2010, 2012 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 core/core_api_is_connected.c
23 * @brief implementation of the 'GNUNET_CORE_is_peer_connected function
24 * @author Christian Grothoff
25 * @author Nathan Evans
26 *
27 * TODO:
28 * - define nice structs for the IPC messages in core.h
29 * - consider NOT always sending the 'END' message -- it is redundant!
30 */
31#include "platform.h"
32#include "gnunet_core_service.h"
33#include "core.h"
34
35
36/**
37 * Closure for 'transmit_is_connected_request"
38 */
39struct GNUNET_CORE_ConnectTestHandle
40{
41
42 /**
43 * Our connection to the service.
44 */
45 struct GNUNET_CLIENT_Connection *client;
46
47 /**
48 * Handle for transmitting a request.
49 */
50 struct GNUNET_CLIENT_TransmitHandle *th;
51
52 /**
53 * Function called with the peer.
54 */
55 GNUNET_CORE_ConnectEventHandler peer_cb;
56
57 /**
58 * Peer to check for.
59 */
60 struct GNUNET_PeerIdentity peer;
61
62 /**
63 * Closure for peer_cb.
64 */
65 void *cb_cls;
66
67};
68
69
70/**
71 * Receive reply from core service with information about a peer.
72 *
73 * @param cls our 'struct GNUNET_CORE_RequestContext *'
74 * @param msg NULL on error or last entry
75 */
76static void
77receive_connect_info (void *cls, const struct GNUNET_MessageHeader *msg)
78{
79 struct GNUNET_CORE_ConnectTestHandle *cth = cls;
80 const struct ConnectNotifyMessage *connect_message;
81 uint16_t msize;
82
83 if (NULL == msg)
84 {
85 /* core died, failure */
86 cth->peer_cb (cth->cb_cls, NULL);
87 GNUNET_CORE_is_peer_connected_cancel (cth);
88 return;
89 }
90 if ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) &&
91 (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)))
92 {
93 /* end of transmissions */
94 cth->peer_cb (cth->cb_cls, NULL);
95 GNUNET_CORE_is_peer_connected_cancel (cth);
96 return;
97 }
98 msize = ntohs (msg->size);
99 /* Handle incorrect message type or size, disconnect and clean up */
100 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) ||
101 (msize < sizeof (struct ConnectNotifyMessage)))
102 {
103 GNUNET_break (0);
104 cth->peer_cb (cth->cb_cls, NULL);
105 GNUNET_CORE_is_peer_connected_cancel (cth);
106 return;
107 }
108 connect_message = (const struct ConnectNotifyMessage *) msg;
109 if (msize != sizeof (struct ConnectNotifyMessage))
110 {
111 GNUNET_break (0);
112 cth->peer_cb (cth->cb_cls, NULL);
113 GNUNET_CORE_is_peer_connected_cancel (cth);
114 return;
115 }
116 /* Normal case */
117 cth->peer_cb (cth->cb_cls, &connect_message->peer);
118 GNUNET_CLIENT_receive (cth->client, &receive_connect_info,
119 cth, GNUNET_TIME_UNIT_FOREVER_REL);
120}
121
122
123/**
124 * Function called to notify a client about the socket
125 * begin ready to queue more data. "buf" will be
126 * NULL and "size" zero if the socket was closed for
127 * writing in the meantime.
128 *
129 * @param cls closure
130 * @param size number of bytes available in buf
131 * @param buf where the callee should write the message
132 * @return number of bytes written to buf
133 */
134static size_t
135transmit_is_connected_request (void *cls, size_t size, void *buf)
136{
137 struct GNUNET_CORE_ConnectTestHandle *cth = cls;
138 struct GNUNET_MessageHeader *msg;
139 unsigned int msize;
140
141 cth->th = NULL;
142 msize =
143 sizeof (struct GNUNET_MessageHeader) +
144 sizeof (struct GNUNET_PeerIdentity);
145 if ( (NULL == buf) || (0 == size) )
146 {
147 cth->peer_cb (cth->cb_cls, NULL);
148 GNUNET_CLIENT_disconnect (cth->client);
149 GNUNET_free (cth);
150 return 0;
151 }
152 GNUNET_assert (size >= msize);
153 msg = (struct GNUNET_MessageHeader *) buf;
154 msg->size = htons (msize);
155 msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED);
156 memcpy (&msg[1], &cth->peer, sizeof (struct GNUNET_PeerIdentity));
157 GNUNET_CLIENT_receive (cth->client, &receive_connect_info, cth,
158 GNUNET_TIME_UNIT_FOREVER_REL);
159 return msize;
160}
161
162
163/**
164 * Iterate over all currently connected peers.
165 * Calls peer_cb with each connected peer, and then
166 * once with NULL to indicate that all peers have
167 * been handled.
168 *
169 * @param cfg configuration to use
170 * @param peer the specific peer to check for
171 * @param peer_cb function to call with the peer information
172 * @param cb_cls closure for peer_cb
173 *
174 * @return GNUNET_OK if iterating, GNUNET_SYSERR on error
175 */
176struct GNUNET_CORE_ConnectTestHandle *
177GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg,
178 const struct GNUNET_PeerIdentity *peer,
179 GNUNET_CORE_ConnectEventHandler peer_cb,
180 void *cb_cls)
181{
182 struct GNUNET_CORE_ConnectTestHandle *cth;
183 struct GNUNET_CLIENT_Connection *client;
184
185 GNUNET_assert (NULL != peer);
186 GNUNET_assert (NULL != peer_cb);
187 client = GNUNET_CLIENT_connect ("core", cfg);
188 if (NULL == client)
189 return NULL;
190 cth = GNUNET_malloc (sizeof (struct GNUNET_CORE_ConnectTestHandle));
191 cth->peer = *peer;
192 cth->client = client;
193 cth->peer_cb = peer_cb;
194 cth->cb_cls = cb_cls;
195 cth->th =
196 GNUNET_CLIENT_notify_transmit_ready (client,
197 sizeof (struct GNUNET_MessageHeader) +
198 sizeof (struct GNUNET_PeerIdentity),
199 GNUNET_TIME_UNIT_FOREVER_REL,
200 GNUNET_YES, &transmit_is_connected_request, cth);
201 GNUNET_assert (NULL != cth->th);
202 return cth;
203}
204
205
206/**
207 * Abort 'is_connected' test operation.
208 *
209 * @param cth handle for operation to cancel
210 */
211void
212GNUNET_CORE_is_peer_connected_cancel (struct GNUNET_CORE_ConnectTestHandle *cth)
213{
214 if (NULL != cth->th)
215 {
216 GNUNET_CLIENT_notify_transmit_ready_cancel (cth->th);
217 cth->th = NULL;
218 }
219 GNUNET_CLIENT_disconnect (cth->client);
220 GNUNET_free (cth);
221}
222
223
224/* end of core_api_is_connected.c */
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c
index cc3db6476..4889e638a 100644
--- a/src/core/core_api_iterate_peers.c
+++ b/src/core/core_api_iterate_peers.c
@@ -37,6 +37,7 @@ struct GNUNET_CORE_RequestContext
37 struct GNUNET_CLIENT_Connection *client; 37 struct GNUNET_CLIENT_Connection *client;
38 38
39 /** 39 /**
40
40 * Handle for transmitting a request. 41 * Handle for transmitting a request.
41 */ 42 */
42 struct GNUNET_CLIENT_TransmitHandle *th; 43 struct GNUNET_CLIENT_TransmitHandle *th;
@@ -120,7 +121,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
120 * NULL and "size" zero if the socket was closed for 121 * NULL and "size" zero if the socket was closed for
121 * writing in the meantime. 122 * writing in the meantime.
122 * 123 *
123 * @param cls closure 124 * @param cls closure, always NULL
124 * @param size number of bytes available in buf 125 * @param size number of bytes available in buf
125 * @param buf where the callee should write the message 126 * @param buf where the callee should write the message
126 * @return number of bytes written to buf 127 * @return number of bytes written to buf
@@ -129,32 +130,19 @@ static size_t
129transmit_request (void *cls, size_t size, void *buf) 130transmit_request (void *cls, size_t size, void *buf)
130{ 131{
131 struct GNUNET_MessageHeader *msg; 132 struct GNUNET_MessageHeader *msg;
132 struct GNUNET_PeerIdentity *peer = cls;
133 int msize; 133 int msize;
134 134
135 if (peer == NULL) 135 msize = sizeof (struct GNUNET_MessageHeader);
136 msize = sizeof (struct GNUNET_MessageHeader);
137 else
138 msize =
139 sizeof (struct GNUNET_MessageHeader) +
140 sizeof (struct GNUNET_PeerIdentity);
141 if ((size < msize) || (buf == NULL)) 136 if ((size < msize) || (buf == NULL))
142 return 0; 137 return 0;
143 msg = (struct GNUNET_MessageHeader *) buf; 138 msg = (struct GNUNET_MessageHeader *) buf;
144 msg->size = htons (msize); 139 msg->size = htons (msize);
145 if (peer != NULL) 140 msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS);
146 {
147 msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED);
148 memcpy (&msg[1], peer, sizeof (struct GNUNET_PeerIdentity));
149 }
150 else
151 msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS);
152 141
153 return msize; 142 return msize;
154} 143}
155 144
156 145
157
158/** 146/**
159 * Iterate over all currently connected peers. 147 * Iterate over all currently connected peers.
160 * Calls peer_cb with each connected peer, and then 148 * Calls peer_cb with each connected peer, and then
@@ -163,9 +151,8 @@ transmit_request (void *cls, size_t size, void *buf)
163 * 151 *
164 * @param cfg configuration to use 152 * @param cfg configuration to use
165 * @param peer_cb function to call with the peer information 153 * @param peer_cb function to call with the peer information
166 * @param cb_cls closure for peer_cb 154 * @param cb_cls closure for @a peer_cb
167 * 155 * @return #GNUNET_OK if iterating, #GNUNET_SYSERR on error
168 * @return GNUNET_OK if iterating, GNUNET_SYSERR on error
169 */ 156 */
170int 157int
171GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, 158GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -178,7 +165,7 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
178 client = GNUNET_CLIENT_connect ("core", cfg); 165 client = GNUNET_CLIENT_connect ("core", cfg);
179 if (client == NULL) 166 if (client == NULL)
180 return GNUNET_SYSERR; 167 return GNUNET_SYSERR;
181 request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext)); 168 request_context = GNUNET_new (struct GNUNET_CORE_RequestContext);
182 request_context->client = client; 169 request_context->client = client;
183 request_context->peer_cb = peer_cb; 170 request_context->peer_cb = peer_cb;
184 request_context->cb_cls = cb_cls; 171 request_context->cb_cls = cb_cls;
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c
index eed890a8f..7813a97c1 100644
--- a/src/core/gnunet-service-core_clients.c
+++ b/src/core/gnunet-service-core_clients.c
@@ -829,10 +829,6 @@ GSC_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
829 {&GSC_SESSIONS_handle_client_iterate_peers, NULL, 829 {&GSC_SESSIONS_handle_client_iterate_peers, NULL,
830 GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS, 830 GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS,
831 sizeof (struct GNUNET_MessageHeader)}, 831 sizeof (struct GNUNET_MessageHeader)},
832 {&GSC_SESSIONS_handle_client_have_peer, NULL,
833 GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED,
834 sizeof (struct GNUNET_MessageHeader) +
835 sizeof (struct GNUNET_PeerIdentity)},
836 {&handle_client_send_request, NULL, 832 {&handle_client_send_request, NULL,
837 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST, 833 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
838 sizeof (struct SendMessageRequest)}, 834 sizeof (struct SendMessageRequest)},
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index 161ce81a8..1deb3efc6 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -695,37 +695,6 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls,
695 695
696 696
697/** 697/**
698 * Handle CORE_PEER_CONNECTED request. Notify client about connection
699 * to the given neighbour. For this request type, the client does not
700 * have to have transmitted an INIT request. All current peers are
701 * returned, regardless of which message types they accept.
702 *
703 * @param cls unused
704 * @param client client sending the iteration request
705 * @param message iteration request message
706 */
707void
708GSC_SESSIONS_handle_client_have_peer (void *cls,
709 struct GNUNET_SERVER_Client *client,
710 const struct GNUNET_MessageHeader
711 *message)
712{
713 struct GNUNET_MessageHeader done_msg;
714 struct GNUNET_SERVER_TransmitContext *tc;
715 const struct GNUNET_PeerIdentity *peer;
716
717 peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK!
718 tc = GNUNET_SERVER_transmit_context_create (client);
719 GNUNET_CONTAINER_multihashmap_get_multiple (sessions, &peer->hashPubKey,
720 &queue_connect_message, tc);
721 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
722 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
723 GNUNET_SERVER_transmit_context_append_message (tc, &done_msg);
724 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
725}
726
727
728/**
729 * We've received a typemap message from a peer, update ours. 698 * We've received a typemap message from a peer, update ours.
730 * Notifies clients about the session. 699 * Notifies clients about the session.
731 * 700 *
diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h
index e09cf500e..d578e3d72 100644
--- a/src/core/gnunet-service-core_sessions.h
+++ b/src/core/gnunet-service-core_sessions.h
@@ -157,24 +157,6 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls,
157 157
158 158
159/** 159/**
160 * Handle CORE_PEER_CONNECTED request. Notify client about connection
161 * to the given neighbour. For this request type, the client does not
162 * have to have transmitted an INIT request. All current peers are
163 * returned, regardless of which message types they accept.
164 *
165 * @param cls unused
166 * @param client client sending the iteration request
167 * @param message iteration request message
168 */
169void
170GSC_SESSIONS_handle_client_have_peer (void *cls,
171 struct GNUNET_SERVER_Client *client,
172 const struct GNUNET_MessageHeader
173 *message);
174
175
176
177/**
178 * Initialize sessions subsystem. 160 * Initialize sessions subsystem.
179 */ 161 */
180void 162void