ELinks 0.16.1.1
common.h File Reference
#include "main/timer.h"
#include "network/progress.h"
#include "network/socket.h"
#include "network/state.h"
#include "protocol/protocol.h"
#include "protocol/uri.h"
#include "util/error.h"
#include "util/lists.h"
#include "util/md5.h"
#include "util/sha1.h"
#include "util/time.h"
Include dependency graph for common.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  bittorrent_message
 For showing tracker failure responses to the user. More...
struct  bittorrent_peer_request
 The peer request matches information sent in the request and cancel messages in the peer-wire protocol. More...
struct  bittorrent_peer_status
struct  bittorrent_peer_stats
struct  bittorrent_peer_connection
 Peer connection information. More...
struct  bittorrent_tracker_connection
 This stores info about tracker requests. More...
struct  bittorrent_peer
 Information about peers returned by the tracker. More...
struct  bittorrent_file
 Information about a file in the torrent. More...
struct  bittorrent_meta
 Static information from the .torrent metafile. More...
struct  bittorrent_connection
 This stores info about an active BitTorrent connection. More...
struct  bittorrent_const_string
 Like struct string, except the data is const and not freed via this structure. More...

Macros

#define BITTORRENT_DEFAULT_SHARING_RATE   0.250
 The least acceptable default sharing rate.
#define BITTORRENT_DEFAULT_CHOKE_INTERVAL   10
 The number of seconds between updating the connection state and most importantly choke and unchoke peer connections.
#define BITTORRENT_REQUEST_LENGTH   (1 << 14)
 The length regarded as `‘typical’' by the community wiki specification.
#define BITTORRENT_REQUEST_ACCEPT_LENGTH   (1 << 23)
 The length of requested blocks of pieces should not exceed 2^17 bytes.
#define BITTORRENT_MESSAGE_MAX_SIZE   (1 << 23)
 The maximum size to allow a peer message to have.
#define bittorrent_id_is_empty(id)
 Check if the ID has been set.

Typedefs

typedef sha1_digest_bin_T bittorrent_id_T
 20-byte string ID used for both peer IDs and info-hashes.
typedef signed char bittorrent_message_id_T
typedef int bittorrent_message_id_TT
typedef void(* bittorrent_fetch_callback_T) (void *, struct connection_state, struct bittorrent_const_string *)
typedef unsigned char bittorrent_blacklist_flags_T

Enumerations

enum  bittorrent_state {
  BITTORRENT_STATE_OK , BITTORRENT_STATE_ERROR , BITTORRENT_STATE_REQUEST_FAILURE , BITTORRENT_STATE_OUT_OF_MEM ,
  BITTORRENT_STATE_CACHE_FAILURE , BITTORRENT_STATE_CACHE_RESUME , BITTORRENT_STATE_FILE_MISSING
}
 BitTorrent error states. More...
enum  bittorrent_message_id {
  BITTORRENT_MESSAGE_ERROR = -3 , BITTORRENT_MESSAGE_INCOMPLETE = -2 , BITTORRENT_MESSAGE_KEEP_ALIVE = -1 , BITTORRENT_MESSAGE_CHOKE = 0 ,
  BITTORRENT_MESSAGE_UNCHOKE = 1 , BITTORRENT_MESSAGE_INTERESTED = 2 , BITTORRENT_MESSAGE_NOT_INTERESTED = 3 , BITTORRENT_MESSAGE_HAVE = 4 ,
  BITTORRENT_MESSAGE_BITFIELD = 5 , BITTORRENT_MESSAGE_REQUEST = 6 , BITTORRENT_MESSAGE_PIECE = 7 , BITTORRENT_MESSAGE_CANCEL = 8
}
 BitTorrent peer-wire state and message IDs. More...
enum  bittorrent_tracker_event { BITTORRENT_EVENT_STARTED = 0 , BITTORRENT_EVENT_STOPPED , BITTORRENT_EVENT_COMPLETED , BITTORRENT_EVENT_REGULAR }
 Event state information needed by the tracker. More...
enum  meta_type { BITTORRENT_SINGLE_FILE , BITTORRENT_MULTI_FILE }
enum  bittorrent_connection_mode { BITTORRENT_MODE_PIECELESS , BITTORRENT_MODE_NORMAL , BITTORRENT_MODE_END_GAME , BITTORRENT_MODE_SEEDER }
enum  bittorrent_blacklist_flags { BITTORRENT_BLACKLIST_NONE , BITTORRENT_BLACKLIST_PEER_POOL , BITTORRENT_BLACKLIST_MALICIOUS , BITTORRENT_BLACKLIST_BEHAVIOUR }

Functions

static uint32_t get_bittorrent_piece_length (struct bittorrent_meta *meta, uint32_t piece)
char * get_hexed_bittorrent_id (bittorrent_id_T id)
int bittorrent_piece_is_valid (struct bittorrent_meta *meta, uint32_t piece, char *data, uint32_t datalen)
void init_bittorrent_peer_id (bittorrent_id_T peer_id)
int bittorrent_id_is_known (struct bittorrent_connection *bittorrent, bittorrent_id_T id)
enum bittorrent_state add_peer_to_bittorrent_pool (struct bittorrent_connection *bittorrent, bittorrent_id_T id, int port, const char *ip, int iplen)
struct bittorrent_peerget_peer_from_bittorrent_pool (struct bittorrent_connection *bittorrent, bittorrent_id_T id)
void done_bittorrent_meta (struct bittorrent_meta *meta)
void done_bittorrent_message (struct bittorrent_message *message)
char * get_peer_id (bittorrent_id_T peer)
const char * get_peer_message (bittorrent_message_id_T message_id)
struct bittorrent_peer_requestget_bittorrent_peer_request (struct bittorrent_peer_status *status, uint32_t piece, uint32_t offset, uint32_t length)
void add_bittorrent_peer_request (struct bittorrent_peer_status *status, uint32_t piece, uint32_t offset, uint32_t length)
void del_bittorrent_peer_request (struct bittorrent_peer_status *status, uint32_t piece, uint32_t offset, uint32_t length)
struct bittorrent_fetcherinit_bittorrent_fetch (struct bittorrent_fetcher **fetcher_ref, struct uri *uri, bittorrent_fetch_callback_T callback, void *data, int delete_)
void done_bittorrent_fetch (struct bittorrent_fetcher **fetcher_ref)
void add_bittorrent_blacklist_flags (bittorrent_id_T peer_id, bittorrent_blacklist_flags_T flags)
void del_bittorrent_blacklist_flags (bittorrent_id_T peer_id, bittorrent_blacklist_flags_T flags)
bittorrent_blacklist_flags_T get_bittorrent_blacklist_flags (bittorrent_id_T peer_id)
void done_bittorrent_blacklist (void)

Variables

const bittorrent_id_T BITTORRENT_NULL_ID
 Special peer ID used for determining whether an ID has been set.

Macro Definition Documentation

◆ BITTORRENT_DEFAULT_CHOKE_INTERVAL

#define BITTORRENT_DEFAULT_CHOKE_INTERVAL   10

The number of seconds between updating the connection state and most importantly choke and unchoke peer connections.

◆ BITTORRENT_DEFAULT_SHARING_RATE

#define BITTORRENT_DEFAULT_SHARING_RATE   0.250

The least acceptable default sharing rate.

◆ bittorrent_id_is_empty

#define bittorrent_id_is_empty ( id)
Value:
(!memcmp(id, BITTORRENT_NULL_ID, sizeof(bittorrent_id_T)))
const bittorrent_id_T BITTORRENT_NULL_ID
Special peer ID used for determining whether an ID has been set.
Definition common.c:29
sha1_digest_bin_T bittorrent_id_T
20-byte string ID used for both peer IDs and info-hashes.
Definition common.h:49

Check if the ID has been set.

◆ BITTORRENT_MESSAGE_MAX_SIZE

#define BITTORRENT_MESSAGE_MAX_SIZE   (1 << 23)

The maximum size to allow a peer message to have.

◆ BITTORRENT_REQUEST_ACCEPT_LENGTH

#define BITTORRENT_REQUEST_ACCEPT_LENGTH   (1 << 23)

The length of requested blocks of pieces should not exceed 2^17 bytes.

Used for the protocol.bittorrent.max_request_length option. Bram uses 2^23 here.

◆ BITTORRENT_REQUEST_LENGTH

#define BITTORRENT_REQUEST_LENGTH   (1 << 14)

The length regarded as `‘typical’' by the community wiki specification.

Looks like Bram uses 2^14 here. Used for the protocol.bittorrent.request_length option

Typedef Documentation

◆ bittorrent_blacklist_flags_T

typedef unsigned char bittorrent_blacklist_flags_T

◆ bittorrent_fetch_callback_T

typedef void(* bittorrent_fetch_callback_T) (void *, struct connection_state, struct bittorrent_const_string *)

◆ bittorrent_id_T

20-byte string ID used for both peer IDs and info-hashes.

◆ bittorrent_message_id_T

typedef signed char bittorrent_message_id_T

◆ bittorrent_message_id_TT

Enumeration Type Documentation

◆ bittorrent_blacklist_flags

Enumerator
BITTORRENT_BLACKLIST_NONE 

No blacklisting is in effect.

BITTORRENT_BLACKLIST_PEER_POOL 

Blacklist from peer pool.

BITTORRENT_BLACKLIST_MALICIOUS 

Malicious peer, refuse connection.

BITTORRENT_BLACKLIST_BEHAVIOUR 

Unfair behaviour, refuse connection.

◆ bittorrent_connection_mode

Enumerator
BITTORRENT_MODE_PIECELESS 

The client has no piece to share.

BITTORRENT_MODE_NORMAL 

The client is up- and downloading.

BITTORRENT_MODE_END_GAME 

All remaining pieces are requested.

BITTORRENT_MODE_SEEDER 

The client is only uploading.

◆ bittorrent_message_id

BitTorrent peer-wire state and message IDs.

Enumerator
BITTORRENT_MESSAGE_ERROR 
BITTORRENT_MESSAGE_INCOMPLETE 
BITTORRENT_MESSAGE_KEEP_ALIVE 
BITTORRENT_MESSAGE_CHOKE 
BITTORRENT_MESSAGE_UNCHOKE 
BITTORRENT_MESSAGE_INTERESTED 
BITTORRENT_MESSAGE_NOT_INTERESTED 
BITTORRENT_MESSAGE_HAVE 
BITTORRENT_MESSAGE_BITFIELD 
BITTORRENT_MESSAGE_REQUEST 
BITTORRENT_MESSAGE_PIECE 
BITTORRENT_MESSAGE_CANCEL 

◆ bittorrent_state

BitTorrent error states.

Enumerator
BITTORRENT_STATE_OK 

All is well.

BITTORRENT_STATE_ERROR 

Some error happened.

BITTORRENT_STATE_REQUEST_FAILURE 

Failure from tracker.

BITTORRENT_STATE_OUT_OF_MEM 

Allocation failure.

BITTORRENT_STATE_CACHE_FAILURE 

Cache data access failed.

BITTORRENT_STATE_CACHE_RESUME 

Resume state from disk.

BITTORRENT_STATE_FILE_MISSING 

File does not exist.

◆ bittorrent_tracker_event

Event state information needed by the tracker.

Enumerator
BITTORRENT_EVENT_STARTED 

XXX: Zero, to always send first.

BITTORRENT_EVENT_STOPPED 

Graceful shut down.

BITTORRENT_EVENT_COMPLETED 

Download was completed.

BITTORRENT_EVENT_REGULAR 

Regular (periodical) tracker request.

◆ meta_type

enum meta_type
Enumerator
BITTORRENT_SINGLE_FILE 
BITTORRENT_MULTI_FILE 

Function Documentation

◆ add_bittorrent_blacklist_flags()

void add_bittorrent_blacklist_flags ( bittorrent_id_T peer_id,
bittorrent_blacklist_flags_T flags )

◆ add_bittorrent_peer_request()

void add_bittorrent_peer_request ( struct bittorrent_peer_status * status,
uint32_t piece,
uint32_t offset,
uint32_t length )

◆ add_peer_to_bittorrent_pool()

enum bittorrent_state add_peer_to_bittorrent_pool ( struct bittorrent_connection * bittorrent,
bittorrent_id_T id,
int port,
const char * ip,
int iplen )

◆ bittorrent_id_is_known()

int bittorrent_id_is_known ( struct bittorrent_connection * bittorrent,
bittorrent_id_T id )

◆ bittorrent_piece_is_valid()

int bittorrent_piece_is_valid ( struct bittorrent_meta * meta,
uint32_t piece,
char * data,
uint32_t datalen )

◆ del_bittorrent_blacklist_flags()

void del_bittorrent_blacklist_flags ( bittorrent_id_T peer_id,
bittorrent_blacklist_flags_T flags )

◆ del_bittorrent_peer_request()

void del_bittorrent_peer_request ( struct bittorrent_peer_status * status,
uint32_t piece,
uint32_t offset,
uint32_t length )

◆ done_bittorrent_blacklist()

void done_bittorrent_blacklist ( void )

◆ done_bittorrent_fetch()

void done_bittorrent_fetch ( struct bittorrent_fetcher ** fetcher_ref)

◆ done_bittorrent_message()

void done_bittorrent_message ( struct bittorrent_message * message)

◆ done_bittorrent_meta()

void done_bittorrent_meta ( struct bittorrent_meta * meta)

◆ get_bittorrent_blacklist_flags()

bittorrent_blacklist_flags_T get_bittorrent_blacklist_flags ( bittorrent_id_T peer_id)

◆ get_bittorrent_peer_request()

struct bittorrent_peer_request * get_bittorrent_peer_request ( struct bittorrent_peer_status * status,
uint32_t piece,
uint32_t offset,
uint32_t length )

◆ get_bittorrent_piece_length()

uint32_t get_bittorrent_piece_length ( struct bittorrent_meta * meta,
uint32_t piece )
inlinestatic

◆ get_hexed_bittorrent_id()

char * get_hexed_bittorrent_id ( bittorrent_id_T id)

◆ get_peer_from_bittorrent_pool()

struct bittorrent_peer * get_peer_from_bittorrent_pool ( struct bittorrent_connection * bittorrent,
bittorrent_id_T id )

◆ get_peer_id()

char * get_peer_id ( bittorrent_id_T peer)

◆ get_peer_message()

const char * get_peer_message ( bittorrent_message_id_T message_id)

◆ init_bittorrent_fetch()

struct bittorrent_fetcher * init_bittorrent_fetch ( struct bittorrent_fetcher ** fetcher_ref,
struct uri * uri,
bittorrent_fetch_callback_T callback,
void * data,
int delete_ )

◆ init_bittorrent_peer_id()

void init_bittorrent_peer_id ( bittorrent_id_T peer_id)

Variable Documentation

◆ BITTORRENT_NULL_ID

const bittorrent_id_T BITTORRENT_NULL_ID
extern

Special peer ID used for determining whether an ID has been set.