aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-03-27 16:51:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-03-27 16:51:32 +0000
commit25fea659b134e2716aa95edc8f6267603e08ce61 (patch)
treefe0eb5a7fdaca512c833f930486942d688e6cfd7 /src/transport/transport_api.c
parent075f1356987b48d3afd3f5c01ddebe23fa0ae240 (diff)
downloadgnunet-25fea659b134e2716aa95edc8f6267603e08ce61.tar.gz
gnunet-25fea659b134e2716aa95edc8f6267603e08ce61.zip
added functionality to use the CLI to disconnect peers
fixed DISCONNECT functionality
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r--src/transport/transport_api.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index c6ee3e47d..27a281afd 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -203,6 +203,8 @@ struct GNUNET_TRANSPORT_TryConnectHandle
203 203
204 GNUNET_TRANSPORT_TryConnectCallback cb; 204 GNUNET_TRANSPORT_TryConnectCallback cb;
205 205
206 int connect;
207
206 /** 208 /**
207 * Closure for @e cb. 209 * Closure for @e cb.
208 */ 210 */
@@ -1166,7 +1168,7 @@ send_try_connect (void *cls, size_t size, void *buf)
1166 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); 1168 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1167 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); 1169 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
1168 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT); 1170 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT);
1169 msg.reserved = htonl (0); 1171 msg.connect = htonl (tch->connect);
1170 msg.peer = tch->pid; 1172 msg.peer = tch->pid;
1171 memcpy (buf, &msg, sizeof (msg)); 1173 memcpy (buf, &msg, sizeof (msg));
1172 if (NULL != tch->cb) 1174 if (NULL != tch->cb)
@@ -1203,6 +1205,7 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1203 tch->pid = *(target); 1205 tch->pid = *(target);
1204 tch->cb = cb; 1206 tch->cb = cb;
1205 tch->cb_cls = cb_cls; 1207 tch->cb_cls = cb_cls;
1208 tch->connect = GNUNET_YES;
1206 tch->tth = schedule_control_transmit (handle, 1209 tch->tth = schedule_control_transmit (handle,
1207 sizeof (struct TransportRequestConnectMessage), 1210 sizeof (struct TransportRequestConnectMessage),
1208 &send_try_connect, tch); 1211 &send_try_connect, tch);
@@ -1221,6 +1224,7 @@ void
1221GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch) 1224GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch)
1222{ 1225{
1223 struct GNUNET_TRANSPORT_Handle *th; 1226 struct GNUNET_TRANSPORT_Handle *th;
1227 GNUNET_assert (GNUNET_YES == tch->connect);
1224 1228
1225 th = tch->th; 1229 th = tch->th;
1226 cancel_control_transmit (th, tch->tth); 1230 cancel_control_transmit (th, tch->tth);
@@ -1228,6 +1232,62 @@ GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *t
1228 GNUNET_free (tch); 1232 GNUNET_free (tch);
1229} 1233}
1230 1234
1235/**
1236 * Ask the transport service to shutdown a connection to
1237 * the given peer.
1238 *
1239 * @param handle connection to transport service
1240 * @param target who we should try to connect to
1241 * @param cb callback to be called when request was transmitted to transport
1242 * service
1243 * @param cb_cls closure for the callback
1244 * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
1245 * NULL on failure (cb will not be called)
1246 */
1247struct GNUNET_TRANSPORT_TryConnectHandle *
1248GNUNET_TRANSPORT_try_disconnect (struct GNUNET_TRANSPORT_Handle *handle,
1249 const struct GNUNET_PeerIdentity *target,
1250 GNUNET_TRANSPORT_TryConnectCallback cb,
1251 void *cb_cls)
1252{
1253 struct GNUNET_TRANSPORT_TryConnectHandle *tch = NULL;
1254
1255 if (NULL == handle->client)
1256 return NULL;
1257 tch = GNUNET_new (struct GNUNET_TRANSPORT_TryConnectHandle);
1258 tch->th = handle;
1259 tch->pid = *(target);
1260 tch->cb = cb;
1261 tch->cb_cls = cb_cls;
1262 tch->connect = GNUNET_NO;
1263 tch->tth = schedule_control_transmit (handle,
1264 sizeof (struct TransportRequestConnectMessage),
1265 &send_try_connect, tch);
1266 GNUNET_CONTAINER_DLL_insert(handle->tc_head, handle->tc_tail, tch);
1267 return tch;
1268}
1269
1270
1271/**
1272 * Cancel the request to transport to try a disconnect
1273 * Callback will not be called
1274 *
1275 * @param tch the handle to cancel
1276 */
1277void
1278GNUNET_TRANSPORT_try_disconnect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch)
1279{
1280 struct GNUNET_TRANSPORT_Handle *th;
1281 GNUNET_assert (GNUNET_NO == tch->connect);
1282
1283 th = tch->th;
1284 cancel_control_transmit (th, tch->tth);
1285 GNUNET_CONTAINER_DLL_remove (th->tc_head, th->tc_tail, tch);
1286 GNUNET_free (tch);
1287}
1288
1289
1290
1231 1291
1232/** 1292/**
1233 * Send HELLO message to the service. 1293 * Send HELLO message to the service.