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

search.c File Reference


Detailed Description

Search handling (core side).

Author:
Raphael Manfredi
Date:
2001-2003

#include "common.h"
#include "extensions.h"
#include "gmsg.h"
#include "huge.h"
#include "nodes.h"
#include "routing.h"
#include "downloads.h"
#include "gnet_stats.h"
#include "ignore.h"
#include "ggep_type.h"
#include "version.h"
#include "qrp.h"
#include "search.h"
#include "hostiles.h"
#include "dmesh.h"
#include "fileinfo.h"
#include "guid.h"
#include "dq.h"
#include "dh.h"
#include "share.h"
#include "sockets.h"
#include "vmsg.h"
#include "sq.h"
#include "settings.h"
#include "oob_proxy.h"
#include "hosts.h"
#include "bogons.h"
#include "geo_ip.h"
#include "if/gnet_property_priv.h"
#include "if/gui_property.h"
#include "if/core/hosts.h"
#include "lib/atoms.h"
#include "lib/endian.h"
#include "lib/glib-missing.h"
#include "lib/idtable.h"
#include "lib/listener.h"
#include "lib/misc.h"
#include "lib/tm.h"
#include "lib/vendors.h"
#include "lib/wordvec.h"
#include "lib/walloc.h"
#include "lib/zalloc.h"
#include "lib/utf8.h"
#include "lib/urn.h"
#include "lib/override.h"

Data Structures

struct  search_ctrl
 Structure for search results. More...


Defines

#define MUID_MAX   4 /**< Max amount of MUID we keep per search */
 Max amount of MUID we keep per search.

#define SEARCH_MIN_RETRY   1800 /**< Minimum search retry timeout */
 Minimum search retry timeout.

#define search_find_by_handle(n)   (search_ctrl_t *) idtable_get_value(search_handle_map, n)
#define search_request_handle(n)   idtable_new_id(search_handle_map, n)
#define search_drop_handle(n)   idtable_free_id(search_handle_map, n);
#define count_sha1(x)   do { } while (0)
#define count_host(x)   do { } while (0)
#define CLOSED_SEARCH   0xffff

Typedefs

typedef search_ctrl search_ctrl_t
 Structure for search results.


Functions

 RCSID ("$Id:search.c, v 1.98 2006/02/01 23:13:21 cbiere Exp $")
void search_check_results_set (gnet_results_set_t *rs)
 Check a results_set for matching entries in the download queue, and generate new entries if we find a match.

void search_add_got_results_listener (search_got_results_listener_t l)
void search_remove_got_results_listener (search_got_results_listener_t l)
void search_fire_got_results (GSList *sch_matched, const gnet_results_set_t *rs)
guint sent_node_hash_func (gconstpointer key)
gint sent_node_compare (gconstpointer a, gconstpointer b)
gboolean search_free_sent_node (gpointer key, gpointer unused_value, gpointer unused_udata)
void search_free_sent_nodes (search_ctrl_t *sch)
void search_reset_sent_nodes (search_ctrl_t *sch)
void mark_search_sent_to_node (search_ctrl_t *sch, gnutella_node_t *n)
void mark_search_sent_to_connected_nodes (search_ctrl_t *sch)
void search_free_sent_node_ids (search_ctrl_t *sch)
void search_reset_sent_node_ids (search_ctrl_t *sch)
void mark_search_sent_to_node_id (search_ctrl_t *sch, guint32 node_id)
gboolean search_already_sent_to_node (const search_ctrl_t *sch, const gnutella_node_t *n)
void search_free_alt_locs (gnet_record_t *rc)
 Free the alternate locations held within a file record.

void search_free_proxies (gnet_results_set_t *rs)
 Free the push proxies held within a result set.

void search_free_record (gnet_record_t *rc)
 Free one file record.

void search_free_r_set (gnet_results_set_t *rs)
 Free one results_set.

gnet_results_set_tget_results_set (gnutella_node_t *n, gboolean validate_only, gboolean browse)
 Parse Query Hit and extract the embedded records, plus the optional trailing Query Hit Descritor (QHD).

void update_neighbour_info (gnutella_node_t *n, gnet_results_set_t *rs)
 Called when we get a query hit from an immediate neighbour.

gnutella_msg_searchbuild_search_msg (search_ctrl_t *sch, guint32 *len, guint32 *sizep)
 Create a search request message for specified search.

void search_qhv_fill (search_ctrl_t *sch, query_hashvec_t *qhv)
 Fill supplied query hash vector `qhv' with relevant word/SHA1 entries for the given search.

void search_send_packet (search_ctrl_t *sch, gnutella_node_t *n)
 Create and send a search request packet.

void node_added_callback (gpointer data)
 Called when we connect to a new node and thus can send it our searches.

void search_add_new_muid (search_ctrl_t *sch, gchar *muid)
 Create a new muid and add it to the search's list of muids.

void search_send_packet_all (search_ctrl_t *sch)
 Send search to all connected nodes.

gboolean search_reissue_timeout_callback (gpointer data)
 Called when the reissue timer for any search is triggered.

void update_one_reissue_timeout (search_ctrl_t *sch)
 Make sure a timer is created/removed after a search was started/stopped.

gboolean search_alive (search_ctrl_t *sch, guint32 id)
 Check whether search bearing the specified ID is still alive.

void search_send_query_status (search_ctrl_t *sch, guint32 node_id, guint16 kept)
 Send an unsolicited "Query Status Response" to the specified node ID, bearing the amount of kept results.

void search_send_status (gpointer key, gpointer unused_value, gpointer udata)
 Send an unsolicited "Query Status Response" to the specified node ID about the results we kept so far for the relevant search.

void search_update_results (search_ctrl_t *sch)
 Update our querying ultrapeers about the results we kept so far for the given search.

void search_send_closed (gpointer key, gpointer unused_value, gpointer udata)
 Send an unsolicited "Query Status Response" to the specified node ID informing it that the search was closed.

void search_notify_closed (gnet_search_t sh)
 Tell our querying ultrapeers that the search is closed.

void search_dequeue_all_nodes (gnet_search_t sh)
 Signal to all search queues that search was closed.

void search_init (void)
void search_shutdown (void)
void search_browse_results (gnutella_node_t *n, gnet_search_t sh)
 This routine is called for each Query Hit packet we receive out of a browse-host request, since we know the target search result, and we don't need to bother with forwarding that message.

gboolean search_results (gnutella_node_t *n, gint *results)
 This routine is called for each Query Hit packet we receive.

gboolean search_query_allowed (gnet_search_t sh)
 Check whether we can send another query for this search.

guint32 search_get_id (gnet_search_t sh, gpointer *search)
void search_notify_sent (gpointer search, guint32 id, guint32 node_id)
 Notification from sq that a query for this search was sent to the specified node ID.

void search_check_alt_locs (gnet_results_set_t *rs, gnet_record_t *rc, fileinfo_t *fi)
 Check for alternate locations in the result set, and enqueue the downloads if there are any.

void search_close (gnet_search_t sh)
 Remove the search from the list of searches and free all associated ressources.

gchar * search_new_muid (gboolean initial)
 Allocate a new MUID for a search.

gboolean search_expired (const search_ctrl_t *sch)
void search_reissue (gnet_search_t sh)
 Force a reissue of the given search.

void search_set_reissue_timeout (gnet_search_t sh, guint32 timeout)
 Set the reissue timeout of a search.

guint32 search_get_reissue_timeout (gnet_search_t sh)
 Get the reissue timeout of a search.

guint search_get_lifetime (gnet_search_t sh)
 Get the initial lifetime (in hours) of a search.

time_t search_get_create_time (gnet_search_t sh)
 Get the create time of a search.

void search_set_create_time (gnet_search_t sh, time_t t)
 Set the create time of a search.

gnet_search_t search_new (const gchar *query, time_t create_time, guint lifetime, guint32 reissue_timeout, flag_t flags)
 Create a new suspended search and return a handle which identifies it.

void search_update_items (gnet_search_t sh, guint32 items)
 The GUI updates us on the amount of items displayed in the search.

void search_add_kept (gnet_search_t sh, guint32 kept)
 The filtering side lets us know the amount of items we "kept", which are either things we display to the user or entries we used for auto-download.

void search_start (gnet_search_t sh)
 Start a newly created start or resume stopped search.

void search_stop (gnet_search_t sh)
 Stop search.

gboolean search_get_kept_results (gchar *muid, guint32 *kept)
 Get amount of results we displayed for the search identified by its MUID.

guint32 search_get_kept_results_by_handle (gnet_search_t sh)
void search_oob_pending_results (gnutella_node_t *n, gchar *muid, gint hits, gboolean udp_firewalled)
 Received out-of-band indication of results for search identified by its MUID, on remote node `n'.

gboolean search_is_frozen (gnet_search_t sh)
gboolean search_is_passive (gnet_search_t sh)
gboolean search_is_active (gnet_search_t sh)
gboolean search_is_expired (gnet_search_t sh)
gboolean search_browse (gnet_search_t sh, const gchar *hostname, host_addr_t addr, guint16 port, const gchar *guid, gboolean push, const gnet_host_vec_t *proxies)
 Associate download to fill in the opened browse search.

void search_dissociate_browse (gnet_search_t sh, gpointer download)
 Notification from the download layer that a browse-host download is being removed.


Variables

guint32 search_id = 0
 Unique search counter.

GHashTable * searches = NULL
 All alive searches.

GSList * sl_search_ctrl = NULL
 All searches.

GSList * sl_passive_ctrl = NULL
 Only passive searches.

GHashTable * search_by_muid = NULL
zone_trs_zone = NULL
 Allocation of results_set.

zone_trc_zone = NULL
 Allocation of record.

idtable_tsearch_handle_map = NULL
query_hashvec_tquery_hashvec = NULL
GHashTable * ht_sha1 = NULL
GHashTable * ht_host = NULL
listeners_t search_got_results_listeners = NULL


Define Documentation

#define CLOSED_SEARCH   0xffff
 

#define count_host  )     do { } while (0)
 

#define count_sha1  )     do { } while (0)
 

#define MUID_MAX   4 /**< Max amount of MUID we keep per search */
 

Max amount of MUID we keep per search.

#define search_drop_handle  )     idtable_free_id(search_handle_map, n);
 

#define search_find_by_handle  )     (search_ctrl_t *) idtable_get_value(search_handle_map, n)
 

#define SEARCH_MIN_RETRY   1800 /**< Minimum search retry timeout */
 

Minimum search retry timeout.

#define search_request_handle  )     idtable_new_id(search_handle_map, n)
 


Typedef Documentation

typedef struct search_ctrl search_ctrl_t
 

Structure for search results.


Function Documentation

struct gnutella_msg_search* build_search_msg search_ctrl_t sch,
guint32 *  len,
guint32 *  sizep
[static]
 

Create a search request message for specified search.

Since this is inherently a variable sized structure, fill in `len' to be the actual size of the allocated message, and `sizep' the length of the built message.

NB: the actual Gnutella messsage can be SHORTER if we compacted the query string. Don't use the reported length as an indicator of the message size. Use the value returned in `sizep' instead.

Returns:
NULL if we cannot build a suitable message (bad query string containing only whitespaces, for instance).

gnet_results_set_t* get_results_set gnutella_node_t n,
gboolean  validate_only,
gboolean  browse
[static]
 

Parse Query Hit and extract the embedded records, plus the optional trailing Query Hit Descritor (QHD).

If `validate_only' is set, we only validate the results and don't wish to permanently use the results, so don't allocate any memory for each record.

Returns:
a structure describing the whole result set, or NULL if we were unable to parse it properly.

void mark_search_sent_to_connected_nodes search_ctrl_t sch  )  [static]
 

void mark_search_sent_to_node search_ctrl_t sch,
gnutella_node_t n
[static]
 

void mark_search_sent_to_node_id search_ctrl_t sch,
guint32  node_id
[static]
 

void node_added_callback gpointer  data  )  [static]
 

Called when we connect to a new node and thus can send it our searches.

Bug:
FIXME: uses node_added which is a global variable in nodes.c. This should instead be contained with the argument to this call.

RCSID "$Id:search.  c,
v 1.98 2006/02/01 23:13:21 cbiere Exp $" 
 

void search_add_got_results_listener search_got_results_listener_t  l  ) 
 

void search_add_kept gnet_search_t  sh,
guint32  kept
 

The filtering side lets us know the amount of items we "kept", which are either things we display to the user or entries we used for auto-download.

void search_add_new_muid search_ctrl_t sch,
gchar *  muid
[static]
 

Create a new muid and add it to the search's list of muids.

Also record the direct mapping between this muid and the search into the `search_by_muid' table.

gboolean search_alive search_ctrl_t sch,
guint32  id
[static]
 

Check whether search bearing the specified ID is still alive.

gboolean search_already_sent_to_node const search_ctrl_t sch,
const gnutella_node_t n
[static]
 

Returns:
TRUE if we already queried the given node for the given search.

gboolean search_browse gnet_search_t  sh,
const gchar *  hostname,
host_addr_t  addr,
guint16  port,
const gchar *  guid,
gboolean  push,
const gnet_host_vec_t proxies
 

Associate download to fill in the opened browse search.

Parameters:
sh no document.
hostname the DNS name of the host, or NULL if none known.
addr the IP address of the host to browse.
port the port to contact.
guid the GUID of the remote host.
push whether a PUSH request is neeed to reach remote host.
proxies vector holding known push-proxies.
Returns:
TRUE if we successfully initialized the download layer.

void search_browse_results gnutella_node_t n,
gnet_search_t  sh
 

This routine is called for each Query Hit packet we receive out of a browse-host request, since we know the target search result, and we don't need to bother with forwarding that message.

void search_check_alt_locs gnet_results_set_t rs,
gnet_record_t rc,
fileinfo_t fi
[static]
 

Check for alternate locations in the result set, and enqueue the downloads if there are any.

Then free the alternate location from the record.

void search_check_results_set gnet_results_set_t rs  )  [static]
 

Check a results_set for matching entries in the download queue, and generate new entries if we find a match.

void search_close gnet_search_t  sh  ) 
 

Remove the search from the list of searches and free all associated ressources.

void search_dequeue_all_nodes gnet_search_t  sh  )  [static]
 

Signal to all search queues that search was closed.

void search_dissociate_browse gnet_search_t  sh,
gpointer  download
 

Notification from the download layer that a browse-host download is being removed.

This closes the relationship between the given search and the removed download.

gboolean search_expired const search_ctrl_t sch  )  [static]
 

Returns:
whether search has expired.

void search_fire_got_results GSList *  sch_matched,
const gnet_results_set_t rs
[static]
 

void search_free_alt_locs gnet_record_t rc  ) 
 

Free the alternate locations held within a file record.

void search_free_proxies gnet_results_set_t rs  ) 
 

Free the push proxies held within a result set.

void search_free_r_set gnet_results_set_t rs  )  [static]
 

Free one results_set.

void search_free_record gnet_record_t rc  )  [static]
 

Free one file record.

gboolean search_free_sent_node gpointer  key,
gpointer  unused_value,
gpointer  unused_udata
[static]
 

void search_free_sent_node_ids search_ctrl_t sch  )  [static]
 

void search_free_sent_nodes search_ctrl_t sch  )  [static]
 

time_t search_get_create_time gnet_search_t  sh  ) 
 

Get the create time of a search.

guint32 search_get_id gnet_search_t  sh,
gpointer *  search
 

Returns:
unique ID associated with search with given handle, and return the address of the search object as well.

gboolean search_get_kept_results gchar *  muid,
guint32 *  kept
 

Get amount of results we displayed for the search identified by its MUID.

We assume it is the last MUID we used for requerying if we find a search that sent a query with the MUID.

Returns:
TRUE if we found a search having sent this MUID, along with the amount of results we kept sofar for the last requery, via "kept", or FALSE if we did not find any search.

guint32 search_get_kept_results_by_handle gnet_search_t  sh  ) 
 

Returns:
amount of hits kept by the search, identified by its handle

guint search_get_lifetime gnet_search_t  sh  ) 
 

Get the initial lifetime (in hours) of a search.

guint32 search_get_reissue_timeout gnet_search_t  sh  ) 
 

Get the reissue timeout of a search.

void search_init void   ) 
 

gboolean search_is_active gnet_search_t  sh  ) 
 

gboolean search_is_expired gnet_search_t  sh  ) 
 

gboolean search_is_frozen gnet_search_t  sh  ) 
 

gboolean search_is_passive gnet_search_t  sh  ) 
 

gnet_search_t search_new const gchar *  query,
time_t  create_time,
guint  lifetime,
guint32  reissue_timeout,
flag_t  flags
 

Create a new suspended search and return a handle which identifies it.

Parameters:
query an UTF-8 encoded query string.
create_time no document.
lifetime no document.
flags option flags for the search.
reissue_timeout delay in seconds before requerying.
Returns:
-1 if the search could not be created, a valid handle for the search otherwise.

gchar* search_new_muid gboolean  initial  )  [static]
 

Allocate a new MUID for a search.

Parameters:
initial indicates whether this is an initial query or a requery.
Returns:
a new MUID that can be wfree()'d when done.

void search_notify_closed gnet_search_t  sh  )  [static]
 

Tell our querying ultrapeers that the search is closed.

void search_notify_sent gpointer  search,
guint32  id,
guint32  node_id
 

Notification from sq that a query for this search was sent to the specified node ID.

void search_oob_pending_results gnutella_node_t n,
gchar *  muid,
gint  hits,
gboolean  udp_firewalled
 

Received out-of-band indication of results for search identified by its MUID, on remote node `n'.

Parameters:
n the remote node which has results for us.
muid the MUID of the search.
hits the amount of hits available (255 mean 255+ hits).
udp_firewalled the remote host is UDP-firewalled and cannot receive unsolicited UDP traffic.

void search_qhv_fill search_ctrl_t sch,
query_hashvec_t qhv
[static]
 

Fill supplied query hash vector `qhv' with relevant word/SHA1 entries for the given search.

gboolean search_query_allowed gnet_search_t  sh  ) 
 

Check whether we can send another query for this search.

Returns:
TRUE if we can send, with the emitted counter incremented, or FALSE if the query should just be ignored.

void search_reissue gnet_search_t  sh  ) 
 

Force a reissue of the given search.

Restart reissue timer.

gboolean search_reissue_timeout_callback gpointer  data  )  [static]
 

Called when the reissue timer for any search is triggered.

The data given is the search to be reissued.

void search_remove_got_results_listener search_got_results_listener_t  l  ) 
 

void search_reset_sent_node_ids search_ctrl_t sch  )  [static]
 

void search_reset_sent_nodes search_ctrl_t sch  )  [static]
 

gboolean search_results gnutella_node_t n,
gint *  results
 

This routine is called for each Query Hit packet we receive.

Returns:
whether the message should be dropped, i.e. FALSE if OK. If the message should not be dropped, `results' is filled with the amount of results contained in the query hit.

void search_send_closed gpointer  key,
gpointer  unused_value,
gpointer  udata
[static]
 

Send an unsolicited "Query Status Response" to the specified node ID informing it that the search was closed.

-- hash table iterator callback

void search_send_packet search_ctrl_t sch,
gnutella_node_t n
[static]
 

Create and send a search request packet.

Parameters:
sch DOCUMENT THIS!
n if NULL, we're "broadcasting" an initial search. Otherwise, this is the only node to which we should send the message.

void search_send_packet_all search_ctrl_t sch  )  [static]
 

Send search to all connected nodes.

void search_send_query_status search_ctrl_t sch,
guint32  node_id,
guint16  kept
[static]
 

Send an unsolicited "Query Status Response" to the specified node ID, bearing the amount of kept results.

The 0xffff value is a special marker to indicate the search was closed.

void search_send_status gpointer  key,
gpointer  unused_value,
gpointer  udata
[static]
 

Send an unsolicited "Query Status Response" to the specified node ID about the results we kept so far for the relevant search.

-- hash table iterator callback

void search_set_create_time gnet_search_t  sh,
time_t  t
 

Set the create time of a search.

void search_set_reissue_timeout gnet_search_t  sh,
guint32  timeout
 

Set the reissue timeout of a search.

void search_shutdown void   ) 
 

void search_start gnet_search_t  sh  ) 
 

Start a newly created start or resume stopped search.

void search_stop gnet_search_t  sh  ) 
 

Stop search.

Cancel reissue timer and don't return any results anymore.

void search_update_items gnet_search_t  sh,
guint32  items
 

The GUI updates us on the amount of items displayed in the search.

void search_update_results search_ctrl_t sch  )  [static]
 

Update our querying ultrapeers about the results we kept so far for the given search.

gint sent_node_compare gconstpointer  a,
gconstpointer  b
[static]
 

guint sent_node_hash_func gconstpointer  key  )  [static]
 

void update_neighbour_info gnutella_node_t n,
gnet_results_set_t rs
[static]
 

Called when we get a query hit from an immediate neighbour.

void update_one_reissue_timeout search_ctrl_t sch  )  [static]
 

Make sure a timer is created/removed after a search was started/stopped.


Variable Documentation

GHashTable* ht_host = NULL [static]
 

GHashTable* ht_sha1 = NULL [static]
 

query_hashvec_t* query_hashvec = NULL [static]
 

zone_t* rc_zone = NULL [static]
 

Allocation of record.

zone_t* rs_zone = NULL [static]
 

Allocation of results_set.

GHashTable* search_by_muid = NULL [static]
 

listeners_t search_got_results_listeners = NULL [static]
 

idtable_t* search_handle_map = NULL [static]
 

guint32 search_id = 0 [static]
 

Unique search counter.

GHashTable* searches = NULL [static]
 

All alive searches.

GSList* sl_passive_ctrl = NULL [static]
 

Only passive searches.

GSList* sl_search_ctrl = NULL [static]
 

All searches.


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