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

huge.c File Reference


Detailed Description

HUGE support (Hash/URN Gnutella Extension).

Author:
Raphael Manfredi
Date:
2002-2003
Author:
Ch. Tronche (http://tronche.com/)
Date:
2002-04-28

#include "common.h"
#include "huge.h"
#include "share.h"
#include "gmsg.h"
#include "dmesh.h"
#include "verify_sha1.h"
#include "verify_tth.h"
#include "version.h"
#include "settings.h"
#include "spam.h"
#include "lib/atoms.h"
#include "lib/base32.h"
#include "lib/file.h"
#include "lib/header.h"
#include "lib/sha1.h"
#include "lib/tm.h"
#include "lib/urn.h"
#include "lib/walloc.h"
#include "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "lib/override.h"

Data Structures

struct  sha1_cache_entry
 There's an in-core cache (the GHashTable sha1_cache), and a persistent copy (normally in ~/.gtk-gnutella/sha1_cache). More...
struct  dump_cache_context

Functions

void update_volatile_cache (struct sha1_cache_entry *item, filesize_t size, time_t mtime, const struct sha1 *sha1, const struct tth *tth)
 Takes an in-memory cached entry, and update its content.
void add_volatile_cache_entry (const char *filename, filesize_t size, time_t mtime, const struct sha1 *sha1, const struct tth *tth, gboolean known_to_be_shared)
 Add a new entry to the in-memory cache.
void cache_entry_print (FILE *f, const char *filename, const struct sha1 *sha1, const struct tth *tth, filesize_t size, time_t mtime)
void add_persistent_cache_entry (const char *filename, filesize_t size, time_t mtime, const struct sha1 *sha1, const struct tth *tth)
 Add an entry to the persistent cache.
void dump_cache_one_entry (gpointer unused_key, gpointer value, gpointer udata)
 Dump one (in-memory) cache into the persistent cache.
void dump_cache (gboolean force)
 Dump the whole in-memory cache onto disk.
void parse_and_append_cache_entry (char *line)
 This function is used to read the disk cache into memory.
void sha1_read_cache (void)
 Read the whole persistent cache into memory.
gboolean huge_update_hashes (struct shared_file *sf, const struct sha1 *sha1, const struct tth *tth)
 Asynchronous computation of hash value.
gboolean huge_need_sha1 (struct shared_file *sf)
 Get the next file waiting for its hash to be computed from the queue (actually a stack).
gboolean huge_verify_callback (const struct verify *ctx, enum verify_status status, void *user_data)
 External interface.
void queue_shared_file_for_sha1_computation (struct shared_file *sf)
 Put the shared file on the stack of the things to do.
gboolean cached_entry_up_to_date (const struct sha1_cache_entry *cache_entry, const struct shared_file *sf)
 Check to see if an (in-memory) entry cache is up to date.
gboolean sha1_is_cached (const struct shared_file *sf)
 External interface to check whether the sha1 for shared_file is known.
gboolean request_sha1 (struct shared_file *sf)
 External interface to call for getting the hash for a shared_file.
void huge_init (void)
 Call this function at the beginning.
gboolean cache_free_entry (gpointer unused_key, gpointer v, gpointer unused_udata)
 Free SHA1 cache entry.
void huge_close (void)
 Call this when servent is shutdown.
gboolean huge_improbable_sha1 (const gchar *buf, size_t len)
 Test whether the SHA1 in its base32/binary form is improbable.
gboolean huge_sha1_extract32 (const gchar *buf, size_t len, struct sha1 *sha1, gconstpointer header)
 Validate `len' bytes starting from `buf' as a proper base32 encoding of a SHA1 hash, and write decoded value in `sha1'.
void huge_collect_locations (const struct sha1 *sha1, header_t *header)
 Parse the "X-Gnutella-Alternate-Location" header if present to learn about other sources for this file.

Variables

GHashTable * sha1_cache
gboolean cache_dirty
 cache_dirty means that in-core cache is different from the one on disk when TRUE.
time_t cache_dumped
const char sha1_persistent_cache_file_header []
 Disk cache.


Function Documentation

void add_persistent_cache_entry const char *  filename,
filesize_t  size,
time_t  mtime,
const struct sha1 sha1,
const struct tth tth
[static]
 

Add an entry to the persistent cache.

void add_volatile_cache_entry const char *  filename,
filesize_t  size,
time_t  mtime,
const struct sha1 sha1,
const struct tth tth,
gboolean  known_to_be_shared
[static]
 

Add a new entry to the in-memory cache.

void cache_entry_print FILE *  f,
const char *  filename,
const struct sha1 sha1,
const struct tth tth,
filesize_t  size,
time_t  mtime
[static]
 

gboolean cache_free_entry gpointer  unused_key,
gpointer  v,
gpointer  unused_udata
[static]
 

Free SHA1 cache entry.

gboolean cached_entry_up_to_date const struct sha1_cache_entry cache_entry,
const struct shared_file sf
[static]
 

Check to see if an (in-memory) entry cache is up to date.

Returns:
true (in the C sense) if it is, or false otherwise.

void dump_cache gboolean  force  )  [static]
 

Dump the whole in-memory cache onto disk.

void dump_cache_one_entry gpointer  unused_key,
gpointer  value,
gpointer  udata
[static]
 

Dump one (in-memory) cache into the persistent cache.

This is a callback called by dump_cache to dump the whole in-memory cache onto disk.

void huge_close void   ) 
 

Call this when servent is shutdown.

void huge_collect_locations const struct sha1 sha1,
header_t header
 

Parse the "X-Gnutella-Alternate-Location" header if present to learn about other sources for this file.

gboolean huge_improbable_sha1 const gchar *  buf,
size_t  len
 

Test whether the SHA1 in its base32/binary form is improbable.

This is used to detect "urn:sha1:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" and things using the same pattern with other letters, as being rather improbable hashes.

void huge_init void   ) 
 

Call this function at the beginning.

gboolean huge_need_sha1 struct shared_file sf  )  [static]
 

Get the next file waiting for its hash to be computed from the queue (actually a stack).

Returns:
this file.

gboolean huge_sha1_extract32 const gchar *  buf,
size_t  len,
struct sha1 sha1,
gconstpointer  header
 

Validate `len' bytes starting from `buf' as a proper base32 encoding of a SHA1 hash, and write decoded value in `sha1'.

Also make sure that the SHA1 is not an improbable value.

`header' is the header of the packet where we found the SHA1, so that we may trace errors if needed.

When `check_old' is true, check the encoding against an earlier version of the base32 alphabet.

Returns:
TRUE if the SHA1 was valid and properly decoded, FALSE on error.

gboolean huge_update_hashes struct shared_file sf,
const struct sha1 sha1,
const struct tth tth
 

Asynchronous computation of hash value.

gboolean huge_verify_callback const struct verify ctx,
enum verify_status  status,
void *  user_data
[static]
 

External interface.

void parse_and_append_cache_entry char *  line  )  [static]
 

This function is used to read the disk cache into memory.

It must be passed one line from the cache (ending with '
'). It performs all the syntactic processing to extract the fields from the line and calls add_volatile_cache_entry() to append the record to the in-memory cache.

void queue_shared_file_for_sha1_computation struct shared_file sf  )  [static]
 

Put the shared file on the stack of the things to do.

Activate the timer if this wasn't done already.

gboolean request_sha1 struct shared_file sf  ) 
 

External interface to call for getting the hash for a shared_file.

Returns:
if shared_file_remove() was called, FALSE is returned and "sf" is no longer valid. Otherwise TRUE is returned.

gboolean sha1_is_cached const struct shared_file sf  ) 
 

External interface to check whether the sha1 for shared_file is known.

void sha1_read_cache void   )  [static]
 

Read the whole persistent cache into memory.

void update_volatile_cache struct sha1_cache_entry item,
filesize_t  size,
time_t  mtime,
const struct sha1 sha1,
const struct tth tth
[static]
 

Takes an in-memory cached entry, and update its content.


Variable Documentation

gboolean cache_dirty [static]
 

cache_dirty means that in-core cache is different from the one on disk when TRUE.

time_t cache_dumped [static]
 

GHashTable* sha1_cache [static]
 

const char sha1_persistent_cache_file_header[] [static]
 

Initial value:

"#\n"
"# gtk-gnutella SHA1 cache file.\n"
"# This file is automatically generated.\n"
"# Format is: URN<TAB>file_size<TAB>file_mtime<TAB>file_name\n"
"# Comment lines start with a sharp (#)\n"
"#\n"
"\n"
Disk cache.


Generated on Sat Jun 30 17:53:28 2007 for gtk-gnutella by  doxygen 1.3.9.1