Listing peers.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@252 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-02 21:51:40 +00:00
parent 5f102a5dcf
commit bd7849199c
13 changed files with 182 additions and 65 deletions
+3
View File
@@ -43,6 +43,9 @@ class CurlGet : public torrent::Http {
void perform(CURLMsg* msg);
private:
CurlGet(const CurlGet&);
void operator = (const CurlGet&);
friend size_t curl_get_receive_write(void* data, size_t size, size_t nmemb, void* handle);
std::string m_url;
+2 -2
View File
@@ -110,12 +110,12 @@ CurlStack::remove_get(CurlGet* get) {
}
void
CurlStack::global_init() {
CurlStack::init() {
curl_global_init(CURL_GLOBAL_ALL);
}
void
CurlStack::global_cleanup() {
CurlStack::cleanup() {
curl_global_cleanup();
}
+5 -2
View File
@@ -22,14 +22,17 @@ class CurlStack {
// TODO: Set fd_set's only once?
void fdset(fd_set* readfds, fd_set* writefds, fd_set* exceptfds, int* maxFd);
static void global_init();
static void global_cleanup();
static void init();
static void cleanup();
protected:
void add_get(CurlGet* get);
void remove_get(CurlGet* get);
private:
CurlStack(const CurlStack&);
void operator = (const CurlStack&);
void* m_handle;
int m_size;
+2 -2
View File
@@ -33,10 +33,10 @@ Poll::poll() {
timeval timeout = {t / 1000000, t % 1000000};
m_maxFd = select(m_maxFd, &m_readSet, &m_writeSet, &m_exceptSet, &timeout);
m_maxFd = select(m_maxFd + 1, &m_readSet, &m_writeSet, &m_exceptSet, &timeout);
if (m_maxFd >= 0)
return;
work();
else if (errno == EINTR)
m_slotSelectInterrupted();
+2 -1
View File
@@ -14,7 +14,6 @@ public:
typedef sigc::slot1<void, int> SlotInt;
void poll();
void work();
void register_http();
@@ -22,6 +21,8 @@ public:
void slot_select_interrupted(Slot s) { m_slotSelectInterrupted = s; }
private:
void work();
SlotInt m_slotReadStdin;
Slot m_slotSelectInterrupted;
+2 -2
View File
@@ -7,10 +7,10 @@ libsub_display_a_SOURCES = \
manager.h \
window.cc \
window.h \
window_download.cc \
window_download.h \
window_download_list.cc \
window_download_list.h \
window_peer_list.cc \
window_peer_list.h \
window_statusbar.cc \
window_statusbar.h \
window_title.cc \
-20
View File
@@ -1,20 +0,0 @@
#include "config.h"
#include "canvas.h"
#include "window_download.h"
namespace display {
WindowDownload::WindowDownload(DPtr d) :
Window(new Canvas, true),
m_download(d) {
}
void
WindowDownload::redraw() {
m_canvas->erase();
m_canvas->print(0, 0, "Download: %s", m_download->get_download().get_name().c_str());
}
}
-25
View File
@@ -1,25 +0,0 @@
#ifndef RTORRENT_DISPLAY_WINDOW_DOWNLOAD_H
#define RTORRENT_DISPLAY_WINDOW_DOWNLOAD_H
#include "window.h"
#include "core/download_list.h"
namespace display {
class WindowDownload : public Window {
public:
typedef core::DownloadList::iterator DPtr;
WindowDownload(DPtr d);
DPtr get_download() { return m_download; }
virtual void redraw();
private:
DPtr m_download;
};
}
#endif
+2 -2
View File
@@ -5,7 +5,7 @@
namespace display {
WindowDownloadList::WindowDownloadList(List* d) :
WindowDownloadList::WindowDownloadList(DList* d) :
Window(new Canvas, true),
m_downloads(d) {
@@ -22,7 +22,7 @@ WindowDownloadList::redraw() {
// Remember to check for end of screen too.
for (List::iterator itr = m_downloads->begin(); itr != m_downloads->end(); ++itr) {
for (DList::iterator itr = m_downloads->begin(); itr != m_downloads->end(); ++itr) {
m_canvas->print(0, pos++, "%c %s",
itr == m_focus ? '*' : ' ',
itr->get_download().get_name().c_str());
+8 -8
View File
@@ -8,20 +8,20 @@ namespace display {
class WindowDownloadList : public Window {
public:
typedef core::DownloadList List;
typedef core::DownloadList DList;
WindowDownloadList(List* d);
WindowDownloadList(DList* d);
List* get_list() { return m_downloads; }
DList& get_list() { return *m_downloads; }
List::iterator get_focus() { return m_focus; }
void set_focus(core::DownloadList::iterator itr) { m_focus = itr; }
DList::iterator get_focus() { return m_focus; }
void set_focus(DList::iterator itr) { m_focus = itr; }
virtual void redraw();
virtual void redraw();
private:
List* m_downloads;
List::iterator m_focus;
DList* m_downloads;
DList::iterator m_focus;
};
}
+116
View File
@@ -0,0 +1,116 @@
#include "config.h"
#include <stdexcept>
#include "canvas.h"
#include "window_peer_list.h"
namespace display {
WindowPeerList::WindowPeerList(PList* l) :
Window(new Canvas, true),
m_list(l),
m_focus(l->end()) {
}
void
WindowPeerList::redraw() {
m_canvas->erase();
int x = 2;
int y = 0;
m_canvas->print(x, y, "DNS"); x += 16;
m_canvas->print(x, y, "UP"); x += 7;
m_canvas->print(x, y, "DOWN"); x += 7;
m_canvas->print(x, y, "PEER"); x += 7;
m_canvas->print(x, y, "RE/LO"); x += 7;
m_canvas->print(x, y, "QS"); x += 6;
m_canvas->print(x, y, "DONE"); x += 6;
m_canvas->print(x, y, "REQ"); x += 6;
m_canvas->print(x, y, "SNUB");
++y;
if (m_list->empty())
return;
PList::iterator itr, last;
if (m_focus != m_list->end()) {
int i = 0;
itr = last = m_focus;
while (i < m_canvas->get_height() - y && !(itr == m_list->begin() && last == m_list->end())) {
if (itr != m_list->begin()) {
--itr;
++i;
}
if (last != m_list->end() && i < m_canvas->get_height() - y) {
++last;
++i;
}
}
} else {
itr = m_list->begin();
last = m_list->end();
}
uint32_t chunksTotal = m_slotChunksTotal();
if (chunksTotal <= 0)
throw std::logic_error("WindowPeerList::redraw() m_slotChunksTotal() returned invalid value");
while (itr != m_list->end() && y < m_canvas->get_height()) {
x = 0;
m_canvas->print(x, y, "%c %s",
itr == m_focus ? '*' : ' ',
itr->get_dns().c_str());
x += 18;
m_canvas->print(x, y, "%.1f",
(double)itr->get_rate_up() / 1024);
x += 7;
m_canvas->print(x, y, "%.1f",
(double)itr->get_rate_down() / 1024);
x += 7;
m_canvas->print(x, y, "%.1f",
(double)itr->get_rate_peer() / 1024);
x += 7;
m_canvas->print(x, y, "%c%c/%c%c%c",
itr->get_remote_choked() ? 'c' : 'u',
itr->get_remote_interested() ? 'i' : 'n',
itr->get_local_choked() ? 'c' : 'u',
itr->get_local_interested() ? 'i' : 'n',
itr->get_choke_delayed() ? 'd' : ' ');
x += 7;
m_canvas->print(x, y, "%i/%i",
itr->get_outgoing_queue_size(),
itr->get_incoming_queue_size());
x += 6;
m_canvas->print(x, y, "%3i", (itr->get_chunks_done() * 100) / chunksTotal);
x += 6;
if (itr->get_incoming_queue_size())
m_canvas->print(x, y, "%i",
itr->get_incoming_index(0));
x += 6;
if (itr->get_snubbed())
m_canvas->print(x, y, "*");
++y;
++itr;
}
}
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef RTORRENT_DISPLAY_PEER_LIST_H
#define RTORRENT_DISPLAY_PEER_LIST_H
#include <list>
#include <sigc++/slot.h>
#include <torrent/peer.h>
#include "window.h"
namespace display {
class WindowPeerList : public Window {
public:
typedef std::list<torrent::Peer> PList;
typedef sigc::slot0<uint32_t> SlotChunksTotal;
WindowPeerList(PList* l);
PList& get_list() { return *m_list; }
PList::iterator get_focus() { return m_focus; }
void set_focus(PList::iterator itr) { m_focus = itr; }
void slot_chunks_total(SlotChunksTotal s) { m_slotChunksTotal = s; }
virtual void redraw();
private:
PList* m_list;
PList::iterator m_focus;
SlotChunksTotal m_slotChunksTotal;
};
}
#endif
+3 -1
View File
@@ -9,6 +9,7 @@
#include "display/window_statusbar.h"
#include "core/poll.h"
#include "core/curl_stack.h"
#include "core/download_list.h"
#include "ui/control.h"
@@ -45,6 +46,7 @@ main(int argc, char** argv) {
try {
display::Canvas::init();
core::CurlStack::init();
ui::Control uiControl;
ui::DownloadList uiDownloadList(&downloads, &uiControl);
@@ -78,7 +80,6 @@ main(int argc, char** argv) {
uiControl.get_display().do_update();
poll.poll();
poll.work();
}
display::Canvas::cleanup();
@@ -90,6 +91,7 @@ main(int argc, char** argv) {
}
torrent::cleanup();
core::CurlStack::cleanup();
return 0;
}