This file takes care of paceing search messages out at a rate that doesn't flood the gnutella network. A search queue is maintained for each gnutella node and regularly polled by the timer function to release messages into the lower message queues
For ultrapeers conducting dynamic querying for their own queries, this system of having one search queue per node is not used. Instead, we have one global search queue, which is used to space launching of dynamic queries.
Raphael Manfredi
#include "common.h"
#include "sq.h"
#include "pmsg.h"
#include "nodes.h"
#include "search.h"
#include "dq.h"
#include "if/gnet_property_priv.h"
#include "lib/atoms.h"
#include "lib/tm.h"
#include "lib/walloc.h"
#include "lib/override.h"
Data Structures | |
struct | smsg |
A search queue entry. More... | |
struct | smsg_info |
Message information for mutated blocks. More... | |
Defines | |
#define | QUERY_TEXT(m) ((m) + sizeof(struct gnutella_header) + 2) |
Typedefs | |
typedef smsg | smsg_t |
A search queue entry. | |
Functions | |
RCSID ("$Id:sq.c, v 1.12 2005/08/31 21:37:28 rmanfredi Exp $") | |
void | cap_queue (squeue_t *sq) |
Decides if it needs to drop the oldest messages on the search queue based on the search count. | |
void | sq_pmsg_free (pmsg_t *mb, gpointer arg) |
Free routine for a query message. | |
smsg_t * | smsg_alloc (gnet_search_t sh, pmsg_t *mb, query_hashvec_t *qhv) |
Allocate a new search queue entry. | |
void | smsg_free (smsg_t *sb) |
Dispose of the search queue entry. | |
void | smsg_discard (smsg_t *sb) |
Dispose of the search queue entry and of all its contained data. | |
void | smsg_mutate (smsg_t *sb, struct gnutella_node *n) |
Mutate the message so that we can be notified about its freeing by the mq to which it will be sent to. | |
gboolean | sqh_exists (squeue_t *sq, gnet_search_t sh) |
Checks whether an entry exists in the search queue for given search handle. | |
void | sqh_put (squeue_t *sq, gnet_search_t sh) |
Record search handle in the hash table. | |
void | sqh_remove (squeue_t *sq, gnet_search_t sh) |
Remove search handle from the hash table. | |
squeue_t * | sq_make (struct gnutella_node *node) |
Create a new search queue. | |
void | sq_clear (squeue_t *sq) |
Clear all queued searches. | |
void | sq_free (squeue_t *sq) |
Free queue and all queued searches. | |
void | sq_puthere (squeue_t *sq, gnet_search_t sh, pmsg_t *mb, query_hashvec_t *qhv) |
Enqueue query message in specified queue. | |
void | sq_putq (squeue_t *sq, gnet_search_t sh, pmsg_t *mb) |
Enqueue a single query (LIFO behaviour). | |
void | sq_global_putq (gnet_search_t sh, pmsg_t *mb, query_hashvec_t *qhv) |
Enqueue a single query waiting for dynamic querying into global SQ. | |
void | sq_process (squeue_t *sq, time_t now) |
Decides if the queue can send a message. | |
void | sq_search_closed (squeue_t *sq, gnet_search_t sh) |
Signals the search queue that a search was closed. | |
void | sq_set_peermode (node_peer_t mode) |
Invoked when the current peermode changes. | |
squeue_t * | sq_global_queue (void) |
void | sq_init (void) |
Initialization of SQ at startup. | |
void | sq_close (void) |
Cleanup at shutdown time. | |
Variables | |
squeue_t * | global_sq = NULL |
|
|
|
A search queue entry. Each entry references the search that issued the query. Before sending the query message, a check will be made to make sure we are not over-querying for that particular search. |
|
Decides if it needs to drop the oldest messages on the search queue based on the search count.
|
|
|
|
Allocate a new search queue entry.
|
|
Dispose of the search queue entry and of all its contained data. Used only when the query described in `sb' is not dispatched. |
|
Dispose of the search queue entry.
|
|
Mutate the message so that we can be notified about its freeing by the mq to which it will be sent to.
|
|
Clear all queued searches.
|
|
Cleanup at shutdown time.
|
|
Free queue and all queued searches.
|
|
Enqueue a single query waiting for dynamic querying into global SQ.
|
|
|
|
Initialization of SQ at startup.
|
|
Create a new search queue.
|
|
Free routine for a query message.
|
|
Decides if the queue can send a message. Currently use simple fixed time base heuristics. May add bursty control later... |
|
Enqueue query message in specified queue.
|
|
Enqueue a single query (LIFO behaviour). Having the search handle allows us to check before sending the query that we are not over-querying for a given search. It's also handy to remove the queries when a search is closed, and avoid queuing twice the same search.
|
|
Signals the search queue that a search was closed. Any query for that search still in the queue is dropped. |
|
Invoked when the current peermode changes.
|
|
Checks whether an entry exists in the search queue for given search handle.
|
|
Record search handle in the hash table.
|
|
Remove search handle from the hash table.
|
|
|