~ubuntu-branches/ubuntu/wily/libtorrent/wily-proposed

« back to all changes in this revision

Viewing changes to src/torrent/peer/connection_list.h

  • Committer: Bazaar Package Importer
  • Author(s): Rogério Brito
  • Date: 2011-03-20 01:06:18 UTC
  • mfrom: (1.1.13 upstream) (4.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110320010618-g3wyylccqzqko73c
Tags: 0.12.7-5
* Use Steinar's "real" patch for IPv6. Addresses #490277, #618275,
  and Closes: #617791.
* Adapt libtorrent-0.12.6-ipv6-07.patch. It FTBFS otherwise.
* Add proper attibution to the IPv6 patch.

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
#ifndef LIBTORRENT_PEER_CONNECTION_LIST_H
 
38
#define LIBTORRENT_PEER_CONNECTION_LIST_H
 
39
 
 
40
#include <vector>
 
41
#include <sigc++/signal.h>
 
42
#include <torrent/common.h>
 
43
#include <torrent/hash_string.h>
 
44
 
 
45
namespace torrent {
 
46
 
 
47
class AddressList;
 
48
class Bitfield;
 
49
class DownloadMain;
 
50
class DownloadWrapper;
 
51
class Peer;
 
52
class PeerConnectionBase;
 
53
class PeerInfo;
 
54
class ProtocolExtension;
 
55
class SocketFd;
 
56
class EncryptionInfo;
 
57
class HandshakeManager;
 
58
 
 
59
class LIBTORRENT_EXPORT ConnectionList : private std::vector<Peer*> {
 
60
public:
 
61
  friend class DownloadMain;
 
62
  friend class DownloadWrapper;
 
63
  friend class HandshakeManager;
 
64
 
 
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;
 
69
 
 
70
  typedef PeerConnectionBase* (*slot_new_conn_type)(bool encrypted);
 
71
 
 
72
  using base_type::value_type;
 
73
  using base_type::reference;
 
74
  using base_type::difference_type;
 
75
 
 
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;
 
82
 
 
83
  using base_type::front;
 
84
  using base_type::back;
 
85
  using base_type::begin;
 
86
  using base_type::end;
 
87
  using base_type::rbegin;
 
88
  using base_type::rend;
 
89
  
 
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);
 
95
 
 
96
  ConnectionList(DownloadMain* download);
 
97
 
 
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);
 
102
 
 
103
  void                erase_remaining(iterator pos, int flags);
 
104
  void                erase_seeders();
 
105
 
 
106
  iterator            find(const char* id);
 
107
  iterator            find(const sockaddr* sa);
 
108
 
 
109
  size_type           min_size() const                          { return m_minSize; }
 
110
  void                set_min_size(size_type v);
 
111
 
 
112
  size_type           size() const                              { return base_type::size(); }
 
113
 
 
114
  size_type           max_size() const                          { return m_maxSize; }
 
115
  void                set_max_size(size_type v);
 
116
 
 
117
  // Removes from 'l' addresses that are already connected to. Assumes
 
118
  // 'l' is sorted and unique.
 
119
  void                set_difference(AddressList* l);
 
120
 
 
121
  signal_peer_type&   signal_connected()                        { return m_signalConnected; }
 
122
  signal_peer_type&   signal_disconnected()                     { return m_signalDisconnected; }
 
123
 
 
124
  // Move to protected:
 
125
  void                slot_new_connection(slot_new_conn_type s) { m_slotNewConnection = s; }
 
126
 
 
127
protected:
 
128
  // Does not do the usual cleanup done by 'erase'.
 
129
  void                clear() LIBTORRENT_NO_EXPORT;
 
130
 
 
131
  // Returns false if the connection was not added, the caller is then
 
132
  // responsible for cleaning up 'fd'.
 
133
  //
 
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;
 
136
 
 
137
  void                disconnect_queued() LIBTORRENT_NO_EXPORT;
 
138
 
 
139
private:
 
140
  ConnectionList(const ConnectionList&) LIBTORRENT_NO_EXPORT;
 
141
  void operator = (const ConnectionList&) LIBTORRENT_NO_EXPORT;
 
142
 
 
143
  DownloadMain*       m_download;
 
144
 
 
145
  size_type           m_minSize;
 
146
  size_type           m_maxSize;
 
147
 
 
148
  signal_peer_type    m_signalConnected;
 
149
  signal_peer_type    m_signalDisconnected;
 
150
 
 
151
  slot_new_conn_type  m_slotNewConnection;
 
152
 
 
153
  queue_type          m_disconnectQueue;
 
154
};
 
155
 
 
156
}
 
157
 
 
158
#endif