1
// libTorrent - BitTorrent library
2
// Copyright (C) 2005-2007, Jari Sundell
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.
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.
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
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
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.
32
// Contact: Jari Sundell <jaris@ifi.uio.no>
35
// 3185 Skoppum, NORWAY
39
#include <torrent/exceptions.h>
40
#include <torrent/throttle.h>
43
#include "dht/dht_router.h"
45
#include "dht_manager.h"
49
DhtManager::~DhtManager() {
55
DhtManager::initialize(const Object& dhtCache) {
57
throw internal_error("DhtManager::initialize called with DHT already active.");
59
m_router = new DhtRouter(dhtCache, rak::socket_address::cast_from(manager->connection_manager()->bind_address()));
63
DhtManager::start(port_type port) {
65
throw internal_error("DhtManager::start called without initializing first.");
68
m_router->start(port);
79
DhtManager::is_active() const {
80
return m_router != NULL && m_router->is_active();
84
DhtManager::add_node(const sockaddr* addr, int port) {
86
m_router->contact(rak::socket_address::cast_from(addr), port);
90
DhtManager::add_node(const std::string& host, int port) {
92
m_router->add_contact(host, port);
96
DhtManager::store_cache(Object* container) const {
98
throw internal_error("DhtManager::store_cache called but DHT not initialized.");
100
return m_router->store_cache(container);
103
DhtManager::statistics_type
104
DhtManager::get_statistics() const {
105
return m_router->get_statistics();
109
DhtManager::reset_statistics() {
110
m_router->reset_statistics();
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.");
118
m_router->set_upload_throttle(t->throttle_list());
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.");
126
m_router->set_download_throttle(t->throttle_list());