ELinks 0.16.1.1
peerwire.c File Reference
#include <errno.h>
#include <sys/types.h>
#include "elinks.h"
#include "config/options.h"
#include "main/select.h"
#include "main/timer.h"
#include "network/connection.h"
#include "network/socket.h"
#include "osdep/osdep.h"
#include "protocol/bittorrent/bittorrent.h"
#include "protocol/bittorrent/common.h"
#include "protocol/bittorrent/connection.h"
#include "protocol/bittorrent/peerconnect.h"
#include "protocol/bittorrent/peerwire.h"
#include "protocol/bittorrent/piececache.h"
#include "protocol/protocol.h"
#include "protocol/uri.h"
#include "util/bitfield.h"
#include "util/memory.h"
#include "util/string.h"
Include dependency graph for peerwire.c:

Macros

#define BITTORRENT_PEER_HANDSHAKE_SIZE   (1 + 19 + 8 + 20 + 20)
#define bittorrent_peer_is_sending(peer)
#define add_to_handshake(handshake, i, data)

Enumerations

enum  bittorrent_handshake_state { BITTORRENT_PEER_HANDSHAKE_OK , BITTORRENT_PEER_HANDSHAKE_ERROR , BITTORRENT_PEER_HANDSHAKE_INFO_HASH , BITTORRENT_PEER_HANDSHAKE_INCOMPLETE }

Functions

static enum bittorrent_state do_send_bittorrent_peer_message (struct bittorrent_peer_connection *peer, struct bittorrent_peer_request *message)
static enum bittorrent_handshake_state do_read_bittorrent_peer_handshake (struct socket *socket, struct read_buffer *buffer)
static void queue_bittorrent_peer_connection_requests (struct bittorrent_peer_connection *peer)
void update_bittorrent_peer_connection_state (struct bittorrent_peer_connection *peer)
static double get_bittorrent_rate (struct bittorrent_peer_stats *stats, time_t now, double rate, uint32_t loaded)
void update_bittorrent_peer_connection_stats (struct bittorrent_peer_connection *peer, uint32_t downloaded, uint32_t have_piece, uint32_t uploaded)
static void sent_bittorrent_peer_message (struct socket *socket)
static void add_bittorrent_peer_integer (struct string *string, uint32_t integer)
void send_bittorrent_peer_message (struct bittorrent_peer_connection *peer, bittorrent_message_id_TT message_id,...)
static uint32_t get_bittorrent_peer_integer (struct read_buffer *buffer, int offset)
static bittorrent_message_id_T check_bittorrent_peer_message (struct bittorrent_peer_connection *peer, struct read_buffer *buffer, uint32_t *length)
static enum bittorrent_state read_bittorrent_peer_message (struct bittorrent_peer_connection *peer, bittorrent_message_id_T message_id, struct read_buffer *buffer, uint32_t message_length, int *write_errno)
static void read_bittorrent_peer_data (struct socket *socket, struct read_buffer *buffer)
static void sent_bittorrent_peer_handshake (struct socket *socket)
void send_bittorrent_peer_handshake (struct socket *socket)
static enum bittorrent_handshake_state check_bittorrent_peer_handshake (struct bittorrent_peer_connection *peer, struct read_buffer *buffer)
void read_bittorrent_peer_handshake (struct socket *socket, struct read_buffer *buffer)

Variables

static const bittorrent_id_T BITTORRENT_ID = {'\023','B','i','t','T','o','r','r','e','n','t',' ','p','r','o','t','o','c','o','l'}

Macro Definition Documentation

◆ add_to_handshake

#define add_to_handshake ( handshake,
i,
data )
Value:
do { \
memcpy((handshake) + (i), data, sizeof(data)); \
i += sizeof(data); \
} while (0)
i
Definition uni_7b.inc:369

◆ BITTORRENT_PEER_HANDSHAKE_SIZE

#define BITTORRENT_PEER_HANDSHAKE_SIZE   (1 + 19 + 8 + 20 + 20)

◆ bittorrent_peer_is_sending

#define bittorrent_peer_is_sending ( peer)
Value:
((peer)->socket->write_buffer)

Enumeration Type Documentation

◆ bittorrent_handshake_state

Enumerator
BITTORRENT_PEER_HANDSHAKE_OK 
BITTORRENT_PEER_HANDSHAKE_ERROR 
BITTORRENT_PEER_HANDSHAKE_INFO_HASH 
BITTORRENT_PEER_HANDSHAKE_INCOMPLETE 

Function Documentation

◆ add_bittorrent_peer_integer()

void add_bittorrent_peer_integer ( struct string * string,
uint32_t integer )
inlinestatic

◆ check_bittorrent_peer_handshake()

enum bittorrent_handshake_state check_bittorrent_peer_handshake ( struct bittorrent_peer_connection * peer,
struct read_buffer * buffer )
static

◆ check_bittorrent_peer_message()

bittorrent_message_id_T check_bittorrent_peer_message ( struct bittorrent_peer_connection * peer,
struct read_buffer * buffer,
uint32_t * length )
static

◆ do_read_bittorrent_peer_handshake()

enum bittorrent_handshake_state do_read_bittorrent_peer_handshake ( struct socket * socket,
struct read_buffer * buffer )
static

◆ do_send_bittorrent_peer_message()

enum bittorrent_state do_send_bittorrent_peer_message ( struct bittorrent_peer_connection * peer,
struct bittorrent_peer_request * message )
static

◆ get_bittorrent_peer_integer()

uint32_t get_bittorrent_peer_integer ( struct read_buffer * buffer,
int offset )
inlinestatic

◆ get_bittorrent_rate()

double get_bittorrent_rate ( struct bittorrent_peer_stats * stats,
time_t now,
double rate,
uint32_t loaded )
inlinestatic

◆ queue_bittorrent_peer_connection_requests()

void queue_bittorrent_peer_connection_requests ( struct bittorrent_peer_connection * peer)
static

◆ read_bittorrent_peer_data()

void read_bittorrent_peer_data ( struct socket * socket,
struct read_buffer * buffer )
static

◆ read_bittorrent_peer_handshake()

void read_bittorrent_peer_handshake ( struct socket * socket,
struct read_buffer * buffer )

◆ read_bittorrent_peer_message()

enum bittorrent_state read_bittorrent_peer_message ( struct bittorrent_peer_connection * peer,
bittorrent_message_id_T message_id,
struct read_buffer * buffer,
uint32_t message_length,
int * write_errno )
static

◆ send_bittorrent_peer_handshake()

void send_bittorrent_peer_handshake ( struct socket * socket)

◆ send_bittorrent_peer_message()

void send_bittorrent_peer_message ( struct bittorrent_peer_connection * peer,
bittorrent_message_id_TT message_id,
... )

◆ sent_bittorrent_peer_handshake()

void sent_bittorrent_peer_handshake ( struct socket * socket)
static

◆ sent_bittorrent_peer_message()

void sent_bittorrent_peer_message ( struct socket * socket)
static

◆ update_bittorrent_peer_connection_state()

void update_bittorrent_peer_connection_state ( struct bittorrent_peer_connection * peer)

◆ update_bittorrent_peer_connection_stats()

void update_bittorrent_peer_connection_stats ( struct bittorrent_peer_connection * peer,
uint32_t downloaded,
uint32_t have_piece,
uint32_t uploaded )

Variable Documentation

◆ BITTORRENT_ID

const bittorrent_id_T BITTORRENT_ID = {'\023','B','i','t','T','o','r','r','e','n','t',' ','p','r','o','t','o','c','o','l'}
static