Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

sq.c File Reference


Detailed Description

Search queue.

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.

Author:
Alex Bennee <alex@bennee.com>

Raphael Manfredi

Date:
2002-2003

#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_tsmsg_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_tsq_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_tsq_global_queue (void)
void sq_init (void)
 Initialization of SQ at startup.

void sq_close (void)
 Cleanup at shutdown time.


Variables

squeue_tglobal_sq = NULL


Define Documentation

#define QUERY_TEXT  )     ((m) + sizeof(struct gnutella_header) + 2)
 


Typedef Documentation

typedef struct smsg smsg_t
 

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.


Function Documentation

void cap_queue squeue_t sq  )  [static]
 

Decides if it needs to drop the oldest messages on the search queue based on the search count.

RCSID "$Id:sq.  c,
v 1.12 2005/08/31 21:37:28 rmanfredi Exp $" 
 

smsg_t* smsg_alloc gnet_search_t  sh,
pmsg_t mb,
query_hashvec_t qhv
[static]
 

Allocate a new search queue entry.

void smsg_discard smsg_t sb  )  [static]
 

Dispose of the search queue entry and of all its contained data.

Used only when the query described in `sb' is not dispatched.

void smsg_free smsg_t sb  )  [static]
 

Dispose of the search queue entry.

void smsg_mutate smsg_t sb,
struct gnutella_node n
[static]
 

Mutate the message so that we can be notified about its freeing by the mq to which it will be sent to.

void sq_clear squeue_t sq  ) 
 

Clear all queued searches.

void sq_close void   ) 
 

Cleanup at shutdown time.

void sq_free squeue_t sq  ) 
 

Free queue and all queued searches.

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.

Parameters:
mb the query message
sh the search handle
qhv the query hash vector for QRP matching

squeue_t* sq_global_queue void   ) 
 

Returns:
global queue.

void sq_init void   ) 
 

Initialization of SQ at startup.

squeue_t* sq_make struct gnutella_node node  ) 
 

Create a new search queue.

void sq_pmsg_free pmsg_t mb,
gpointer  arg
[static]
 

Free routine for a query message.

void sq_process squeue_t sq,
time_t  now
 

Decides if the queue can send a message.

Currently use simple fixed time base heuristics. May add bursty control later...

void sq_puthere squeue_t sq,
gnet_search_t  sh,
pmsg_t mb,
query_hashvec_t qhv
[static]
 

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).

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.

Parameters:
sq DOCUMENT THIS!
mb the query message
sh the search handle

void sq_search_closed squeue_t sq,
gnet_search_t  sh
 

Signals the search queue that a search was closed.

Any query for that search still in the queue is dropped.

void sq_set_peermode node_peer_t  mode  ) 
 

Invoked when the current peermode changes.

gboolean sqh_exists squeue_t sq,
gnet_search_t  sh
[static]
 

Checks whether an entry exists in the search queue for given search handle.

void sqh_put squeue_t sq,
gnet_search_t  sh
[static]
 

Record search handle in the hash table.

void sqh_remove squeue_t sq,
gnet_search_t  sh
[static]
 

Remove search handle from the hash table.


Variable Documentation

squeue_t* global_sq = NULL [static]
 


Generated on Sun Feb 12 10:50:08 2006 for Gtk-Gnutella by doxygen 1.3.6