(trunk) #3256 "libtransmission/publish.[ch] should be replaced" -- apply publish.diff for 2.10

This commit is contained in:
Charles Kerr 2010-06-19 14:33:10 +00:00
parent bab5d73dc5
commit db44d81b24
14 changed files with 56 additions and 228 deletions

View File

@ -44,7 +44,6 @@ libtransmission_a_SOURCES = \
platform.c \
port-forwarding.c \
ptrarray.c \
publish.c \
ratecontrol.c \
resume.c \
rpcimpl.c \
@ -96,7 +95,6 @@ noinst_HEADERS = \
platform.h \
port-forwarding.h \
ptrarray.h \
publish.h \
ratecontrol.h \
resume.h \
rpcimpl.h \

View File

@ -21,7 +21,6 @@
#include "crypto.h"
#include "net.h"
#include "ptrarray.h"
#include "publish.h"
#include "session.h"
#include "tr-dht.h"
#include "tr-lpd.h"
@ -530,7 +529,8 @@ tierAddTracker( tr_announcer * announcer,
typedef struct tr_torrent_tiers
{
tr_ptrArray tiers;
tr_publisher publisher;
tr_tracker_callback * callback;
void * callbackData;
}
tr_torrent_tiers;
@ -539,14 +539,12 @@ tiersNew( void )
{
tr_torrent_tiers * tiers = tr_new0( tr_torrent_tiers, 1 );
tiers->tiers = TR_PTR_ARRAY_INIT;
tiers->publisher = TR_PUBLISHER_INIT;
return tiers;
}
static void
tiersFree( tr_torrent_tiers * tiers )
{
tr_publisherDestruct( &tiers->publisher );
tr_ptrArrayDestruct( &tiers->tiers, tierFree );
tr_free( tiers );
}
@ -593,7 +591,9 @@ publishMessage( tr_tier * tier, const char * msg, int type )
event.messageType = type;
event.text = msg;
event.tracker = tier->currentTracker ? tier->currentTracker->announce : NULL;
tr_publisherPublish( &tiers->publisher, tier, &event );
if( tiers->callback != NULL )
tiers->callback( tier->tor, &event, tiers->callbackData );
}
}
@ -640,7 +640,8 @@ publishNewPeers( tr_tier * tier, int seeds, int leechers,
e.compact = compact;
e.compactLen = compactLen;
tr_publisherPublish( &tier->tor->tiers->publisher, tier, &e );
if( tier->tor->tiers->callback != NULL )
tier->tor->tiers->callback( tier->tor, &e, NULL );
return compactLen / 6;
}
@ -844,7 +845,8 @@ addTorrentToTier( tr_announcer * announcer, tr_torrent_tiers * tiers, tr_torrent
}
tr_torrent_tiers *
tr_announcerAddTorrent( tr_announcer * announcer, tr_torrent * tor )
tr_announcerAddTorrent( tr_announcer * announcer, tr_torrent * tor,
tr_tracker_callback * callback, void * callbackData )
{
tr_torrent_tiers * tiers;
@ -852,6 +854,8 @@ tr_announcerAddTorrent( tr_announcer * announcer, tr_torrent * tor )
assert( tr_isTorrent( tor ) );
tiers = tiersNew( );
tiers->callback = callback;
tiers->callbackData = callbackData;
addTorrentToTier( announcer, tiers, tor );
@ -929,22 +933,6 @@ tr_announcerResetTorrent( tr_announcer * announcer, tr_torrent * tor )
tr_ptrArrayDestruct( &oldTiers, tierFree );
}
tr_publisher_tag
tr_announcerSubscribe( struct tr_torrent_tiers * tiers,
tr_delivery_func func,
void * userData )
{
return tr_publisherSubscribe( &tiers->publisher, func, userData );
}
void
tr_announcerUnsubscribe( struct tr_torrent_tiers * tiers,
tr_publisher_tag tag )
{
if( tiers )
tr_publisherUnsubscribe( &tiers->publisher, tag );
}
static tr_bool
tierCanManualAnnounce( const tr_tier * tier )
{

View File

@ -18,7 +18,6 @@
#define _TR_ANNOUNCER_H_
#include "transmission.h"
#include "publish.h"
struct tr_announcer;
struct tr_torrent_tiers;
@ -55,6 +54,10 @@ typedef struct
}
tr_tracker_event;
typedef void tr_tracker_callback ( tr_torrent * tor,
const tr_tracker_event * event,
void * client_data );
/**
*** Session ctor/dtor
**/
@ -67,20 +70,15 @@ void tr_announcerClose( tr_session * );
*** For torrent customers
**/
struct tr_torrent_tiers * tr_announcerAddTorrent( struct tr_announcer *,
tr_torrent * );
struct tr_torrent_tiers * tr_announcerAddTorrent( struct tr_announcer *,
tr_torrent * torrent,
tr_tracker_callback * cb,
void * cbdata );
tr_bool tr_announcerHasBacklog( const struct tr_announcer * );
void tr_announcerResetTorrent( struct tr_announcer*, tr_torrent* );
tr_publisher_tag tr_announcerSubscribe( struct tr_torrent_tiers * tiers,
tr_delivery_func func,
void * userData );
void tr_announcerUnsubscribe( struct tr_torrent_tiers * tiers,
tr_publisher_tag tag );
void tr_announcerRemoveTorrent( struct tr_announcer * ,
tr_torrent * );

View File

@ -84,6 +84,12 @@ typedef struct
}
tr_peer_event;
struct tr_peer;
typedef void tr_peer_callback( struct tr_peer * peer,
const tr_peer_event * event,
void * client_data );
#ifdef WIN32
#define EMSGSIZE WSAEMSGSIZE
#endif

View File

@ -392,10 +392,7 @@ peerDestructor( Torrent * t, tr_peer * peer )
peerDeclinedAllRequests( t, peer );
if( peer->msgs != NULL )
{
tr_peerMsgsUnsubscribe( peer->msgs, peer->msgsTag );
tr_peerMsgsFree( peer->msgs );
}
tr_peerIoClear( peer->io );
tr_peerIoUnref( peer->io ); /* balanced by the ref in handshakeDoneCB() */
@ -457,7 +454,7 @@ torrentDestructor( void * vt )
tr_free( t );
}
static void peerCallbackFunc( void * vpeer, void * vevent, void * vt );
static void peerCallbackFunc( tr_peer *, const tr_peer_event *, void * );
static Torrent*
torrentConstructor( tr_peerMgr * manager,
@ -1338,11 +1335,9 @@ peerDeclinedAllRequests( Torrent * t, const tr_peer * peer )
}
static void
peerCallbackFunc( void * vpeer, void * vevent, void * vt )
peerCallbackFunc( tr_peer * peer, const tr_peer_event * e, void * vt )
{
tr_peer * peer = vpeer; /* may be NULL if peer is a webseed */
Torrent * t = vt;
const tr_peer_event * e = vevent;
torrentLock( t );
@ -1706,7 +1701,7 @@ myHandshakeDoneCB( tr_handshake * handshake,
peer->io = tr_handshakeStealIO( handshake ); /* this steals its refcount too, which is
balanced by our unref in peerDestructor() */
tr_peerIoSetParent( peer->io, t->tor->bandwidth );
tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag );
tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t );
success = TRUE;
}

View File

@ -28,7 +28,6 @@
#include "history.h"
#include "net.h"
#include "peer-common.h" /* struct peer_request */
#include "publish.h" /* tr_publisher_tag */
/**
* @addtogroup peers Peers
@ -124,7 +123,6 @@ typedef struct tr_peer
tr_recentHistory * cancelsSentToPeer;
struct tr_peermsgs * msgs;
tr_publisher_tag msgsTag;
}
tr_peer;

View File

@ -201,7 +201,8 @@ struct tr_peermsgs
tr_torrent * torrent;
tr_publisher publisher;
tr_peer_callback * callback;
void * callbackData;
struct evbuffer * outMessages; /* all the non-piece messages */
@ -470,7 +471,8 @@ publish( tr_peermsgs * msgs, tr_peer_event * e )
assert( msgs->peer );
assert( msgs->peer->msgs == msgs );
tr_publisherPublish( &msgs->publisher, msgs->peer, e );
if( msgs->callback != NULL )
msgs->callback( msgs->peer, e, msgs->callbackData );
}
static void
@ -2315,11 +2317,10 @@ pexPulse( int foo UNUSED, short bar UNUSED, void * vmsgs )
**/
tr_peermsgs*
tr_peerMsgsNew( struct tr_torrent * torrent,
struct tr_peer * peer,
tr_delivery_func func,
void * userData,
tr_publisher_tag * setme )
tr_peerMsgsNew( struct tr_torrent * torrent,
struct tr_peer * peer,
tr_peer_callback * callback,
void * callbackData )
{
tr_peermsgs * m;
@ -2327,7 +2328,8 @@ tr_peerMsgsNew( struct tr_torrent * torrent,
assert( peer->io );
m = tr_new0( tr_peermsgs, 1 );
m->publisher = TR_PUBLISHER_INIT;
m->callback = callback;
m->callbackData = callbackData;
m->peer = peer;
m->torrent = torrent;
m->peer->clientIsChoked = 1;
@ -2343,8 +2345,6 @@ tr_peerMsgsNew( struct tr_torrent * torrent,
tr_timerAdd( &m->pexTimer, PEX_INTERVAL_SECS, 0 );
peer->msgs = m;
*setme = tr_publisherSubscribe( &m->publisher, func, userData );
if( tr_peerIoSupportsLTEP( peer->io ) )
sendLtepHandshake( m );
@ -2371,7 +2371,6 @@ tr_peerMsgsFree( tr_peermsgs* msgs )
if( msgs )
{
evtimer_del( &msgs->pexTimer );
tr_publisherDestruct( &msgs->publisher );
evbuffer_free( msgs->incoming.block );
evbuffer_free( msgs->outMessages );
@ -2382,10 +2381,3 @@ tr_peerMsgsFree( tr_peermsgs* msgs )
tr_free( msgs );
}
}
void
tr_peerMsgsUnsubscribe( tr_peermsgs * peer,
tr_publisher_tag tag )
{
tr_publisherUnsubscribe( &peer->publisher, tag );
}

View File

@ -19,7 +19,6 @@
#include <inttypes.h>
#include "peer-common.h"
#include "publish.h"
struct tr_torrent;
struct tr_peer;
@ -32,12 +31,10 @@ struct tr_bitfield;
typedef struct tr_peermsgs tr_peermsgs;
tr_peermsgs* tr_peerMsgsNew( struct tr_torrent * torrent,
struct tr_peer * peer,
tr_delivery_func func,
void * user,
tr_publisher_tag * setme );
tr_peermsgs* tr_peerMsgsNew( struct tr_torrent * torrent,
struct tr_peer * peer,
tr_peer_callback * callback,
void * callback_data );
void tr_peerMsgsSetChoke( tr_peermsgs *, int doChoke );
@ -55,9 +52,6 @@ void tr_peerMsgsCancel( tr_peermsgs * msgs,
void tr_peerMsgsFree( tr_peermsgs* );
void tr_peerMsgsUnsubscribe( tr_peermsgs * peer,
tr_publisher_tag tag );
size_t tr_generateAllowedSet( tr_piece_index_t * setmePieces,
size_t desiredSetSize,
size_t pieceCount,

View File

@ -1,69 +0,0 @@
/*
* This file Copyright (C) 2007-2010 Mnemosyne LLC
*
* This file is licensed by the GPL version 2. Works owned by the
* Transmission project are granted a special exemption to clause 2(b)
* so that the bulk of its code can remain under the MIT license.
* This exemption does not extend to derived works not owned by
* the Transmission project.
*
* $Id$
*/
#include <assert.h>
#include "list.h"
#include "publish.h"
#include "utils.h"
struct tr_publisher_node
{
tr_delivery_func * func;
void * user_data;
};
const tr_publisher TR_PUBLISHER_INIT = { NULL };
void
tr_publisherDestruct( tr_publisher * p )
{
tr_list_free( &p->list, NULL );
}
tr_publisher_tag
tr_publisherSubscribe( tr_publisher * p,
tr_delivery_func func,
void * user_data )
{
struct tr_publisher_node * node = tr_new( struct tr_publisher_node, 1 );
node->func = func;
node->user_data = user_data;
tr_list_append( &p->list, node );
return node;
}
void
tr_publisherUnsubscribe( tr_publisher * p,
tr_publisher_tag tag )
{
tr_list_remove_data( &p->list, tag );
tr_free( tag );
}
void
tr_publisherPublish( tr_publisher * p,
void * source,
void * event )
{
tr_list * walk;
for( walk = p->list; walk != NULL; )
{
tr_list * next = walk->next;
struct tr_publisher_node * node =
(struct tr_publisher_node*)walk->data;
( node->func )( source, event, node->user_data );
walk = next;
}
}

View File

@ -1,61 +0,0 @@
/*
* This file Copyright (C) 2007-2010 Mnemosyne LLC
*
* This file is licensed by the GPL version 2. Works owned by the
* Transmission project are granted a special exemption to clause 2(b)
* so that the bulk of its code can remain under the MIT license.
* This exemption does not extend to derived works not owned by
* the Transmission project.
*
* $Id$
*/
#ifndef __TRANSMISSION__
#error only libtransmission should #include this header.
#endif
#ifndef _TR_PUBLISHER_H_
#define _TR_PUBLISHER_H_
struct tr_list;
/**
*** A lightweight implementation of the 'Observable' design pattern.
**/
typedef struct tr_publisher
{
struct tr_list * list;
}
tr_publisher;
typedef void * tr_publisher_tag;
typedef void tr_delivery_func ( void * source,
void * event,
void * user_data );
/**
*** Observer API
**/
tr_publisher_tag tr_publisherSubscribe( tr_publisher * publisher,
tr_delivery_func delivery_func,
void * user_data );
void tr_publisherUnsubscribe( tr_publisher * publisher,
tr_publisher_tag tag );
/**
*** Observable API
**/
extern const tr_publisher TR_PUBLISHER_INIT;
void tr_publisherDestruct( tr_publisher * );
void tr_publisherPublish( tr_publisher * publisher,
void * source,
void * event );
#endif

View File

@ -360,13 +360,8 @@ tr_torrentClearError( tr_torrent * tor )
}
static void
onTrackerResponse( void * tracker UNUSED,
void * vevent,
void * user_data )
onTrackerResponse( tr_torrent * tor, const tr_tracker_event * event, void * unused UNUSED )
{
tr_torrent * tor = user_data;
tr_tracker_event * event = vevent;
switch( event->messageType )
{
case TR_TRACKER_PEERS:
@ -727,8 +722,7 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor )
}
}
tor->tiers = tr_announcerAddTorrent( tor->session->announcer, tor );
tor->tiersSubscription = tr_announcerSubscribe( tor->tiers, onTrackerResponse, tor );
tor->tiers = tr_announcerAddTorrent( tor->session->announcer, tor, onTrackerResponse, NULL );
if( doStart )
torrentStart( tor );
@ -1314,7 +1308,6 @@ freeTorrent( tr_torrent * tor )
tr_cpDestruct( &tor->completion );
tr_announcerUnsubscribe( tor->tiers, tor->tiersSubscription );
tr_announcerRemoveTorrent( session->announcer, tor );
tr_bitfieldDestruct( &tor->checkedPieces );

View File

@ -194,7 +194,6 @@ struct tr_torrent
tr_completeness completeness;
struct tr_torrent_tiers * tiers;
struct tr_publisher_tag * tiersSubscription;
time_t dhtAnnounceAt;
time_t dhtAnnounce6At;

View File

@ -31,8 +31,8 @@ struct tr_webseed
char * url;
tr_delivery_func * callback;
void * callback_userdata;
tr_peer_callback * callback;
void * callback_data;
tr_piece_index_t pieceIndex;
uint32_t pieceOffset;
@ -52,11 +52,10 @@ struct tr_webseed
static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
static void
publish( tr_webseed * w,
tr_peer_event * e )
publish( tr_webseed * w, tr_peer_event * e )
{
if( w->callback )
w->callback( NULL, e, w->callback_userdata );
if( w->callback != NULL )
w->callback( NULL, e, w->callback_data );
}
static void
@ -236,9 +235,9 @@ tr_webseedGetSpeed( const tr_webseed * w, uint64_t now, float * setme_KiBs )
tr_webseed*
tr_webseedNew( struct tr_torrent * torrent,
const char * url,
tr_delivery_func callback,
void * callback_userdata )
const char * url,
tr_peer_callback * callback,
void * callback_data )
{
tr_webseed * w = tr_new0( tr_webseed, 1 );
@ -247,9 +246,8 @@ tr_webseedNew( struct tr_torrent * torrent,
w->content = evbuffer_new( );
w->url = tr_strdup( url );
w->callback = callback;
w->callback_userdata = callback_userdata;
w->callback_data = callback_data;
tr_rcConstruct( &w->rateDown );
/*fprintf( stderr, "w->callback_userdata is %p\n", w->callback_userdata );*/
return w;
}

View File

@ -20,12 +20,11 @@
typedef struct tr_webseed tr_webseed;
#include "peer-common.h"
#include "publish.h"
tr_webseed* tr_webseedNew( struct tr_torrent * torrent,
const char * url,
tr_delivery_func delivery_func,
void * delivery_userdata );
const char * url,
tr_peer_callback * callback,
void * callback_data );
void tr_webseedFree( tr_webseed * );