2006-07-16 19:39:23 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-03-23 08:28:01 +00:00
|
|
|
* Copyright (c) 2005-2007 Transmission authors and contributors
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TR_INTERNAL_H
|
|
|
|
#define TR_INTERNAL_H 1
|
|
|
|
|
2007-07-29 18:11:21 +00:00
|
|
|
|
2007-01-21 08:43:58 +00:00
|
|
|
#ifdef SYS_BEOS
|
|
|
|
/* BeOS doesn't declare vasprintf in its headers, but actually
|
|
|
|
* implements it */
|
2007-07-29 18:11:21 +00:00
|
|
|
extern int vasprintf( char **, const char *, va_list );
|
2007-07-30 13:59:23 +00:00
|
|
|
#include <signal.h>
|
2007-01-21 08:43:58 +00:00
|
|
|
#endif
|
2007-07-29 18:11:21 +00:00
|
|
|
|
2006-10-17 18:48:04 +00:00
|
|
|
#ifdef SYS_BEOS
|
|
|
|
# define socklen_t uint32_t
|
|
|
|
#endif
|
2007-07-29 18:11:21 +00:00
|
|
|
|
2007-07-30 18:04:10 +00:00
|
|
|
#if defined(BEOS_NETSERVER) || defined(__MINGW__)
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef uint16_t tr_port_t;
|
2006-07-16 19:39:23 +00:00
|
|
|
#else
|
2007-07-30 18:04:10 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
typedef in_port_t tr_port_t;
|
2006-07-16 19:39:23 +00:00
|
|
|
#endif
|
|
|
|
|
2007-07-29 18:11:21 +00:00
|
|
|
#define TR_NAME "Transmission"
|
2007-03-23 08:28:01 +00:00
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
#ifndef INADDR_NONE
|
2007-07-29 18:11:21 +00:00
|
|
|
#define INADDR_NONE 0xffffffff
|
2006-09-25 18:37:45 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# define UNUSED __attribute__((unused))
|
2006-09-25 18:37:45 +00:00
|
|
|
# define PRINTF( fmt, args ) __attribute__((format (printf, fmt, args)))
|
2006-07-16 19:39:23 +00:00
|
|
|
#else
|
|
|
|
# define UNUSED
|
2006-09-25 18:37:45 +00:00
|
|
|
# define PRINTF( fmt, args )
|
2006-07-16 19:39:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TR_MAX_PEER_COUNT 60
|
|
|
|
|
2007-01-14 12:00:21 +00:00
|
|
|
typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2007-07-30 18:04:10 +00:00
|
|
|
#include "platform.h" /* thread, lock */
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "peer.h"
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
|
2007-07-16 11:19:44 +00:00
|
|
|
void tr_peerIdNew ( char* buf, int buflen );
|
|
|
|
|
2007-06-26 18:45:03 +00:00
|
|
|
void tr_torrentResetTransferStats( tr_torrent_t * );
|
|
|
|
|
2007-03-29 00:19:09 +00:00
|
|
|
int tr_torrentAddCompact( tr_torrent_t * tor, int from,
|
2007-03-23 08:28:01 +00:00
|
|
|
uint8_t * buf, int count );
|
2007-07-30 18:04:10 +00:00
|
|
|
int tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * );
|
2007-01-21 06:42:05 +00:00
|
|
|
|
2007-06-26 18:45:03 +00:00
|
|
|
void tr_torrentSetHasPiece( tr_torrent_t * tor, int pieceIndex, int has );
|
|
|
|
|
|
|
|
void tr_torrentReaderLock ( const tr_torrent_t * );
|
|
|
|
void tr_torrentReaderUnlock ( const tr_torrent_t * );
|
|
|
|
void tr_torrentWriterLock ( tr_torrent_t * );
|
|
|
|
void tr_torrentWriterUnlock ( tr_torrent_t * );
|
|
|
|
|
2007-07-28 15:43:34 +00:00
|
|
|
/* get the index of this piece's first block */
|
|
|
|
#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
|
2007-07-19 11:54:37 +00:00
|
|
|
|
2007-07-28 15:43:34 +00:00
|
|
|
/* what piece index is this block in? */
|
|
|
|
#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
|
2007-07-25 01:59:46 +00:00
|
|
|
|
2007-07-28 15:43:34 +00:00
|
|
|
/* how many blocks are in this piece? */
|
|
|
|
#define tr_torPieceCountBlocks(tor,piece) \
|
|
|
|
( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
|
2007-07-19 11:54:37 +00:00
|
|
|
|
2007-07-28 15:43:34 +00:00
|
|
|
/* how many bytes are in this piece? */
|
|
|
|
#define tr_torPieceCountBytes(tor,piece) \
|
|
|
|
( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
|
2007-07-19 11:54:37 +00:00
|
|
|
|
2007-07-28 15:43:34 +00:00
|
|
|
/* how many bytes are in this block? */
|
|
|
|
#define tr_torBlockCountBytes(tor,block) \
|
|
|
|
( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
|
2007-07-19 11:54:37 +00:00
|
|
|
|
|
|
|
#define tr_block(a,b) _tr_block(tor,a,b)
|
|
|
|
int _tr_block( const tr_torrent_t * tor, int index, int begin );
|
|
|
|
|
|
|
|
|
2007-06-26 18:45:03 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2007-07-12 20:48:13 +00:00
|
|
|
TR_RUN_CHECKING = (1<<0), /* checking files' checksums */
|
|
|
|
TR_RUN_RUNNING = (1<<1), /* seeding or leeching */
|
|
|
|
TR_RUN_STOPPING = (1<<2), /* stopping */
|
|
|
|
TR_RUN_STOPPING_NET_WAIT = (1<<3), /* waiting on network -- we're
|
|
|
|
telling tracker we've stopped */
|
|
|
|
TR_RUN_STOPPED = (1<<4) /* stopped */
|
2007-06-26 18:45:03 +00:00
|
|
|
}
|
|
|
|
run_status_t;
|
|
|
|
|
2007-07-16 11:19:44 +00:00
|
|
|
#define TR_ID_LEN 20
|
|
|
|
#define TR_KEY_LEN 20
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
struct tr_torrent_s
|
|
|
|
{
|
2007-01-08 21:53:55 +00:00
|
|
|
tr_handle_t * handle;
|
2006-07-16 19:39:23 +00:00
|
|
|
tr_info_t info;
|
|
|
|
|
2007-07-20 03:24:04 +00:00
|
|
|
tr_speedlimit_t uploadLimitMode;
|
|
|
|
tr_speedlimit_t downloadLimitMode;
|
2007-07-30 18:04:10 +00:00
|
|
|
struct tr_ratecontrol_s * upload;
|
|
|
|
struct tr_ratecontrol_s * download;
|
|
|
|
struct tr_ratecontrol_s * swarmspeed;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
int error;
|
2007-01-14 12:00:21 +00:00
|
|
|
char errorString[128];
|
2007-06-18 03:40:41 +00:00
|
|
|
int hasChangedState;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-16 11:19:44 +00:00
|
|
|
char peer_id[TR_ID_LEN+1];
|
2006-07-16 19:39:23 +00:00
|
|
|
char * key;
|
2007-03-23 08:28:01 +00:00
|
|
|
uint8_t * azId;
|
2007-01-27 21:17:10 +00:00
|
|
|
int publicPort;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
/* An escaped string used to include the hash in HTTP queries */
|
2006-12-02 01:46:54 +00:00
|
|
|
char escapedHashString[3*SHA_DIGEST_LENGTH+1];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
/* Where to download */
|
|
|
|
char * destination;
|
|
|
|
|
|
|
|
/* How many bytes we ask for per request */
|
|
|
|
int blockSize;
|
|
|
|
int blockCount;
|
2007-07-28 15:43:34 +00:00
|
|
|
|
|
|
|
int lastBlockSize;
|
|
|
|
int lastPieceSize;
|
|
|
|
|
|
|
|
int blockCountInPiece;
|
|
|
|
int blockCountInLastPiece;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-30 18:04:10 +00:00
|
|
|
struct tr_completion_s * completion;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-06-26 18:45:03 +00:00
|
|
|
volatile char dieFlag;
|
2007-07-30 18:04:10 +00:00
|
|
|
struct tr_bitfield_s * uncheckedPieces;
|
2007-06-26 18:45:03 +00:00
|
|
|
run_status_t runStatus;
|
|
|
|
cp_status_t cpStatus;
|
2007-07-30 15:27:52 +00:00
|
|
|
tr_thread_t * thread;
|
|
|
|
tr_rwlock_t * lock;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-07-30 18:04:10 +00:00
|
|
|
struct tr_tracker_s * tracker;
|
|
|
|
struct tr_io_s * io;
|
2007-05-25 19:14:42 +00:00
|
|
|
uint64_t startDate;
|
2006-07-16 19:39:23 +00:00
|
|
|
uint64_t stopDate;
|
2007-07-16 19:57:34 +00:00
|
|
|
char ioLoaded;
|
|
|
|
char fastResumeDirty;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
int peerCount;
|
|
|
|
tr_peer_t * peers[TR_MAX_PEER_COUNT];
|
|
|
|
|
2006-09-26 22:36:04 +00:00
|
|
|
uint64_t downloadedCur;
|
|
|
|
uint64_t downloadedPrev;
|
|
|
|
uint64_t uploadedCur;
|
|
|
|
uint64_t uploadedPrev;
|
2007-05-25 19:14:42 +00:00
|
|
|
uint64_t activityDate;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-03-31 19:19:09 +00:00
|
|
|
uint8_t pexDisabled;
|
|
|
|
|
2007-07-16 19:57:34 +00:00
|
|
|
int8_t statCur;
|
2006-07-16 19:39:23 +00:00
|
|
|
tr_stat_t stats[2];
|
|
|
|
|
|
|
|
tr_torrent_t * next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tr_handle_s
|
|
|
|
{
|
2007-05-16 02:03:18 +00:00
|
|
|
int torrentCount;
|
|
|
|
tr_torrent_t * torrentList;
|
|
|
|
|
|
|
|
char * tag;
|
|
|
|
int isPortSet;
|
|
|
|
|
2007-07-20 08:33:59 +00:00
|
|
|
char useUploadLimit;
|
|
|
|
char useDownloadLimit;
|
2007-07-30 18:04:10 +00:00
|
|
|
struct tr_ratecontrol_s * upload;
|
|
|
|
struct tr_ratecontrol_s * download;
|
2007-05-16 02:03:18 +00:00
|
|
|
|
2007-07-30 18:04:10 +00:00
|
|
|
struct tr_shared_s * shared;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-03-28 06:28:34 +00:00
|
|
|
char key[TR_KEY_LEN+1];
|
2007-02-06 04:26:40 +00:00
|
|
|
|
|
|
|
tr_handle_status_t stats[2];
|
|
|
|
int statCur;
|
2007-03-23 08:28:01 +00:00
|
|
|
#define TR_AZ_ID_LEN 20
|
|
|
|
uint8_t azId[TR_AZ_ID_LEN];
|
2006-07-16 19:39:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|