~ubuntu-branches/ubuntu/oneiric/libtorrent/oneiric

« back to all changes in this revision

Viewing changes to src/tracker/tracker_base.h

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-09-11 15:12:31 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070911151231-brompt7pecvfbaau
Tags: 0.11.8-1
* New upstream version
* debian/patches/update-changelog.patch:
 + Updated with the new changelog.
* debian/control:
 + Added the Homepage field, deleted Homepages from the descriptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// libTorrent - BitTorrent library
2
 
// Copyright (C) 2005-2006, Jari Sundell
 
2
// Copyright (C) 2005-2007, Jari Sundell
3
3
//
4
4
// This program is free software; you can redistribute it and/or modify
5
5
// it under the terms of the GNU General Public License as published by
47
47
 
48
48
namespace torrent {
49
49
 
 
50
class AddressList;
50
51
class TrackerControl;
51
52
 
52
53
class TrackerBase {
53
54
public:
54
 
  typedef std::list<rak::socket_address>                                        AddressList;
55
 
  typedef rak::mem_fun1<TrackerControl, void, int>                              SlotInt;
56
55
  typedef rak::mem_fun2<TrackerControl, void, TrackerBase*, AddressList*>       SlotTbAddressList;
57
56
  typedef rak::mem_fun2<TrackerControl, void, TrackerBase*, const std::string&> SlotTbString;
58
57
 
63
62
  } Type;
64
63
 
65
64
  TrackerBase(DownloadInfo* info, const std::string& url) :
66
 
    m_enabled(true), m_info(info), m_url(url), m_scrapeComplete(0), m_scrapeIncomplete(0) {}
 
65
    m_enabled(true), m_info(info), m_url(url),
 
66
    m_normalInterval(1800), m_minInterval(0),
 
67
    m_scrapeComplete(0), m_scrapeIncomplete(0) {}
67
68
  virtual ~TrackerBase() {}
68
69
 
69
70
  virtual bool        is_busy() const = 0;
83
84
  const std::string&  tracker_id() const                    { return m_trackerId; }
84
85
  void                set_tracker_id(const std::string& id) { m_trackerId = id; }
85
86
 
 
87
  uint32_t            normal_interval() const               { return m_normalInterval; }
 
88
  uint32_t            min_interval() const                  { return m_minInterval; }
 
89
 
86
90
  const rak::timer&   scrape_time_last() const              { return m_scrapeTimeLast; }
87
91
  uint32_t            scrape_complete() const               { return m_scrapeComplete; }
88
92
  uint32_t            scrape_incomplete() const             { return m_scrapeIncomplete; }
90
94
 
91
95
  void                slot_success(SlotTbAddressList s)     { m_slotSuccess = s; }
92
96
  void                slot_failed(SlotTbString s)           { m_slotFailed = s; }
93
 
  void                slot_set_interval(SlotInt s)          { m_slotSetInterval = s; }
94
 
  void                slot_set_min_interval(SlotInt s)      { m_slotSetMinInterval = s; }
95
97
 
96
98
protected:
97
99
  TrackerBase(const TrackerBase& t);
98
100
  void operator = (const TrackerBase& t);
99
101
 
 
102
  void                set_normal_interval(int v) { if (v >= 60 && v <= 3600) m_normalInterval = v; }
 
103
  void                set_min_interval(int v)    { if (v >= 0 && v <= 600)   m_minInterval = v; }
 
104
 
100
105
  bool                m_enabled;
101
106
 
102
107
  DownloadInfo*       m_info;
104
109
 
105
110
  std::string         m_trackerId;
106
111
 
 
112
  uint32_t            m_normalInterval;
 
113
  uint32_t            m_minInterval;
 
114
 
107
115
  rak::timer          m_scrapeTimeLast;
108
116
  uint32_t            m_scrapeComplete;
109
117
  uint32_t            m_scrapeIncomplete;
111
119
 
112
120
  SlotTbAddressList   m_slotSuccess;
113
121
  SlotTbString        m_slotFailed;
114
 
  SlotInt             m_slotSetInterval;
115
 
  SlotInt             m_slotSetMinInterval;
116
 
};
117
 
 
118
 
struct address_list_add_address : public std::unary_function<rak::socket_address, void> {
119
 
  address_list_add_address(TrackerBase::AddressList* l) : m_list(l) {}
120
 
 
121
 
  void operator () (const rak::socket_address& sa) const {
122
 
    if (!sa.is_valid())
123
 
      return;
124
 
 
125
 
    m_list->push_back(sa);
126
 
  }
127
 
 
128
 
  TrackerBase::AddressList* m_list;
129
122
};
130
123
 
131
124
}