This file is part of GNUnet.
Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file transport-testing.c
*
* @param p1 first peer
* @param p2 second peer
- * @param cb function to call
+ * @param cb function to call
* @param cb_cls closure for @a cb
*/
void
{
ccn = cc->next;
if ( (cc->p1 == p1) &&
- (cc->p2 == p2) )
+ (cc->p2 == p2) )
cb (cb_cls,
cc);
}
static void
-set_p1c (void *cls,
+set_p1c (void *cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
{
+ int *found = cls;
+
+ if (NULL != found)
+ *found = GNUNET_YES;
cx->p1_c = GNUNET_YES;
}
static void
-set_p2c (void *cls,
+set_mq (void *cls,
+ struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
+{
+ struct GNUNET_MQ_Handle *mq = cls;
+
+ cx->mq = mq;
+}
+
+
+static void
+set_p2c (void *cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
{
+ int *found = cls;
+
+ if (NULL != found)
+ *found = GNUNET_YES;
cx->p2_c = GNUNET_YES;
}
static void
-clear_p1c (void *cls,
+clear_p1c (void *cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
{
+ int *found = cls;
+
+ if (NULL != found)
+ *found = GNUNET_YES;
cx->p1_c = GNUNET_NO;
}
static void
-clear_p2c (void *cls,
+clear_p2c (void *cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
{
+ int *found = cls;
+
+ if (NULL != found)
+ *found = GNUNET_YES;
cx->p2_c = GNUNET_NO;
}
-static void
+static void *
notify_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
+ int found;
+ void *ret;
p2 = find_peer_context (p->tth,
peer);
if (NULL != p->nc)
- p->nc (p->cb_cls,
- peer);
+ ret = p->nc (p->cb_cls,
+ peer,
+ mq);
+ else
+ ret = NULL;
- if (p2 != NULL)
+ if (NULL != p2)
GNUNET_asprintf (&p2_s,
"%u (`%s')",
p2->no,
GNUNET_i2s (&p->id));
GNUNET_free (p2_s);
/* update flags in connecting contexts */
+ found = GNUNET_NO;
GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
p2,
&set_p1c,
- NULL);
+ &found);
+ if (GNUNET_NO == found)
+ {
+ cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
+ cc->p1 = p;
+ cc->p2 = p2;
+ cc->p1_c = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (tth->cc_head,
+ tth->cc_tail,
+ cc);
+ }
+ found = GNUNET_NO;
GNUNET_TRANSPORT_TESTING_find_connecting_context (p2,
p,
&set_p2c,
- NULL);
+ &found);
+ if (GNUNET_NO == found)
+ {
+ cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
+ cc->p1 = p2;
+ cc->p2 = p;
+ cc->p1_c = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (tth->cc_head,
+ tth->cc_tail,
+ cc);
+ }
+ GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
+ p2,
+ &set_mq,
+ mq);
/* update set connected flag for all requests */
for (cc = tth->cc_head; NULL != cc; cc = cc->next)
{
cc->cb = NULL; /* only notify once! */
}
}
+ return ret;
}
static void
notify_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ void *handler_cls)
{
struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
/* Find PeerContext */
int no = 0;
struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
- struct TRANSPORT_TESTING_SendJob *sj;
- struct TRANSPORT_TESTING_SendJob *sjn;
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
-
+
p2 = find_peer_context (p->tth,
peer);
no = p->no;
/* notify about disconnect */
if (NULL != p->nd)
p->nd (p->cb_cls,
- peer);
+ peer,
+ handler_cls);
if (NULL == p2)
return;
- /* abort all transmissions this disconnected pair is involved in */
- for (sj = tth->sj_head; NULL != sj; sj = sjn)
- {
- sjn = sj->next;
- if ( ( (sj->sender == p2) &&
- (sj->receiver == p) ) ||
- ( (sj->receiver == p2) &&
- (sj->sender == p) ) )
- {
- GNUNET_CONTAINER_DLL_remove (tth->sj_head,
- tth->sj_tail,
- sj);
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (sj->th);
- GNUNET_free (sj);
- }
- }
+ /* clear MQ, it is now invalid */
+ GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
+ p2,
+ &set_mq,
+ NULL);
/* update set connected flags for all requests */
GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
p2,
}
-static void
-notify_receive (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
-{
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
- if (NULL == p)
- return;
- if (NULL != p->rec)
- p->rec (p->cb_cls,
- peer,
- message);
-}
-
-
static void
get_hello (void *cb_cls,
const struct GNUNET_MessageHeader *message)
"Peer %u (`%s') successfully started\n",
p->no,
GNUNET_i2s (&p->id));
- p->start_cb (p,
- p->start_cb_cls);
+ p->start_cb (p->start_cb_cls);
p->start_cb = NULL;
}
}
* @param tth the testing handle
* @param cfgname configuration file
* @param peer_id a unique number to identify the peer
- * @param rec receive callback
+ * @param handlers functions for receiving messages
* @param nc connect callback
* @param nd disconnect callback
* @param cb_cls closure for callback
GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
const char *cfgname,
int peer_id,
- GNUNET_TRANSPORT_ReceiveCallback rec,
- GNUNET_TRANSPORT_NotifyConnect nc,
- GNUNET_TRANSPORT_NotifyDisconnect nd,
+ const struct GNUNET_MQ_MessageHandler *handlers,
+ GNUNET_TRANSPORT_NotifyConnecT nc,
+ GNUNET_TRANSPORT_NotifyDisconnecT nd,
void *cb_cls,
- GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
+ GNUNET_SCHEDULER_TaskCallback start_cb,
void *start_cb_cls)
{
char *emsg = NULL;
struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
- struct GNUNET_PeerIdentity *dummy;
+ struct GNUNET_PeerIdentity dummy;
+ unsigned int i;
if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
{
p->tth = tth;
p->nc = nc;
p->nd = nd;
- p->rec = rec;
+ if (NULL != handlers)
+ {
+ for (i=0;NULL != handlers[i].cb;i++) ;
+ p->handlers = GNUNET_new_array (i + 1,
+ struct GNUNET_MQ_MessageHandler);
+ GNUNET_memcpy (p->handlers,
+ handlers,
+ i * sizeof (struct GNUNET_MQ_MessageHandler));
+ }
if (NULL != cb_cls)
p->cb_cls = cb_cls;
else
p->cb_cls = p;
p->start_cb = start_cb;
- p->start_cb_cls = start_cb_cls;
+ if (NULL != start_cb_cls)
+ p->start_cb_cls = start_cb_cls;
+ else
+ p->start_cb_cls = p;
GNUNET_CONTAINER_DLL_insert (tth->p_head,
tth->p_tail,
p);
"Peer %u configured with identity `%s'\n",
p->no,
GNUNET_i2s_full (&p->id));
-
- p->th = GNUNET_TRANSPORT_connect (p->cfg,
- NULL,
- p,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect);
- if (NULL == p->th)
+ p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg);
+ p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
+ NULL,
+ handlers,
+ p,
+ ¬ify_connect,
+ ¬ify_disconnect,
+ NULL);
+ if ( (NULL == p->th) ||
+ (NULL == p->tmh) )
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Failed to connect to transport service for peer `%s': `%s'\n",
GNUNET_TRANSPORT_TESTING_stop_peer (p);
return NULL;
}
- p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg,
- &get_hello,
+ p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
+ GNUNET_TRANSPORT_AC_ANY,
+ &get_hello,
p);
- GNUNET_assert (p->ghh != NULL);
+ GNUNET_assert (NULL != p->ghh);
return p;
}
*/
int
GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
- GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
+ GNUNET_SCHEDULER_TaskCallback restart_cb,
void *restart_cb_cls)
{
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
-
+
/* shutdown */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Stopping peer %u (`%s')\n",
GNUNET_i2s (&p->id));
if (NULL != p->ghh)
{
- GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
+ GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
p->ghh = NULL;
}
if (NULL != p->th)
{
- GNUNET_TRANSPORT_disconnect (p->th);
+ GNUNET_TRANSPORT_core_disconnect (p->th);
p->th = NULL;
}
+ if (NULL != p->tmh)
+ {
+ GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
+ p->tmh = NULL;
+ }
for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
{
ccn = cc->next;
p->start_cb = restart_cb;
p->start_cb_cls = restart_cb_cls;
- p->th = GNUNET_TRANSPORT_connect (p->cfg,
- NULL,
- p,
- ¬ify_receive,
- ¬ify_connect,
- ¬ify_disconnect);
+ p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
+ NULL,
+ p->handlers,
+ p,
+ ¬ify_connect,
+ ¬ify_disconnect,
+ NULL);
GNUNET_assert (NULL != p->th);
p->ats = GNUNET_ATS_connectivity_init (p->cfg);
- p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg,
+ p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
+ GNUNET_TRANSPORT_AC_ANY,
&get_hello,
p);
GNUNET_assert (NULL != p->ghh);
}
if (NULL != p->ghh)
{
- GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
+ GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
p->ghh = NULL;
}
+ if (NULL != p->tmh)
+ {
+ GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
+ p->tmh = NULL;
+ }
if (NULL != p->th)
{
- GNUNET_TRANSPORT_disconnect (p->th);
+ GNUNET_TRANSPORT_core_disconnect (p->th);
p->th = NULL;
}
if (NULL != p->peer)
GNUNET_CONFIGURATION_destroy (p->cfg);
p->cfg = NULL;
}
+ if (NULL != p->handlers)
+ {
+ GNUNET_free (p->handlers);
+ p->handlers = NULL;
+ }
GNUNET_CONTAINER_DLL_remove (tth->p_head,
tth->p_tail,
p);
{
struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
+ struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
+
+ ccn = NULL;
+ for (cc = tth->cc_head; NULL != cc; cc = cc->next)
+ {
+ if ( (cc->p1 == p1) &&
+ (cc->p2 == p2) )
+ {
+ ccn = cc;
+ break;
+ }
+ }
cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
cc->p1 = p1;
cc->cb_cls = cls;
else
cc->cb_cls = cc;
+ if (NULL != ccn)
+ {
+ cc->p1_c = ccn->p1_c;
+ cc->p2_c = ccn->p2_c;
+ cc->connected = ccn->connected;
+ }
GNUNET_CONTAINER_DLL_insert (tth->cc_head,
tth->cc_tail,
cc);