ELinks 0.16.1.1
piececache.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "elinks.h"
#include "cache/cache.h"
#include "main/select.h"
#include "network/connection.h"
#include "osdep/osdep.h"
#include "protocol/bittorrent/bencoding.h"
#include "protocol/bittorrent/common.h"
#include "protocol/bittorrent/connection.h"
#include "protocol/bittorrent/dialogs.h"
#include "protocol/bittorrent/peerwire.h"
#include "protocol/bittorrent/piececache.h"
#include "protocol/bittorrent/tracker.h"
#include "util/bitfield.h"
#include "util/error.h"
#include "util/file.h"
#include "util/lists.h"
#include "util/memory.h"
#include "util/random.h"
#include "util/string.h"
Include dependency graph for piececache.c:

Macros

#define BITTORRENT_PIECE_UNDEF   UINT_MAX
#define BITTORRENT_PIECE_RARITY_UNDEF   USHRT_MAX
#define find_local_bittorrent_peer_request(peer, request)

Enumerations

enum  bittorrent_translation { BITTORRENT_READ , BITTORRENT_WRITE , BITTORRENT_SEEK }

Functions

static void set_bittorrent_piece_cache_remaining (struct bittorrent_piece_cache *cache, uint32_t piece, int remaining)
static void set_bittorrent_piece_cache_completed (struct bittorrent_piece_cache *cache, uint32_t piece)
static void handle_bittorrent_mode_changes (struct bittorrent_connection *bittorrent)
static struct bittorrent_peer_requestfind_bittorrent_free_list_peer_request (struct bittorrent_piece_cache *cache, struct bittorrent_peer_connection *peer)
static int randomize (size_t scale)
static uint32_t find_random_in_bittorrent_piece_cache (struct bittorrent_piece_cache *cache, struct bittorrent_peer_connection *peer)
static uint32_t find_rarest_in_bittorrent_piece_cache (struct bittorrent_piece_cache *cache, struct bittorrent_peer_connection *peer)
static struct bittorrent_peer_requestfind_clonable_bittorrent_peer_request (struct bittorrent_peer_connection *peer)
static struct bittorrent_peer_requestclone_bittorrent_peer_request (struct bittorrent_peer_request *request)
static struct bittorrent_peer_requestadd_piece_to_bittorrent_free_list (struct bittorrent_piece_cache *cache, struct bittorrent_connection *bittorrent, uint32_t piece)
struct bittorrent_peer_requestfind_bittorrent_peer_request (struct bittorrent_peer_connection *peer)
static void clear_cloned_bittorrent_peer_request (struct bittorrent_connection *bittorrent, struct bittorrent_peer_request *request)
static void add_request_to_bittorrent_piece_cache (struct bittorrent_connection *bittorrent, struct bittorrent_peer_request *request)
void add_requests_to_bittorrent_piece_cache (struct bittorrent_peer_connection *peer, struct bittorrent_peer_status *status)
void update_bittorrent_piece_cache (struct bittorrent_peer_connection *peer, uint32_t piece)
void update_bittorrent_piece_cache_from_bitfield (struct bittorrent_peer_connection *peer)
void remove_bittorrent_peer_from_piece_cache (struct bittorrent_peer_connection *peer)
static enum bittorrent_state create_bittorrent_path (char *path)
static void remove_bittorrent_path (struct bittorrent_meta *meta, char *path)
static char * get_bittorrent_file_name (struct bittorrent_meta *meta, struct bittorrent_file *file)
static int open_bittorrent_file (struct bittorrent_meta *meta, struct bittorrent_file *file, enum bittorrent_translation trans, off_t offset)
static enum bittorrent_state bittorrent_file_piece_translation (struct bittorrent_meta *meta, struct bittorrent_piece_cache *cache, struct bittorrent_piece_cache_entry *entry, uint32_t piece, enum bittorrent_translation trans)
static void cancel_cloned_bittorrent_peer_requests (struct bittorrent_connection *bittorrent, struct bittorrent_peer_request *request)
enum bittorrent_state add_to_bittorrent_piece_cache (struct bittorrent_peer_connection *peer, uint32_t piece, uint32_t offset, char *data, uint32_t datalen, int *write_errno)
char * get_bittorrent_piece_cache_data (struct bittorrent_connection *bittorrent, uint32_t piece)
static void done_bittorrent_resume (struct bittorrent_piece_cache *cache)
static int prepare_partial_bittorrent_download (struct bittorrent_connection *bittorrent)
static void end_bittorrent_resume (struct bittorrent_connection *bittorrent)
static void bittorrent_resume_writer (void *data, int fd)
static void bittorrent_resume_reader (struct bittorrent_connection *bittorrent)
static void start_bittorrent_resume (struct bittorrent_connection *bittorrent, struct bittorrent_const_string *meta)
void update_bittorrent_piece_cache_state (struct bittorrent_connection *bittorrent)
enum bittorrent_state init_bittorrent_piece_cache (struct bittorrent_connection *bittorrent, struct bittorrent_const_string *metafile)
static void delete_bittorrent_files (struct bittorrent_connection *bittorrent)
void done_bittorrent_piece_cache (struct bittorrent_connection *bittorrent)

Macro Definition Documentation

◆ BITTORRENT_PIECE_RARITY_UNDEF

#define BITTORRENT_PIECE_RARITY_UNDEF   USHRT_MAX

◆ BITTORRENT_PIECE_UNDEF

#define BITTORRENT_PIECE_UNDEF   UINT_MAX

◆ find_local_bittorrent_peer_request

#define find_local_bittorrent_peer_request ( peer,
request )
Value:
get_bittorrent_peer_request(&(peer)->local, (request)->piece, \
(request)->offset, (request)->length)
struct bittorrent_peer_request * get_bittorrent_peer_request(struct bittorrent_peer_status *status, uint32_t piece, uint32_t offset, uint32_t length)
Definition common.c:264

Enumeration Type Documentation

◆ bittorrent_translation

Enumerator
BITTORRENT_READ 
BITTORRENT_WRITE 
BITTORRENT_SEEK 

Function Documentation

◆ add_piece_to_bittorrent_free_list()

struct bittorrent_peer_request * add_piece_to_bittorrent_free_list ( struct bittorrent_piece_cache * cache,
struct bittorrent_connection * bittorrent,
uint32_t piece )
static

◆ add_request_to_bittorrent_piece_cache()

void add_request_to_bittorrent_piece_cache ( struct bittorrent_connection * bittorrent,
struct bittorrent_peer_request * request )
static

◆ add_requests_to_bittorrent_piece_cache()

void add_requests_to_bittorrent_piece_cache ( struct bittorrent_peer_connection * peer,
struct bittorrent_peer_status * status )

◆ add_to_bittorrent_piece_cache()

enum bittorrent_state add_to_bittorrent_piece_cache ( struct bittorrent_peer_connection * peer,
uint32_t piece,
uint32_t offset,
char * data,
uint32_t datalen,
int * write_errno )

◆ bittorrent_file_piece_translation()

enum bittorrent_state bittorrent_file_piece_translation ( struct bittorrent_meta * meta,
struct bittorrent_piece_cache * cache,
struct bittorrent_piece_cache_entry * entry,
uint32_t piece,
enum bittorrent_translation trans )
static

◆ bittorrent_resume_reader()

void bittorrent_resume_reader ( struct bittorrent_connection * bittorrent)
static

◆ bittorrent_resume_writer()

void bittorrent_resume_writer ( void * data,
int fd )
static

◆ cancel_cloned_bittorrent_peer_requests()

void cancel_cloned_bittorrent_peer_requests ( struct bittorrent_connection * bittorrent,
struct bittorrent_peer_request * request )
static

◆ clear_cloned_bittorrent_peer_request()

void clear_cloned_bittorrent_peer_request ( struct bittorrent_connection * bittorrent,
struct bittorrent_peer_request * request )
static

◆ clone_bittorrent_peer_request()

struct bittorrent_peer_request * clone_bittorrent_peer_request ( struct bittorrent_peer_request * request)
static

◆ create_bittorrent_path()

enum bittorrent_state create_bittorrent_path ( char * path)
static

◆ delete_bittorrent_files()

void delete_bittorrent_files ( struct bittorrent_connection * bittorrent)
static

◆ done_bittorrent_piece_cache()

void done_bittorrent_piece_cache ( struct bittorrent_connection * bittorrent)

◆ done_bittorrent_resume()

void done_bittorrent_resume ( struct bittorrent_piece_cache * cache)
static

◆ end_bittorrent_resume()

void end_bittorrent_resume ( struct bittorrent_connection * bittorrent)
static

◆ find_bittorrent_free_list_peer_request()

struct bittorrent_peer_request * find_bittorrent_free_list_peer_request ( struct bittorrent_piece_cache * cache,
struct bittorrent_peer_connection * peer )
static

◆ find_bittorrent_peer_request()

struct bittorrent_peer_request * find_bittorrent_peer_request ( struct bittorrent_peer_connection * peer)

◆ find_clonable_bittorrent_peer_request()

struct bittorrent_peer_request * find_clonable_bittorrent_peer_request ( struct bittorrent_peer_connection * peer)
static

◆ find_random_in_bittorrent_piece_cache()

uint32_t find_random_in_bittorrent_piece_cache ( struct bittorrent_piece_cache * cache,
struct bittorrent_peer_connection * peer )
static

◆ find_rarest_in_bittorrent_piece_cache()

uint32_t find_rarest_in_bittorrent_piece_cache ( struct bittorrent_piece_cache * cache,
struct bittorrent_peer_connection * peer )
static

◆ get_bittorrent_file_name()

char * get_bittorrent_file_name ( struct bittorrent_meta * meta,
struct bittorrent_file * file )
static

◆ get_bittorrent_piece_cache_data()

char * get_bittorrent_piece_cache_data ( struct bittorrent_connection * bittorrent,
uint32_t piece )

◆ handle_bittorrent_mode_changes()

void handle_bittorrent_mode_changes ( struct bittorrent_connection * bittorrent)
static

◆ init_bittorrent_piece_cache()

enum bittorrent_state init_bittorrent_piece_cache ( struct bittorrent_connection * bittorrent,
struct bittorrent_const_string * metafile )

◆ open_bittorrent_file()

int open_bittorrent_file ( struct bittorrent_meta * meta,
struct bittorrent_file * file,
enum bittorrent_translation trans,
off_t offset )
static

◆ prepare_partial_bittorrent_download()

int prepare_partial_bittorrent_download ( struct bittorrent_connection * bittorrent)
static

◆ randomize()

int randomize ( size_t scale)
inlinestatic

◆ remove_bittorrent_path()

void remove_bittorrent_path ( struct bittorrent_meta * meta,
char * path )
static

◆ remove_bittorrent_peer_from_piece_cache()

void remove_bittorrent_peer_from_piece_cache ( struct bittorrent_peer_connection * peer)

◆ set_bittorrent_piece_cache_completed()

void set_bittorrent_piece_cache_completed ( struct bittorrent_piece_cache * cache,
uint32_t piece )
inlinestatic

◆ set_bittorrent_piece_cache_remaining()

void set_bittorrent_piece_cache_remaining ( struct bittorrent_piece_cache * cache,
uint32_t piece,
int remaining )
inlinestatic

◆ start_bittorrent_resume()

void start_bittorrent_resume ( struct bittorrent_connection * bittorrent,
struct bittorrent_const_string * meta )
static

◆ update_bittorrent_piece_cache()

void update_bittorrent_piece_cache ( struct bittorrent_peer_connection * peer,
uint32_t piece )

◆ update_bittorrent_piece_cache_from_bitfield()

void update_bittorrent_piece_cache_from_bitfield ( struct bittorrent_peer_connection * peer)

◆ update_bittorrent_piece_cache_state()

void update_bittorrent_piece_cache_state ( struct bittorrent_connection * bittorrent)