2007-09-20 16:32:01 +00:00
|
|
|
/*
|
2008-12-16 00:20:44 +00:00
|
|
|
* This file Copyright (C) 2007-2008 Charles Kerr <charles@transmissionbt.com>
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2007-09-20 16:32:01 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
|
|
|
#error only libtransmission should #include this header.
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#ifndef TR_PEER_IO_H
|
|
|
|
#define TR_PEER_IO_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
|
|
|
struct evbuffer;
|
2008-12-02 03:41:58 +00:00
|
|
|
struct tr_address;
|
2008-11-24 04:21:23 +00:00
|
|
|
struct tr_bandwidth;
|
2007-09-20 16:32:01 +00:00
|
|
|
struct tr_crypto;
|
|
|
|
typedef struct tr_peerIo tr_peerIo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-12-14 11:21:11 +00:00
|
|
|
tr_peerIo* tr_peerIoNewOutgoing( tr_session * session,
|
2008-12-02 03:41:58 +00:00
|
|
|
const struct tr_address * addr,
|
|
|
|
tr_port port,
|
|
|
|
const uint8_t * torrentHash );
|
2008-11-17 04:00:57 +00:00
|
|
|
|
2008-12-14 11:21:11 +00:00
|
|
|
tr_peerIo* tr_peerIoNewIncoming( tr_session * session,
|
2008-12-02 03:41:58 +00:00
|
|
|
const struct tr_address * addr,
|
|
|
|
tr_port port,
|
|
|
|
int socket );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-02 03:41:58 +00:00
|
|
|
void tr_peerIoFree ( tr_peerIo * io );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-21 18:15:00 +00:00
|
|
|
tr_bool tr_isPeerIo ( const tr_peerIo * io );
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-12-05 22:56:19 +00:00
|
|
|
void tr_peerIoEnableLTEP( tr_peerIo * io, tr_bool flag );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-05 22:56:19 +00:00
|
|
|
tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-12-05 22:56:19 +00:00
|
|
|
void tr_peerIoEnableFEXT( tr_peerIo * io, tr_bool flag );
|
2008-12-02 17:10:54 +00:00
|
|
|
|
2008-12-05 22:56:19 +00:00
|
|
|
tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io );
|
2008-12-02 17:10:54 +00:00
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-12-02 03:41:58 +00:00
|
|
|
tr_session* tr_peerIoGetSession ( tr_peerIo * io );
|
2007-09-30 23:55:49 +00:00
|
|
|
|
2008-12-02 03:41:58 +00:00
|
|
|
const char* tr_peerIoAddrStr( const struct tr_address * addr,
|
|
|
|
tr_port port );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-02 03:41:58 +00:00
|
|
|
const char* tr_peerIoGetAddrStr( const tr_peerIo * io );
|
|
|
|
|
|
|
|
const struct tr_address * tr_peerIoGetAddress( const tr_peerIo * io,
|
|
|
|
tr_port * port );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
const uint8_t* tr_peerIoGetTorrentHash( tr_peerIo * io );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_peerIoHasTorrentHash( const tr_peerIo * io );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-10-23 02:37:21 +00:00
|
|
|
void tr_peerIoSetTorrentHash( tr_peerIo * io,
|
2008-09-23 19:11:04 +00:00
|
|
|
const uint8_t * hash );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_peerIoReconnect( tr_peerIo * io );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
tr_bool tr_peerIoIsIncoming( const tr_peerIo * io );
|
2008-01-11 02:09:20 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_peerIoGetAge( const tr_peerIo * io );
|
2007-10-11 03:54:33 +00:00
|
|
|
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_peerIoSetPeersId( tr_peerIo * io,
|
|
|
|
const uint8_t * peer_id );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
const uint8_t* tr_peerIoGetPeersId( const tr_peerIo * io );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-09-19 17:03:25 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
READ_NOW,
|
|
|
|
READ_LATER,
|
|
|
|
READ_ERR
|
|
|
|
}
|
|
|
|
ReadState;
|
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
typedef ReadState ( *tr_can_read_cb )( tr_peerIo * io,
|
2008-11-25 21:35:17 +00:00
|
|
|
void * user_data,
|
|
|
|
size_t * setme_piece_byte_count );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-11-25 21:35:17 +00:00
|
|
|
typedef void ( *tr_did_write_cb )( tr_peerIo * io,
|
|
|
|
size_t bytesWritten,
|
|
|
|
int wasPieceData,
|
|
|
|
void * userData );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
typedef void ( *tr_net_error_cb )( tr_peerIo * io,
|
2008-11-25 21:35:17 +00:00
|
|
|
short what,
|
|
|
|
void * userData );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-11-17 04:00:57 +00:00
|
|
|
void tr_peerIoSetIOFuncs ( tr_peerIo * io,
|
|
|
|
tr_can_read_cb readcb,
|
|
|
|
tr_did_write_cb writecb,
|
|
|
|
tr_net_error_cb errcb,
|
|
|
|
void * user_data );
|
2008-10-23 02:37:21 +00:00
|
|
|
|
2008-11-17 04:00:57 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2008-10-23 02:37:21 +00:00
|
|
|
|
2008-11-17 04:00:57 +00:00
|
|
|
void tr_peerIoWrite ( tr_peerIo * io,
|
|
|
|
const void * writeme,
|
|
|
|
size_t writemeLen,
|
|
|
|
int isPieceData );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-11-17 04:00:57 +00:00
|
|
|
void tr_peerIoWriteBuf ( tr_peerIo * io,
|
|
|
|
struct evbuffer * buf,
|
|
|
|
int isPieceData );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
|
|
|
struct tr_crypto* tr_peerIoGetCrypto( tr_peerIo * io );
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
/* these match the values in MSE's crypto_select */
|
2008-09-23 19:11:04 +00:00
|
|
|
PEER_ENCRYPTION_NONE = ( 1 << 0 ),
|
|
|
|
PEER_ENCRYPTION_RC4 = ( 1 << 1 )
|
2007-09-20 16:32:01 +00:00
|
|
|
}
|
|
|
|
EncryptionMode;
|
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoSetEncryption( tr_peerIo * io,
|
|
|
|
int encryptionMode );
|
|
|
|
|
|
|
|
int tr_peerIoIsEncrypted( const tr_peerIo * io );
|
|
|
|
|
|
|
|
void tr_peerIoWriteBytes( tr_peerIo * io,
|
|
|
|
struct evbuffer * outbuf,
|
|
|
|
const void * bytes,
|
|
|
|
size_t byteCount );
|
|
|
|
|
|
|
|
void tr_peerIoWriteUint8( tr_peerIo * io,
|
|
|
|
struct evbuffer * outbuf,
|
|
|
|
uint8_t writeme );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoWriteUint16( tr_peerIo * io,
|
|
|
|
struct evbuffer * outbuf,
|
|
|
|
uint16_t writeme );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoWriteUint32( tr_peerIo * io,
|
|
|
|
struct evbuffer * outbuf,
|
|
|
|
uint32_t writeme );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoReadBytes( tr_peerIo * io,
|
|
|
|
struct evbuffer * inbuf,
|
|
|
|
void * bytes,
|
|
|
|
size_t byteCount );
|
2007-09-26 14:42:03 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoReadUint8( tr_peerIo * io,
|
|
|
|
struct evbuffer * inbuf,
|
|
|
|
uint8_t * setme );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoReadUint16( tr_peerIo * io,
|
|
|
|
struct evbuffer * inbuf,
|
|
|
|
uint16_t * setme );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoReadUint32( tr_peerIo * io,
|
|
|
|
struct evbuffer * inbuf,
|
|
|
|
uint32_t * setme );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoDrain( tr_peerIo * io,
|
|
|
|
struct evbuffer * inbuf,
|
|
|
|
size_t byteCount );
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-09-26 14:42:03 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
size_t tr_peerIoGetWriteBufferSpace( const tr_peerIo * io );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoSetBandwidth( tr_peerIo * io,
|
|
|
|
struct tr_bandwidth * bandwidth );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
void tr_peerIoBandwidthUsed( tr_peerIo * io,
|
|
|
|
tr_direction direction,
|
|
|
|
size_t byteCount,
|
|
|
|
int isPieceData );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-17 19:44:24 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-12-20 22:19:34 +00:00
|
|
|
tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io,
|
|
|
|
tr_direction direction );
|
|
|
|
|
|
|
|
void tr_peerIoSetEnabled( tr_peerIo * io,
|
|
|
|
tr_direction dir,
|
|
|
|
tr_bool isEnabled );
|
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
int tr_peerIoFlush( tr_peerIo * io,
|
|
|
|
tr_direction dir,
|
|
|
|
size_t byteLimit );
|
2008-09-17 19:44:24 +00:00
|
|
|
|
2008-12-16 22:08:17 +00:00
|
|
|
struct evbuffer * tr_peerIoGetReadBuffer( tr_peerIo * io );
|
2008-09-17 19:44:24 +00:00
|
|
|
|
2008-11-25 21:35:17 +00:00
|
|
|
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
#endif
|