#define CLIENT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
-/**
+/**
* Handle for a mesh to another peer.
*/
struct MeshHandle;
};
-/**
+/**
* Handle for a mesh to another peer.
*/
struct MeshHandle
/**
* Handle for active write operation, or NULL.
- */
+ */
struct GNUNET_MESH_TransmitHandle *wh;
/**
* Which peer does this mesh go to?
- */
+ */
struct GNUNET_PeerIdentity target;
/**
/**
* Mesh tunnel for creating outbound tunnels.
*/
-static struct GNUNET_MESH_Handle *mesh_tunnel;
+static struct GNUNET_MESH_Handle *mesh_handle;
/**
* Map from peer identities to 'struct MeshHandles' with mesh
* tunnels to those peers.
*/
-static struct GNUNET_CONTAINER_MultiHashMap *mesh_map;
+static struct GNUNET_CONTAINER_MultiPeerMap *mesh_map;
/* ********************* client-side code ************************* */
/**
- * Iterator called on each entry in a waiting map to
+ * Iterator called on each entry in a waiting map to
* move it back to the pending list.
*
* @param cls the 'struct MeshHandle'
{
struct MeshHandle *mh = cls;
struct GSF_MeshRequest *sr = value;
-
+
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map,
key,
GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map,
&move_to_pending,
mh);
- mh->tunnel = GNUNET_MESH_tunnel_create (mesh_tunnel,
- mh,
- &mh->target,
- GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
- GNUNET_YES,
- GNUNET_YES);
+ mh->tunnel = GNUNET_MESH_tunnel_create (mesh_handle,
+ mh,
+ &mh->target,
+ GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
+ GNUNET_NO,
+ GNUNET_YES);
+ transmit_pending (mh);
}
mh->wh = NULL;
if (NULL == buf)
{
- reset_mesh (mh);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Mesh tunnel to %s failed during transmission attempt, rebuilding\n",
+ GNUNET_i2s (&mh->target));
+ reset_mesh_async (mh);
return 0;
}
sr = mh->pending_head;
transmit_pending (mh);
return sizeof (sqm);
}
-
+
/**
* Transmit pending requests via the mesh.
static void
transmit_pending (struct MeshHandle *mh)
{
+ if (NULL == mh->tunnel)
+ return;
if (NULL != mh->wh)
return;
mh->wh = GNUNET_MESH_notify_transmit_ready (mh->tunnel, GNUNET_YES /* allow cork */,
/**
* Reply payload.
- */
+ */
const void *data;
/**
*/
size_t data_size;
- /**
+ /**
* Type of the block.
*/
enum GNUNET_BLOCK_Type type;
-
+
/**
* Did we have a matching query?
*/
/**
- * Iterator called on each entry in a waiting map to
+ * Iterator called on each entry in a waiting map to
* process a result.
*
* @param cls the 'struct HandleReplyClosure'
{
struct HandleReplyClosure *hrc = cls;
struct GSF_MeshRequest *sr = value;
-
+
sr->proc (sr->proc_cls,
hrc->type,
hrc->expiration,
type,
&srm[1], msize, &query))
{
- GNUNET_break_op (0);
+ GNUNET_break_op (0);
reset_mesh_async (mh);
return GNUNET_SYSERR;
}
"Received reply `%s' via mesh from peer %s\n",
GNUNET_h2s (&query),
GNUNET_i2s (&mh->target));
+ GNUNET_MESH_receive_done (tunnel);
GNUNET_STATISTICS_update (GSF_stats,
gettext_noop ("# replies received via mesh"), 1,
GNUNET_NO);
{
struct MeshHandle *mh;
- mh = GNUNET_CONTAINER_multihashmap_get (mesh_map,
- &target->hashPubKey);
+ mh = GNUNET_CONTAINER_multipeermap_get (mesh_map,
+ target);
if (NULL != mh)
{
if (GNUNET_SCHEDULER_NO_TASK != mh->timeout_task)
mh);
mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
mh->target = *target;
- mh->tunnel = GNUNET_MESH_tunnel_create (mesh_tunnel,
- mh,
- &mh->target,
- GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
- GNUNET_NO,
- GNUNET_YES);
+ mh->tunnel = GNUNET_MESH_tunnel_create (mesh_handle,
+ mh,
+ &mh->target,
+ GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
+ GNUNET_NO,
+ GNUNET_YES);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (mesh_map,
- &mh->target.hashPubKey,
+ GNUNET_CONTAINER_multipeermap_put (mesh_map,
+ &mh->target,
mh,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return mh;
/**
- * Iterator called on each entry in a waiting map to
+ * Iterator called on each entry in a waiting map to
* call the 'proc' continuation and release associated
* resources.
*
*
* @param cls NULL
* @param tunnel tunnel of the disconnecting client
- * @param tunnel_ctx our 'struct MeshClient'
+ * @param tunnel_ctx our 'struct MeshClient'
*/
static void
cleaner_cb (void *cls,
if (GNUNET_SCHEDULER_NO_TASK != mh->reset_task)
GNUNET_SCHEDULER_cancel (mh->reset_task);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (mesh_map,
- &mh->target.hashPubKey,
+ GNUNET_CONTAINER_multipeermap_remove (mesh_map,
+ &mh->target,
mh));
GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map);
GNUNET_free (mh);
{ &reply_cb, GNUNET_MESSAGE_TYPE_FS_MESH_REPLY, 0 },
{ NULL, 0, 0 }
};
- static const uint32_t ports[] = {
- GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
- 0
- };
- mesh_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
- mesh_tunnel = GNUNET_MESH_connect (GSF_cfg,
- NULL,
- NULL,
- &cleaner_cb,
- handlers,
- ports);
+ mesh_map = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
+ mesh_handle = GNUNET_MESH_connect (GSF_cfg,
+ NULL,
+ NULL,
+ &cleaner_cb,
+ handlers,
+ NULL);
}
*/
static int
release_meshs (void *cls,
- const struct GNUNET_HashCode *key,
+ const struct GNUNET_PeerIdentity *key,
void *value)
{
struct MeshHandle *mh = value;
void
GSF_mesh_stop_client ()
{
- GNUNET_CONTAINER_multihashmap_iterate (mesh_map,
+ GNUNET_CONTAINER_multipeermap_iterate (mesh_map,
&release_meshs,
NULL);
- GNUNET_CONTAINER_multihashmap_destroy (mesh_map);
+ GNUNET_CONTAINER_multipeermap_destroy (mesh_map);
mesh_map = NULL;
- if (NULL != mesh_tunnel)
+ if (NULL != mesh_handle)
{
- GNUNET_MESH_disconnect (mesh_tunnel);
- mesh_tunnel = NULL;
+ GNUNET_MESH_disconnect (mesh_handle);
+ mesh_handle = NULL;
}
}