Richard Eckart
#include "common.h"
#include "hosts.h"
#include "hcache.h"
#include "pcache.h"
#include "nodes.h"
#include "settings.h"
#include "bogons.h"
#include "hostiles.h"
#include "lib/bg.h"
#include "lib/file.h"
#include "lib/hashlist.h"
#include "lib/tm.h"
#include "lib/walloc.h"
#include "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "lib/override.h"
Data Structures | |
struct | hostcache_entry |
An entry within the hostcache. More... | |
struct | hostcache |
A hostcache table. More... | |
struct | read_ctx |
Defines | |
#define | MIN_RESERVE_SIZE 1024 /**< we'd like that many pongs in reserve */ |
we'd like that many pongs in reserve | |
#define | NO_METADATA GINT_TO_POINTER(1) |
No metadata for host. | |
#define | HALF_PRUNE(x) |
#define | READ_MAGIC 0x3d00003d |
#define | HOST_READ_CNT 20 /**< Amount of hosts to read each tick */ |
Amount of hosts to read each tick. | |
Typedefs | |
typedef hostcache_entry | hostcache_entry_t |
An entry within the hostcache. | |
typedef hostcache | hostcache_t |
A hostcache table. | |
Enumerations | |
enum | { HCACHE_ALREADY_CONNECTED, HCACHE_INVALID_HOST, HCACHE_LOCAL_INSTANCE, HCACHE_STATS_MAX } |
Functions | |
RCSID ("$Id:hcache.c, v 1.31 2005/11/09 19:16:53 cbiere Exp $") | |
void | start_mass_update (hostcache_t *hc) |
Initiate mass update of host cache. | |
void | stop_mass_update (hostcache_t *hc) |
End mass update of host cache. | |
void | hcache_update_low_on_pongs (void) |
hostcache_entry_t * | hce_alloc (void) |
void | hce_free (struct hostcache_entry *hce) |
void | hcache_dump_info (const struct hostcache *hc, const gchar *what) |
Output contents information about a hostcache. | |
gboolean | hcache_ht_get (const host_addr_t addr, guint16 port, gnet_host_t **h, hostcache_entry_t **e) |
Get information about the host entry, both the host and the metadata. | |
hostcache_entry_t * | hcache_ht_add (hcache_type_t type, gnet_host_t *host) |
Add host to the hash table host cache. | |
void | hcache_ht_remove (gnet_host_t *host) |
Remove host from the hash table host cache. | |
hostcache_entry_t * | hcache_get_metadata (gnet_host_t *host) |
Get metadata for host. | |
gboolean | hcache_node_is_bad (const host_addr_t addr) |
void | hcache_move_entries (hostcache_t *to, hostcache_t *from) |
Move entries from one hostcache to another. | |
gboolean | hcache_require_caught (hostcache_t *hc) |
Make sure we have some host available in HCACHE_FRESH_ANY and HCACHE_FRESH_ULTRA. | |
void | hcache_unlink_host (hostcache_t *hc, gnet_host_t *host) |
Remove host from a hostcache. | |
const gchar * | hcache_type_to_string (hcache_type_t type) |
Convert host cache type to string. | |
const gchar * | host_type_to_string (host_type_t type) |
Convert host type to string. | |
gint32 | hcache_slots_left (hcache_type_t type) |
gboolean | hcache_add (hcache_type_t type, const host_addr_t addr, guint16 port, const gchar *what) |
Register a host. | |
gboolean | hcache_add_caught (host_type_t type, const host_addr_t addr, guint16 port, const gchar *what) |
Add a caught (fresh) host to the right list depending on the host type. | |
gboolean | hcache_add_valid (host_type_t type, const host_addr_t addr, guint16 port, const gchar *what) |
Add a valid host to the right list depending on the host type. | |
void | hcache_remove (gnet_host_t *h) |
Remove host from cache. | |
gboolean | hcache_is_low (host_type_t type) |
Do we have less that our mimumum amount of hosts in the cache? | |
void | hcache_remove_all (hostcache_t *hc) |
Remove all entries from hostcache. | |
void | hcache_clear_host_type (host_type_t type) |
Clear the whole host cache for a host type and the pong cache of the same type. | |
void | hcache_clear (hcache_type_t type) |
Clear the whole host cache but does not clear the pong caches. | |
gint | hcache_size (host_type_t type) |
guint32 | hcache_expire_cache (hostcache_t *hc, time_t now) |
Expire hosts from a single hostlist in a hostcache. | |
guint32 | hcache_expire_all (time_t now) |
Expire hosts from the HL_BUSY, HL_TIMEOUT and HL_UNSTABLE lists and remove them from the hosts hashtable too. | |
void | hcache_prune (hcache_type_t type) |
Remove hosts that exceed our maximum. | |
gint | hcache_fill_caught_array (host_type_t type, gnet_host_t *hosts, gint hcount) |
Fill `hosts', an array of `hcount' hosts already allocated with at most `hcount' hosts from out caught list, without removing those hosts from the list. | |
gboolean | hcache_find_nearby (host_type_t type, host_addr_t *addr, guint16 *port) |
Finds a host in either the pong_cache or the host_cache that is in one of the local networks. | |
void | hcache_get_caught (host_type_t type, host_addr_t *addr, guint16 *port) |
Get host IP/port information from our caught host list, or from the recent pong cache, in alternance. | |
hostcache_t * | hcache_alloc (hcache_type_t type, gnet_property_t reading, gnet_property_t catcher, gchar *name) |
Allocate hostcache of type `type'. | |
void | hcache_free (hostcache_t *hc) |
Dispose of the hostcache. | |
void | read_ctx_free (gpointer u) |
Dispose of the read context. | |
void | read_done (hostcache_t *hc) |
Read is finished. | |
bgret_t | read_step (gpointer unused_h, gpointer u, gint ticks) |
One reading step. | |
void | bg_reader_done (gpointer unused_h, gpointer ctx, bgstatus_t unused_status, gpointer unused_arg) |
Invoked when the task is completed. | |
void | hcache_retrieve (hostcache_t *hc, const gchar *filename) |
Loads caught hosts from text file. | |
void | hcache_write (FILE *f, hostcache_t *hc) |
Write all data from cache to supplied file. | |
void | hcache_store (hcache_type_t type, const gchar *filename, hcache_type_t extra) |
Persist hostcache to disk. | |
void | hcache_get_stats (hcache_stats_t *s) |
Get statistical information about the caches. | |
void | hcache_timer (time_t now) |
Host cache timer. | |
void | hcache_init (void) |
Initialize host caches. | |
void | hcache_retrieve_all (void) |
Load hostcache data from disk. | |
void | hcache_store_if_dirty (host_type_t type) |
Save hostcache data to disk, for the relevant host type. | |
gboolean | hcache_read_finished (void) |
Check whether the host caches are completely read. | |
void | hcache_shutdown (void) |
Shutdown host caches. | |
void | hcache_close (void) |
Destroy all host caches. | |
Variables | |
hostcache_t * | caches [HCACHE_MAX] |
gboolean | hcache_close_running = FALSE |
const gchar *const | names [HCACHE_MAX] |
Names of the host caches. | |
const gchar *const | host_type_names [HOST_MAX] |
gpointer | bg_reader [HCACHE_MAX] |
guint | stats [HCACHE_STATS_MAX] |
GHashTable * | ht_known_hosts = NULL |
Hashtable: IP/Port -> Metadata. |
|
Value: do { \ if (hc->host_count < caches[x]->host_count) \ hc = caches[x]; \ } while (0) |
|
Amount of hosts to read each tick.
|
|
we'd like that many pongs in reserve
|
|
No metadata for host.
|
|
|
|
An entry within the hostcache. We don't really store the IP/port, as those are stored in the key of hash table recording all known hosts. Rather, we store "metadata" about the host. |
|
A hostcache table.
|
|
|
|
Invoked when the task is completed.
|
|
Register a host. If a host is already on the known hosts hashtable, it will not be registered. Otherwise it will be added to the hashtable of known hosts and added to one of the host lists as indicated by the "list" parameter. Sanity checks are only applied when the host is added to HL_CAUGHT, since when a host is added to any of the other lists it must have been in HL_CAUGHT or in the pong-cache before.
|
|
Add a caught (fresh) host to the right list depending on the host type.
|
|
Add a valid host to the right list depending on the host type.
|
|
Allocate hostcache of type `type'. The `incache' property is what needs to be updated so that the GUI can display the proper amount of hosts we currently hold. The `maxhosts' variable is the pointer to the variable giving the maximum amount of hosts we can store. The `reading' variable is the property to update to signal whether we're reading the persisted file. |
|
Clear the whole host cache but does not clear the pong caches. Use this to clear the "bad" host caches. |
|
Clear the whole host cache for a host type and the pong cache of the same type. Use this to clear the "ultra" and "any" host caches. |
|
Destroy all host caches.
|
|
Output contents information about a hostcache.
|
|
Expire hosts from the HL_BUSY, HL_TIMEOUT and HL_UNSTABLE lists and remove them from the hosts hashtable too.
|
|
Expire hosts from a single hostlist in a hostcache. Also removes it from the host hashtable.
|
|
Fill `hosts', an array of `hcount' hosts already allocated with at most `hcount' hosts from out caught list, without removing those hosts from the list.
|
|
Finds a host in either the pong_cache or the host_cache that is in one of the local networks.
|
|
Dispose of the hostcache.
|
|
Get host IP/port information from our caught host list, or from the recent pong cache, in alternance.
|
|
Get metadata for host.
|
|
Get statistical information about the caches.
|
|
Add host to the hash table host cache. Also creates a metadata struct unless the host was added to HL_CAUGHT in which case we cannot know anything about the host. Yet we cannot assert that HL_CAUGHT never contains a host with metadata because when HL_CAUGHT becomes empty, move all hosts from HL_VALID to HL_CAUGHT. We can however assert that any host which does not have metadata is in HL_CAUGHT.
|
|
Get information about the host entry, both the host and the metadata.
|
|
Remove host from the hash table host cache.
|
|
Initialize host caches.
|
|
Do we have less that our mimumum amount of hosts in the cache?
|
|
Move entries from one hostcache to another. This only works if the target hostcache is empty. |
|
|
|
Remove hosts that exceed our maximum. This can be called on HCACHE_FRESH_ANY and on HCACHE_FRESH_ULTRA. If too many hosts are in the cache, then it will prune the HCACHE_FRESH_XXX list. Only after HCACHE_FRESH_XXX is empty HCACHE_VALID_XXX will be moved to HCACHE_FRESH_XXX and then it is purged. |
|
Check whether the host caches are completely read. This should be used before contacting a GWebCache at start-up time.
|
|
Remove host from cache. After removing hcache_require_caught is called. |
|
Remove all entries from hostcache.
|
|
Make sure we have some host available in HCACHE_FRESH_ANY and HCACHE_FRESH_ULTRA. If one of the both is empty, all hosts from HCACHE_VALID_XXX are moved to HCACHE_VALID_XXX. When caught on other hcaches than FRESH_ANY and FRESH_ULTRA nothing happens.
|
|
Loads caught hosts from text file.
|
|
Load hostcache data from disk.
|
|
Shutdown host caches.
|
|
|
|
|
|
Persist hostcache to disk. If `extra' is not HCACHE_NONE, it is appended after the dump of `type'. |
|
Save hostcache data to disk, for the relevant host type.
|
|
Host cache timer.
|
|
Convert host cache type to string.
|
|
Remove host from a hostcache.
|
|
|
|
Write all data from cache to supplied file.
|
|
|
|
|
|
Convert host type to string.
|
|
|
|
Dispose of the read context.
|
|
Read is finished.
|
|
One reading step.
|
|
Initiate mass update of host cache. While mass updates are in progress, the hosts_in_catcher property will not be updated. |
|
End mass update of host cache. If a hostcache has already been freed when this function is called, it will not tigger a property update for that hostcache and all of its group (ANY, ULTRA, BAD). |
|
|
|
|
|
|
|
Initial value: { "any", "ultra", } |
|
Hashtable: IP/Port -> Metadata.
|
|
Initial value: { "fresh regular", "valid regular", "fresh ultra", "valid ultra", "timeout", "busy", "unstable", "none", }
|
|
|