~ubuntu-branches/debian/wheezy/libtorrent/wheezy

« back to all changes in this revision

Viewing changes to src/torrent/dht_manager.cc

  • Committer: Bazaar Package Importer
  • Author(s): Rogério Brito
  • Date: 2011-03-09 20:04:41 UTC
  • mfrom: (1.3.4 upstream) (7.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110309200441-ffi9aaqdyd72d8xl
Tags: 0.12.7-4
* Steal patch from upstream's bug tracking system to enable IPv6.
* Refresh patches to apply cleanly.
* This should, hopefully, be a good step towards addressing #490277.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// libTorrent - BitTorrent library
 
2
// Copyright (C) 2005-2007, Jari Sundell
 
3
//
 
4
// This program is free software; you can redistribute it and/or modify
 
5
// it under the terms of the GNU General Public License as published by
 
6
// the Free Software Foundation; either version 2 of the License, or
 
7
// (at your option) any later version.
 
8
// 
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
// 
 
14
// You should have received a copy of the GNU General Public License
 
15
// along with this program; if not, write to the Free Software
 
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
//
 
18
// In addition, as a special exception, the copyright holders give
 
19
// permission to link the code of portions of this program with the
 
20
// OpenSSL library under certain conditions as described in each
 
21
// individual source file, and distribute linked combinations
 
22
// including the two.
 
23
//
 
24
// You must obey the GNU General Public License in all respects for
 
25
// all of the code used other than OpenSSL.  If you modify file(s)
 
26
// with this exception, you may extend this exception to your version
 
27
// of the file(s), but you are not obligated to do so.  If you do not
 
28
// wish to do so, delete this exception statement from your version.
 
29
// If you delete this exception statement from all source files in the
 
30
// program, then also delete it here.
 
31
//
 
32
// Contact:  Jari Sundell <jaris@ifi.uio.no>
 
33
//
 
34
//           Skomakerveien 33
 
35
//           3185 Skoppum, NORWAY
 
36
 
 
37
#include "config.h"
 
38
 
 
39
#include <torrent/exceptions.h>
 
40
#include <torrent/throttle.h>
 
41
 
 
42
#include "manager.h"
 
43
#include "dht/dht_router.h"
 
44
 
 
45
#include "dht_manager.h"
 
46
 
 
47
namespace torrent {
 
48
 
 
49
DhtManager::~DhtManager() {
 
50
  stop();
 
51
  delete m_router;
 
52
}
 
53
 
 
54
void
 
55
DhtManager::initialize(const Object& dhtCache) {
 
56
  if (m_router != NULL)
 
57
    throw internal_error("DhtManager::initialize called with DHT already active.");
 
58
 
 
59
  m_router = new DhtRouter(dhtCache, rak::socket_address::cast_from(manager->connection_manager()->bind_address()));
 
60
}
 
61
 
 
62
void
 
63
DhtManager::start(port_type port) {
 
64
  if (m_router == NULL)
 
65
    throw internal_error("DhtManager::start called without initializing first.");
 
66
 
 
67
  m_port = port;
 
68
  m_router->start(port);
 
69
}
 
70
 
 
71
 
 
72
void
 
73
DhtManager::stop() {
 
74
  if (m_router != NULL)
 
75
    m_router->stop();
 
76
}
 
77
 
 
78
bool
 
79
DhtManager::is_active() const {
 
80
  return m_router != NULL && m_router->is_active();
 
81
}
 
82
 
 
83
void
 
84
DhtManager::add_node(const sockaddr* addr, int port) {
 
85
  if (m_router != NULL)
 
86
    m_router->contact(rak::socket_address::cast_from(addr), port);
 
87
}
 
88
 
 
89
void
 
90
DhtManager::add_node(const std::string& host, int port) {
 
91
  if (m_router != NULL)
 
92
    m_router->add_contact(host, port);
 
93
}
 
94
 
 
95
Object*
 
96
DhtManager::store_cache(Object* container) const {
 
97
  if (m_router == NULL)
 
98
    throw internal_error("DhtManager::store_cache called but DHT not initialized.");
 
99
 
 
100
  return m_router->store_cache(container);
 
101
}
 
102
 
 
103
DhtManager::statistics_type
 
104
DhtManager::get_statistics() const {
 
105
  return m_router->get_statistics();
 
106
}
 
107
 
 
108
void
 
109
DhtManager::reset_statistics() {
 
110
  m_router->reset_statistics();
 
111
}
 
112
 
 
113
void
 
114
DhtManager::set_upload_throttle(Throttle* t) {
 
115
  if (m_router->is_active())
 
116
    throw internal_error("DhtManager::set_upload_throttle() called while DHT server active.");
 
117
 
 
118
  m_router->set_upload_throttle(t->throttle_list());
 
119
}
 
120
 
 
121
void
 
122
DhtManager::set_download_throttle(Throttle* t) {
 
123
  if (m_router->is_active())
 
124
    throw internal_error("DhtManager::set_download_throttle() called while DHT server active.");
 
125
 
 
126
  m_router->set_download_throttle(t->throttle_list());
 
127
}
 
128
 
 
129
}