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
37
#ifndef LIBTORRENT_PEER_CONNECTION_LIST_H
38
#define LIBTORRENT_PEER_CONNECTION_LIST_H
41
#include <sigc++/signal.h>
42
#include <torrent/common.h>
43
#include <torrent/hash_string.h>
50
class DownloadWrapper;
52
class PeerConnectionBase;
54
class ProtocolExtension;
57
class HandshakeManager;
59
class LIBTORRENT_EXPORT ConnectionList : private std::vector<Peer*> {
61
friend class DownloadMain;
62
friend class DownloadWrapper;
63
friend class HandshakeManager;
65
typedef std::vector<Peer*> base_type;
66
typedef std::vector<HashString> queue_type;
67
typedef uint32_t size_type;
68
typedef sigc::signal1<void, Peer*> signal_peer_type;
70
typedef PeerConnectionBase* (*slot_new_conn_type)(bool encrypted);
72
using base_type::value_type;
73
using base_type::reference;
74
using base_type::difference_type;
76
using base_type::iterator;
77
using base_type::reverse_iterator;
78
using base_type::const_iterator;
79
using base_type::const_reverse_iterator;
80
// using base_type::size;
81
using base_type::empty;
83
using base_type::front;
84
using base_type::back;
85
using base_type::begin;
87
using base_type::rbegin;
88
using base_type::rend;
90
// Make sure any change here match PeerList's flags.
91
static const int disconnect_available = (1 << 0);
92
static const int disconnect_quick = (1 << 1);
93
static const int disconnect_unwanted = (1 << 2);
94
static const int disconnect_delayed = (1 << 3);
96
ConnectionList(DownloadMain* download);
98
// Make these protected?
99
iterator erase(iterator pos, int flags);
100
void erase(Peer* p, int flags);
101
void erase(PeerInfo* peerInfo, int flags);
103
void erase_remaining(iterator pos, int flags);
104
void erase_seeders();
106
iterator find(const char* id);
107
iterator find(const sockaddr* sa);
109
size_type min_size() const { return m_minSize; }
110
void set_min_size(size_type v);
112
size_type size() const { return base_type::size(); }
114
size_type max_size() const { return m_maxSize; }
115
void set_max_size(size_type v);
117
// Removes from 'l' addresses that are already connected to. Assumes
118
// 'l' is sorted and unique.
119
void set_difference(AddressList* l);
121
signal_peer_type& signal_connected() { return m_signalConnected; }
122
signal_peer_type& signal_disconnected() { return m_signalDisconnected; }
124
// Move to protected:
125
void slot_new_connection(slot_new_conn_type s) { m_slotNewConnection = s; }
128
// Does not do the usual cleanup done by 'erase'.
129
void clear() LIBTORRENT_NO_EXPORT;
131
// Returns false if the connection was not added, the caller is then
132
// responsible for cleaning up 'fd'.
134
// Clean this up, don't use this many arguments.
135
PeerConnectionBase* insert(PeerInfo* p, const SocketFd& fd, Bitfield* bitfield, EncryptionInfo* encryptionInfo, ProtocolExtension* extensions) LIBTORRENT_NO_EXPORT;
137
void disconnect_queued() LIBTORRENT_NO_EXPORT;
140
ConnectionList(const ConnectionList&) LIBTORRENT_NO_EXPORT;
141
void operator = (const ConnectionList&) LIBTORRENT_NO_EXPORT;
143
DownloadMain* m_download;
148
signal_peer_type m_signalConnected;
149
signal_peer_type m_signalDisconnected;
151
slot_new_conn_type m_slotNewConnection;
153
queue_type m_disconnectQueue;