/**
* Set a peer flag of given peer context.
*/
-#define set_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask))
+#define SET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask))
/**
* Get peer flag of given peer context.
/**
* Unset flag of given peer context.
*/
-#define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask))
+#define UNSET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask))
/**
* Get channel flag of given channel context.
* #GNUNET_NO if peer is not knwon
*/
static int
-Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer)
+check_peer_known (const struct GNUNET_PeerIdentity *peer)
{
if (NULL != peer_map)
{
struct PeerContext *ctx;
int ret;
- GNUNET_assert (GNUNET_NO == Peers_check_peer_known (peer));
+ GNUNET_assert (GNUNET_NO == check_peer_known (peer));
ctx = GNUNET_new (struct PeerContext);
ctx->peer_id = *peer;
static struct PeerContext *
create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
{
- if (GNUNET_NO == Peers_check_peer_known (peer))
+ if (GNUNET_NO == check_peer_known (peer))
{
return create_peer_ctx (peer);
}
}
-/**
- * @brief unset flags on a given peer.
- *
- * @param peer the peer to unset flags on
- * @param flags the flags
- */
-static void
-Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
-{
- struct PeerContext *peer_ctx;
-
- peer_ctx = get_peer_ctx (peer);
- unset_peer_flag (peer_ctx, flags);
-}
-
-
-/**
- * @brief set flags on a given peer.
- *
- * @param peer the peer to set flags on
- * @param flags the flags
- */
-static void
-Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
-{
- struct PeerContext *peer_ctx;
-
- peer_ctx = get_peer_ctx (peer);
- set_peer_flag (peer_ctx, flags);
-}
-
/**
* @brief Check whether we have a connection to this @a peer
*
* #GNUNET_NO otherwise
*/
static int
-Peers_check_connected (const struct GNUNET_PeerIdentity *peer)
+check_connected (const struct GNUNET_PeerIdentity *peer)
{
- const struct PeerContext *peer_ctx;
+ struct PeerContext *peer_ctx;
/* If we don't know about this peer we don't know whether it's online */
- if (GNUNET_NO == Peers_check_peer_known (peer))
+ if (GNUNET_NO == check_peer_known (peer))
{
return GNUNET_NO;
}
if ( (NULL == peer_ctx->send_channel_ctx) &&
(NULL == peer_ctx->recv_channel_ctx) )
{
- Peers_unset_peer_flag (peer, Peers_ONLINE);
+ UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
return GNUNET_NO;
}
/* Otherwise (if we have a channel, we know that it's online */
- Peers_set_peer_flag (peer, Peers_ONLINE);
+ SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
return GNUNET_YES;
}
}
(void) add_valid_peer (peer);
- set_peer_flag (peer_ctx, Peers_ONLINE);
+ SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
/* Call pending operations */
for (i = 0; i < peer_ctx->num_pending_ops; i++)
* @return The channel context
*/
static struct ChannelCtx *
-add_channel_ctx (struct PeerContext *peer_ctx);
+add_channel_ctx (struct PeerContext *peer_ctx)
+{
+ struct ChannelCtx *channel_ctx;
+ channel_ctx = GNUNET_new (struct ChannelCtx);
+ channel_ctx->peer_ctx = peer_ctx;
+ return channel_ctx;
+}
+
/**
* @brief Remove the channel context from the DLL and free the memory.
* @param channel_ctx The channel context.
*/
static void
-remove_channel_ctx (struct ChannelCtx *channel_ctx);
+remove_channel_ctx (struct ChannelCtx *channel_ctx)
+{
+ struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
+
+ if (channel_ctx == peer_ctx->send_channel_ctx)
+ {
+ GNUNET_free (channel_ctx);
+ peer_ctx->send_channel_ctx = NULL;
+ peer_ctx->mq = NULL;
+ }
+ else if (channel_ctx == peer_ctx->recv_channel_ctx)
+ {
+ GNUNET_free (channel_ctx);
+ peer_ctx->recv_channel_ctx = NULL;
+ }
+ else
+ {
+ GNUNET_assert (0);
+ }
+}
/**
return GNUNET_NO;
}
+/**
+ * @brief Callback for scheduler to destroy a channel
+ *
+ * @param cls Context of the channel
+ */
+static void
+destroy_channel (struct ChannelCtx *channel_ctx)
+{
+ struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
+
+ GNUNET_assert (channel_ctx == peer_ctx->send_channel_ctx ||
+ channel_ctx == peer_ctx->recv_channel_ctx);
+
+ GNUNET_CADET_channel_destroy (channel_ctx->channel);
+ remove_channel_ctx (channel_ctx);
+}
+
+
+/**
+ * @brief Remove peer
+ *
+ * @param peer the peer to clean
+ * @return #GNUNET_YES if peer was removed
+ * #GNUNET_NO otherwise
+ */
static int
-Peers_remove_peer (const struct GNUNET_PeerIdentity *peer);
+destroy_peer (struct PeerContext *peer_ctx)
+{
+ GNUNET_assert (NULL != peer_ctx);
+ GNUNET_assert (NULL != peer_map);
+ if (GNUNET_NO ==
+ GNUNET_CONTAINER_multipeermap_contains (peer_map,
+ &peer_ctx->peer_id))
+ {
+ return GNUNET_NO;
+ }
+ SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Going to remove peer %s\n",
+ GNUNET_i2s (&peer_ctx->peer_id));
+ UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
+
+ /* Clear list of pending operations */
+ // TODO this probably leaks memory
+ // ('only' the cls to the function. Not sure what to do with it)
+ GNUNET_array_grow (peer_ctx->pending_ops,
+ peer_ctx->num_pending_ops,
+ 0);
+ /* Remove all pending messages */
+ while (NULL != peer_ctx->pending_messages_head)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing unsent %s\n",
+ peer_ctx->pending_messages_head->type);
+ /* Cancle pending message, too */
+ if ( (NULL != peer_ctx->liveliness_check_pending) &&
+ (0 == memcmp (peer_ctx->pending_messages_head,
+ peer_ctx->liveliness_check_pending,
+ sizeof (struct PendingMessage))) )
+ {
+ // TODO this may leak memory
+ peer_ctx->liveliness_check_pending = NULL;
+ }
+ remove_pending_message (peer_ctx->pending_messages_head,
+ GNUNET_YES);
+ }
+
+ /* If we are still waiting for notification whether this peer is live
+ * cancel the according task */
+ if (NULL != peer_ctx->liveliness_check_pending)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing pending liveliness check for peer %s\n",
+ GNUNET_i2s (&peer_ctx->peer_id));
+ // TODO wait until cadet sets mq->cancel_impl
+ //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
+ remove_pending_message (peer_ctx->liveliness_check_pending,
+ GNUNET_YES);
+ peer_ctx->liveliness_check_pending = NULL;
+ }
+
+ if (NULL != peer_ctx->send_channel_ctx)
+ {
+ destroy_channel (peer_ctx->send_channel_ctx);
+ }
+ if (NULL != peer_ctx->recv_channel_ctx)
+ {
+ destroy_channel (peer_ctx->recv_channel_ctx);
+ }
+
+ if (GNUNET_YES !=
+ GNUNET_CONTAINER_multipeermap_remove_all (peer_map,
+ &peer_ctx->peer_id))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "removing peer from peer_map failed\n");
+ }
+ GNUNET_free (peer_ctx);
+ return GNUNET_YES;
+}
+
/**
* Iterator over hash map entries. Deletes all contexts of peers.
const struct GNUNET_PeerIdentity *key,
void *value)
{
- Peers_remove_peer (key);
+ destroy_peer (get_peer_ctx (key));
return GNUNET_YES;
}
* @param own_id own peer identity
*/
static void
-Peers_initialise (char* fn_valid_peers,
+initialise_peers (char* fn_valid_peers,
struct GNUNET_CADET_Handle *cadet_h)
{
filename_valid_peers = GNUNET_strdup (fn_valid_peers);
/**
- * @brief Delete storage of peers that was created with #Peers_initialise ()
+ * @brief Delete storage of peers that was created with #initialise_peers ()
*/
static void
peers_terminate ()
* #GNUNET_SYSERR if it aborted iteration
*/
static int
-Peers_get_valid_peers (PeersIterator iterator,
- void *it_cls)
+get_valid_peers (PeersIterator iterator,
+ void *it_cls)
{
struct PeersIteratorCls *cls;
int ret;
* #GNUNET_NO otherwise
*/
static int
-Peers_insert_peer (const struct GNUNET_PeerIdentity *peer)
+insert_peer (const struct GNUNET_PeerIdentity *peer)
{
- if (GNUNET_YES == Peers_check_peer_known (peer))
+ if (GNUNET_YES == check_peer_known (peer))
{
return GNUNET_NO; /* We already know this peer - nothing to do */
}
return GNUNET_YES;
}
+
+/**
+ * @brief Check whether flags on a peer are set.
+ *
+ * @param peer the peer to check the flag of
+ * @param flags the flags to check
+ *
+ * @return #GNUNET_SYSERR if peer is not known
+ * #GNUNET_YES if all given flags are set
+ * #GNUNET_NO otherwise
+ */
static int
-Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
+check_peer_flag (const struct GNUNET_PeerIdentity *peer,
+ enum Peers_PeerFlags flags)
+{
+ struct PeerContext *peer_ctx;
+
+ if (GNUNET_NO == check_peer_known (peer))
+ {
+ return GNUNET_SYSERR;
+ }
+ peer_ctx = get_peer_ctx (peer);
+ return check_peer_flag_set (peer_ctx, flags);
+}
/**
* @brief Try connecting to a peer to see whether it is online
* #GNUNET_NO otherwise
*/
static int
-Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
+issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *peer_ctx;
int ret;
- ret = Peers_insert_peer (peer);
+ ret = insert_peer (peer);
peer_ctx = get_peer_ctx (peer);
- if ( (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) &&
+ if ( (GNUNET_NO == check_peer_flag (peer, Peers_ONLINE)) &&
(NULL == peer_ctx->liveliness_check_pending) )
{
check_peer_live (peer_ctx);
* #GNUNET_SYSERR if peer is not known
*/
static int
-Peers_check_removable (const struct GNUNET_PeerIdentity *peer)
+check_removable (const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *peer_ctx;
return GNUNET_YES;
}
-static uint32_t *
-Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
- enum Peers_ChannelRole role);
-
-static int
-Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
-
-/**
- * @brief Callback for the scheduler to destroy the knowledge of a peer.
- *
- * @param cls Context of the peer
- */
-static void
-destroy_peer (void *cls)
-{
- struct PeerContext *peer_ctx = cls;
-
- GNUNET_assert (NULL != peer_ctx);
- Peers_remove_peer (&peer_ctx->peer_id);
-}
-
-
-/**
- * @brief Callback for scheduler to destroy a channel
- *
- * @param cls Context of the channel
- */
-static void
-destroy_channel (void *cls)
-{
- struct ChannelCtx *channel_ctx = cls;
- struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
-
- GNUNET_assert (channel_ctx == peer_ctx->send_channel_ctx ||
- channel_ctx == peer_ctx->recv_channel_ctx);
-
- GNUNET_CADET_channel_destroy (channel_ctx->channel);
- remove_channel_ctx (peer_ctx->send_channel_ctx);
-}
-
-
-/**
- * @brief Remove peer
- *
- * @param peer the peer to clean
- * @return #GNUNET_YES if peer was removed
- * #GNUNET_NO otherwise
- */
-static int
-Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
-{
- struct PeerContext *peer_ctx;
-
- GNUNET_assert (NULL != peer_map);
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multipeermap_contains (peer_map,
- peer))
- {
- return GNUNET_NO;
- }
- peer_ctx = get_peer_ctx (peer);
- set_peer_flag (peer_ctx, Peers_TO_DESTROY);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Going to remove peer %s\n",
- GNUNET_i2s (&peer_ctx->peer_id));
- Peers_unset_peer_flag (peer, Peers_ONLINE);
-
- /* Clear list of pending operations */
- // TODO this probably leaks memory
- // ('only' the cls to the function. Not sure what to do with it)
- GNUNET_array_grow (peer_ctx->pending_ops,
- peer_ctx->num_pending_ops,
- 0);
- /* Remove all pending messages */
- while (NULL != peer_ctx->pending_messages_head)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Removing unsent %s\n",
- peer_ctx->pending_messages_head->type);
- /* Cancle pending message, too */
- if ( (NULL != peer_ctx->liveliness_check_pending) &&
- (0 == memcmp (peer_ctx->pending_messages_head,
- peer_ctx->liveliness_check_pending,
- sizeof (struct PendingMessage))) )
- {
- // TODO this may leak memory
- peer_ctx->liveliness_check_pending = NULL;
- }
- remove_pending_message (peer_ctx->pending_messages_head,
- GNUNET_YES);
- }
-
- /* If we are still waiting for notification whether this peer is live
- * cancel the according task */
- if (NULL != peer_ctx->liveliness_check_pending)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing pending liveliness check for peer %s\n",
- GNUNET_i2s (&peer_ctx->peer_id));
- // TODO wait until cadet sets mq->cancel_impl
- //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
- remove_pending_message (peer_ctx->liveliness_check_pending,
- GNUNET_YES);
- peer_ctx->liveliness_check_pending = NULL;
- }
-
-
- /* Do we still have to wait for destruction of channels
- * or issue the destruction? */
- if (NULL != peer_ctx->send_channel_ctx)
- {
- destroy_channel (peer_ctx->send_channel_ctx);
- return GNUNET_NO;
- }
- if (NULL != peer_ctx->recv_channel_ctx)
- {
- destroy_channel (peer_ctx->recv_channel_ctx);
- return GNUNET_NO;
- }
- destroy_peer (peer_ctx);
-
- if (GNUNET_YES !=
- GNUNET_CONTAINER_multipeermap_remove_all (peer_map,
- &peer_ctx->peer_id))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "removing peer from peer_map failed\n");
- }
- GNUNET_free (peer_ctx);
- return GNUNET_YES;
-}
-
-
-/**
- * @brief Check whether flags on a peer are set.
- *
- * @param peer the peer to check the flag of
- * @param flags the flags to check
- *
- * @return #GNUNET_SYSERR if peer is not known
- * #GNUNET_YES if all given flags are set
- * #GNUNET_NO otherwise
- */
-static int
-Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
-{
- struct PeerContext *peer_ctx;
-
- if (GNUNET_NO == Peers_check_peer_known (peer))
- {
- return GNUNET_SYSERR;
- }
- peer_ctx = get_peer_ctx (peer);
- return check_peer_flag_set (peer_ctx, flags);
-}
-
/**
* @brief Check whether @a peer is actually a peer.
* #GNUNET_NO if peer is not valid
*/
static int
-Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer)
+check_peer_valid (const struct GNUNET_PeerIdentity *peer)
{
return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
}
* @param peer the peer to establish channel to
*/
static void
-Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
+indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
+ GNUNET_assert (GNUNET_YES == check_peer_known (peer));
(void) get_channel (peer);
}
* #GNUNET_NO otherwise
*/
static int
-Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
+check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
{
const struct PeerContext *peer_ctx;
* (can be NULL -- that's not an error)
*/
static void *
-Peers_handle_inbound_channel (void *cls,
- struct GNUNET_CADET_Channel *channel,
- const struct GNUNET_PeerIdentity *initiator)
+handle_inbound_channel (void *cls,
+ struct GNUNET_CADET_Channel *channel,
+ const struct GNUNET_PeerIdentity *initiator)
{
struct PeerContext *peer_ctx;
struct GNUNET_PeerIdentity *ctx_peer;
channel_ctx = add_channel_ctx (peer_ctx);
channel_ctx->channel = channel;
/* We only accept one incoming channel per peer */
- if (GNUNET_YES == Peers_check_peer_send_intention (initiator))
+ if (GNUNET_YES == check_peer_send_intention (initiator))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Already got one receive channel. Destroying old one.\n");
GNUNET_break_op (0);
- GNUNET_CADET_channel_destroy (peer_ctx->recv_channel_ctx->channel);
- peer_ctx->recv_channel_ctx->channel = NULL;
- remove_channel_ctx (peer_ctx->recv_channel_ctx);
+ destroy_channel (peer_ctx->recv_channel_ctx);
peer_ctx->recv_channel_ctx = channel_ctx;
/* return the channel context */
return channel_ctx;
* #GNUNET_NO otherwise
*/
static int
-Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
+check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *peer_ctx;
- if (GNUNET_NO == Peers_check_peer_known (peer))
+ if (GNUNET_NO == check_peer_known (peer))
{ /* If no such peer exists, there is no channel */
return GNUNET_NO;
}
}
-/**
- * @brief check whether the given channel is the sending channel of the given
- * peer
- *
- * @param peer the peer in question
- * @param channel the channel to check for
- * @param role either #Peers_CHANNEL_ROLE_SENDING, or
- * #Peers_CHANNEL_ROLE_RECEIVING
- *
- * @return #GNUNET_YES if the given chennel is the sending channel of the peer
- * #GNUNET_NO otherwise
- */
-static int
-Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_CADET_Channel *channel,
- enum Peers_ChannelRole role)
-{
- const struct PeerContext *peer_ctx;
-
- if (GNUNET_NO == Peers_check_peer_known (peer))
- {
- return GNUNET_NO;
- }
- peer_ctx = get_peer_ctx (peer);
- if ( (Peers_CHANNEL_ROLE_SENDING == role) &&
- (NULL != peer_ctx->send_channel_ctx) &&
- (channel == peer_ctx->send_channel_ctx->channel) )
- {
- return GNUNET_YES;
- }
- if ( (Peers_CHANNEL_ROLE_RECEIVING == role) &&
- (NULL != peer_ctx->recv_channel_ctx) &&
- (channel == peer_ctx->recv_channel_ctx->channel) )
- {
- return GNUNET_YES;
- }
- return GNUNET_NO;
-}
-
-
/**
* @brief Destroy the send channel of a peer e.g. stop indicating a sending
* intention to another peer
* #GNUNET_NO otherwise
*/
static int
-Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
+destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *peer_ctx;
- if (GNUNET_NO == Peers_check_peer_known (peer))
+ if (GNUNET_NO == check_peer_known (peer))
{
return GNUNET_NO;
}
if (NULL != peer_ctx->send_channel_ctx)
{
destroy_channel (peer_ctx->send_channel_ctx);
- (void) Peers_check_connected (peer);
+ (void) check_connected (peer);
return GNUNET_YES;
}
return GNUNET_NO;
* @param type type of the message
*/
static void
-Peers_send_message (const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Envelope *ev,
- const char *type)
+send_message (const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Envelope *ev,
+ const char *type)
{
struct PendingMessage *pending_msg;
struct GNUNET_MQ_Handle *mq;
* #GNUNET_NO otherwise
*/
static int
-Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
+schedule_operation (const struct GNUNET_PeerIdentity *peer,
const PeerOp peer_op)
{
struct PeerPendingOp pending_op;
struct PeerContext *peer_ctx;
- GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
+ GNUNET_assert (GNUNET_YES == check_peer_known (peer));
//TODO if LIVE/ONLINE execute immediately
return GNUNET_NO;
}
-/**
- * @brief Get the recv_channel of @a peer.
- * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming
- * messages.
- *
- * @param peer The peer to get the recv_channel from.
- *
- * @return The recv_channel.
- */
-static struct GNUNET_CADET_Channel *
-Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer)
-{
- struct PeerContext *peer_ctx;
-
- GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
- peer_ctx = get_peer_ctx (peer);
- return peer_ctx->recv_channel_ctx->channel;
-}
/***********************************************************************
* /Old gnunet-service-rps_peers.c
***********************************************************************/
{
int online;
- online = Peers_check_peer_flag (peer, Peers_ONLINE);
+ online = check_peer_flag (peer, Peers_ONLINE);
if ( (GNUNET_NO == online) ||
(GNUNET_SYSERR == online) ) /* peer is not even known */
{
- (void) Peers_issue_peer_liveliness_check (peer);
- (void) Peers_schedule_operation (peer, insert_in_view_op);
+ (void) issue_peer_liveliness_check (peer);
+ (void) schedule_operation (peer, insert_in_view_op);
return GNUNET_NO;
}
/* Open channel towards peer to keep connection open */
- Peers_indicate_sending_intention (peer);
+ indicate_sending_intention (peer);
return View_put (peer);
}
GNUNET_memcpy (&out_msg[1], peer_ids,
send_size * sizeof (struct GNUNET_PeerIdentity));
- Peers_send_message (peer_id, ev, "PULL REPLY");
+ send_message (peer_id, ev, "PULL REPLY");
GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO);
// TODO check with send intention: as send_channel is used/opened we indicate
// a sending intention without intending it.
if (0 < RPS_sampler_count_id (prot_sampler, peer))
{
/* Make sure we 'know' about this peer */
- (void) Peers_issue_peer_liveliness_check (peer);
+ (void) issue_peer_liveliness_check (peer);
/* Establish a channel towards that peer to indicate we are going to send
* messages to it */
- //Peers_indicate_sending_intention (peer);
+ //indicate_sending_intention (peer);
}
#ifdef TO_FILE
num_observed_peers++;
got_peer (const struct GNUNET_PeerIdentity *peer)
{
/* If we did not know this peer already, insert it into sampler and view */
- if (GNUNET_YES == Peers_issue_peer_liveliness_check (peer))
+ if (GNUNET_YES == issue_peer_liveliness_check (peer))
{
- Peers_schedule_operation (peer, insert_in_sampler);
- Peers_schedule_operation (peer, insert_in_view_op);
+ schedule_operation (peer, insert_in_sampler);
+ schedule_operation (peer, insert_in_view_op);
}
}
check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer)
{
/* struct GNUNET_CADET_Channel *channel; */
- if (GNUNET_NO == Peers_check_peer_known (peer))
+ if (GNUNET_NO == check_peer_known (peer))
{
return GNUNET_NO;
}
- if (GNUNET_YES == Peers_check_sending_channel_exists (peer))
+ if (GNUNET_YES == check_sending_channel_exists (peer))
{
if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) ||
(GNUNET_YES == View_contains_peer (peer)) ||
(GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) ||
(GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) ||
- (GNUNET_YES == Peers_check_peer_flag (peer, Peers_PULL_REPLY_PENDING)))
+ (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING)))
{ /* If we want to keep the connection to peer open */
return GNUNET_YES;
}
GNUNET_i2s (peer));
#ifdef ENABLE_MALICIOUS
if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer))
- (void) Peers_destroy_sending_channel (peer);
+ (void) destroy_sending_channel (peer);
#else /* ENABLE_MALICIOUS */
- (void) Peers_destroy_sending_channel (peer);
+ (void) destroy_sending_channel (peer);
#endif /* ENABLE_MALICIOUS */
}
- if ( (GNUNET_NO == Peers_check_peer_send_intention (peer)) &&
+ if ( (GNUNET_NO == check_peer_send_intention (peer)) &&
(GNUNET_NO == View_contains_peer (peer)) &&
(GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
(GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
(0 == RPS_sampler_count_id (prot_sampler, peer)) &&
(0 == RPS_sampler_count_id (client_sampler, peer)) &&
- (GNUNET_NO != Peers_check_removable (peer)) )
+ (GNUNET_NO != check_removable (peer)) )
{ /* We can safely remove this peer */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Going to remove peer %s\n",
}
}
-/**
- * @brief Allocate memory for a new channel context and insert it into DLL
- *
- * @param peer_ctx context of the according peer
- *
- * @return The channel context
- */
-static struct ChannelCtx *
-add_channel_ctx (struct PeerContext *peer_ctx)
-{
- struct ChannelCtx *channel_ctx;
- channel_ctx = GNUNET_new (struct ChannelCtx);
- channel_ctx->peer_ctx = peer_ctx;
- return channel_ctx;
-}
-
-
-/**
- * @brief Remove the channel context from the DLL and free the memory.
- *
- * @param channel_ctx The channel context.
- */
-static void
-remove_channel_ctx (struct ChannelCtx *channel_ctx)
-{
- struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
-
- GNUNET_free (channel_ctx);
- if (channel_ctx == peer_ctx->send_channel_ctx)
- {
- peer_ctx->send_channel_ctx = NULL;
- peer_ctx->mq = NULL;
- }
- else if (channel_ctx == peer_ctx->recv_channel_ctx)
- {
- peer_ctx->recv_channel_ctx = NULL;
- }
- else
- {
- GNUNET_assert (0);
- }
-}
-
/**
* @brief This is called when a channel is destroyed.
/* Add the sending peer to the push_map */
CustomPeerMap_put (push_map, peer);
- GNUNET_break_op (Peers_check_peer_known (peer));
+ GNUNET_break_op (check_peer_known (peer));
GNUNET_CADET_receive_done (channel_ctx->channel);
}
}
#endif /* ENABLE_MALICIOUS */
- GNUNET_break_op (Peers_check_peer_known (peer));
+ GNUNET_break_op (check_peer_known (peer));
GNUNET_CADET_receive_done (channel_ctx->channel);
view_array = View_get_as_array ();
send_pull_reply (peer, view_array, View_size ());
return GNUNET_SYSERR;
}
- if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING))
+ if (GNUNET_YES != check_peer_flag (sender, Peers_PULL_REPLY_PENDING))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Received a pull reply from a peer (%s) we didn't request one from!\n",
}
#endif /* ENABLE_MALICIOUS */
/* Make sure we 'know' about this peer */
- (void) Peers_insert_peer (&peers[i]);
+ (void) insert_peer (&peers[i]);
- if (GNUNET_YES == Peers_check_peer_valid (&peers[i]))
+ if (GNUNET_YES == check_peer_valid (&peers[i]))
{
CustomPeerMap_put (pull_map, &peers[i]);
}
else
{
- Peers_schedule_operation (&peers[i], insert_in_pull_map);
- (void) Peers_issue_peer_liveliness_check (&peers[i]);
+ schedule_operation (&peers[i], insert_in_pull_map);
+ (void) issue_peer_liveliness_check (&peers[i]);
}
}
- Peers_unset_peer_flag (sender, Peers_PULL_REPLY_PENDING);
+ UNSET_PEER_FLAG (get_peer_ctx (sender), Peers_PULL_REPLY_PENDING);
clean_peer (sender);
- GNUNET_break_op (Peers_check_peer_known (sender));
+ GNUNET_break_op (check_peer_known (sender));
GNUNET_CADET_receive_done (channel_ctx->channel);
}
{
struct GNUNET_MQ_Envelope *ev;
- GNUNET_assert (GNUNET_NO == Peers_check_peer_flag (peer,
+ GNUNET_assert (GNUNET_NO == check_peer_flag (peer,
Peers_PULL_REPLY_PENDING));
- Peers_set_peer_flag (peer, Peers_PULL_REPLY_PENDING);
+ SET_PEER_FLAG (get_peer_ctx (peer), Peers_PULL_REPLY_PENDING);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Going to send PULL REQUEST to peer %s.\n",
GNUNET_i2s (peer));
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
- Peers_send_message (peer, ev, "PULL REQUEST");
+ send_message (peer, ev, "PULL REQUEST");
GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO);
}
GNUNET_i2s (peer_id));
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
- Peers_send_message (peer_id, ev, "PUSH");
+ send_message (peer_id, ev, "PUSH");
GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO);
}
&msg->attacked_peer,
sizeof (struct GNUNET_PeerIdentity));
/* Set the flag of the attacked peer to valid to avoid problems */
- if (GNUNET_NO == Peers_check_peer_known (&attacked_peer))
+ if (GNUNET_NO == check_peer_known (&attacked_peer))
{
- (void) Peers_issue_peer_liveliness_check (&attacked_peer);
+ (void) issue_peer_liveliness_check (&attacked_peer);
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
* Send as many pushes to the attacked peer as possible
* That is one push per round as it will ignore more.
*/
- (void) Peers_issue_peer_liveliness_check (&attacked_peer);
- if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE))
+ (void) issue_peer_liveliness_check (&attacked_peer);
+ if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE))
send_push (&attacked_peer);
}
{ /* Combined attack */
/* Send PUSH to attacked peers */
- if (GNUNET_YES == Peers_check_peer_known (&attacked_peer))
+ if (GNUNET_YES == check_peer_known (&attacked_peer))
{
- (void) Peers_issue_peer_liveliness_check (&attacked_peer);
- if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE))
+ (void) issue_peer_liveliness_check (&attacked_peer);
+ if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Goding to send push to attacked peer (%s)\n",
send_push (&attacked_peer);
}
}
- (void) Peers_issue_peer_liveliness_check (&attacked_peer);
+ (void) issue_peer_liveliness_check (&attacked_peer);
/* The maximum of pushes we're going to send this round */
num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1,
for (i = first_border; i < second_border; i++)
{
peer = view_array[permut[i]];
- if ( GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING))
+ if ( GNUNET_NO == check_peer_flag (&peer, Peers_PULL_REPLY_PENDING))
{ // FIXME if this fails schedule/loop this for later
send_pull_request (&peer);
}
&port);
cadet_port = GNUNET_CADET_open_port (cadet_handle,
&port,
- &Peers_handle_inbound_channel, /* Connect handler */
+ &handle_inbound_channel, /* Connect handler */
NULL, /* cls */
NULL, /* WindowSize handler */
&cleanup_destroyed_channel, /* Disconnect handler */
peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
- Peers_initialise (fn_valid_peers, cadet_handle);
+ initialise_peers (fn_valid_peers, cadet_handle);
GNUNET_free (fn_valid_peers);
/* Initialise sampler */
// TODO send push/pull to each of those peers?
// TODO read stored valid peers from last run
LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
- Peers_get_valid_peers (valid_peers_iterator, NULL);
+ get_valid_peers (valid_peers_iterator, NULL);
peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg,
GNUNET_NO,