From 406135df6651987391004d1972b9f7f36166fb50 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 8 Dec 2006 14:17:36 +0000 Subject: [PATCH] new .cpp directory --- library/{ => cpp}/alert.cpp | 0 library/{ => cpp}/allocate_resources.cpp | 0 library/{ => cpp}/bt_peer_connection.cpp | 0 library/{ => cpp}/entry.cpp | 0 library/{ => cpp}/escape_string.cpp | 0 library/{ => cpp}/file.cpp | 0 library/{ => cpp}/http_tracker_connection.cpp | 0 library/{ => cpp}/identify_client.cpp | 0 library/{ => cpp}/ip_filter.cpp | 0 library/{ => cpp}/kademlia/closest_nodes.cpp | 0 library/{ => cpp}/kademlia/dht_tracker.cpp | 0 library/{ => cpp}/kademlia/find_data.cpp | 0 library/{ => cpp}/kademlia/node.cpp | 0 library/{ => cpp}/kademlia/node_id.cpp | 0 library/{ => cpp}/kademlia/refresh.cpp | 0 library/{ => cpp}/kademlia/routing_table.cpp | 0 library/{ => cpp}/kademlia/rpc_manager.cpp | 0 .../kademlia/traversal_algorithm.cpp | 0 library/{ => cpp}/peer_connection.cpp | 0 library/{ => cpp}/piece_picker.cpp | 0 library/{ => cpp}/policy.cpp | 0 library/{ => cpp}/pytorrent_core.cpp | 13 ++-- library/{ => cpp}/session.cpp | 0 library/{ => cpp}/session_impl.cpp | 0 library/{ => cpp}/sha1.cpp | 0 library/{ => cpp}/stat.cpp | 0 library/{ => cpp}/storage.cpp | 0 library/{ => cpp}/torrent.cpp | 0 library/{ => cpp}/torrent_handle.cpp | 0 library/{ => cpp}/torrent_info.cpp | 0 library/{ => cpp}/tracker_manager.cpp | 0 library/{ => cpp}/udp_tracker_connection.cpp | 0 library/{ => cpp}/web_peer_connection.cpp | 0 library/pytorrent.py | 16 ++--- library/setup.py | 2 + library/setup_naive.py | 66 +++++++++---------- library/state.txt | 0 library/test.py | 2 +- 38 files changed, 53 insertions(+), 46 deletions(-) rename library/{ => cpp}/alert.cpp (100%) rename library/{ => cpp}/allocate_resources.cpp (100%) rename library/{ => cpp}/bt_peer_connection.cpp (100%) rename library/{ => cpp}/entry.cpp (100%) rename library/{ => cpp}/escape_string.cpp (100%) rename library/{ => cpp}/file.cpp (100%) rename library/{ => cpp}/http_tracker_connection.cpp (100%) rename library/{ => cpp}/identify_client.cpp (100%) rename library/{ => cpp}/ip_filter.cpp (100%) rename library/{ => cpp}/kademlia/closest_nodes.cpp (100%) rename library/{ => cpp}/kademlia/dht_tracker.cpp (100%) rename library/{ => cpp}/kademlia/find_data.cpp (100%) rename library/{ => cpp}/kademlia/node.cpp (100%) rename library/{ => cpp}/kademlia/node_id.cpp (100%) rename library/{ => cpp}/kademlia/refresh.cpp (100%) rename library/{ => cpp}/kademlia/routing_table.cpp (100%) rename library/{ => cpp}/kademlia/rpc_manager.cpp (100%) rename library/{ => cpp}/kademlia/traversal_algorithm.cpp (100%) rename library/{ => cpp}/peer_connection.cpp (100%) rename library/{ => cpp}/piece_picker.cpp (100%) rename library/{ => cpp}/policy.cpp (100%) rename library/{ => cpp}/pytorrent_core.cpp (99%) rename library/{ => cpp}/session.cpp (100%) rename library/{ => cpp}/session_impl.cpp (100%) rename library/{ => cpp}/sha1.cpp (100%) rename library/{ => cpp}/stat.cpp (100%) rename library/{ => cpp}/storage.cpp (100%) rename library/{ => cpp}/torrent.cpp (100%) rename library/{ => cpp}/torrent_handle.cpp (100%) rename library/{ => cpp}/torrent_info.cpp (100%) rename library/{ => cpp}/tracker_manager.cpp (100%) rename library/{ => cpp}/udp_tracker_connection.cpp (100%) rename library/{ => cpp}/web_peer_connection.cpp (100%) delete mode 100644 library/state.txt diff --git a/library/alert.cpp b/library/cpp/alert.cpp similarity index 100% rename from library/alert.cpp rename to library/cpp/alert.cpp diff --git a/library/allocate_resources.cpp b/library/cpp/allocate_resources.cpp similarity index 100% rename from library/allocate_resources.cpp rename to library/cpp/allocate_resources.cpp diff --git a/library/bt_peer_connection.cpp b/library/cpp/bt_peer_connection.cpp similarity index 100% rename from library/bt_peer_connection.cpp rename to library/cpp/bt_peer_connection.cpp diff --git a/library/entry.cpp b/library/cpp/entry.cpp similarity index 100% rename from library/entry.cpp rename to library/cpp/entry.cpp diff --git a/library/escape_string.cpp b/library/cpp/escape_string.cpp similarity index 100% rename from library/escape_string.cpp rename to library/cpp/escape_string.cpp diff --git a/library/file.cpp b/library/cpp/file.cpp similarity index 100% rename from library/file.cpp rename to library/cpp/file.cpp diff --git a/library/http_tracker_connection.cpp b/library/cpp/http_tracker_connection.cpp similarity index 100% rename from library/http_tracker_connection.cpp rename to library/cpp/http_tracker_connection.cpp diff --git a/library/identify_client.cpp b/library/cpp/identify_client.cpp similarity index 100% rename from library/identify_client.cpp rename to library/cpp/identify_client.cpp diff --git a/library/ip_filter.cpp b/library/cpp/ip_filter.cpp similarity index 100% rename from library/ip_filter.cpp rename to library/cpp/ip_filter.cpp diff --git a/library/kademlia/closest_nodes.cpp b/library/cpp/kademlia/closest_nodes.cpp similarity index 100% rename from library/kademlia/closest_nodes.cpp rename to library/cpp/kademlia/closest_nodes.cpp diff --git a/library/kademlia/dht_tracker.cpp b/library/cpp/kademlia/dht_tracker.cpp similarity index 100% rename from library/kademlia/dht_tracker.cpp rename to library/cpp/kademlia/dht_tracker.cpp diff --git a/library/kademlia/find_data.cpp b/library/cpp/kademlia/find_data.cpp similarity index 100% rename from library/kademlia/find_data.cpp rename to library/cpp/kademlia/find_data.cpp diff --git a/library/kademlia/node.cpp b/library/cpp/kademlia/node.cpp similarity index 100% rename from library/kademlia/node.cpp rename to library/cpp/kademlia/node.cpp diff --git a/library/kademlia/node_id.cpp b/library/cpp/kademlia/node_id.cpp similarity index 100% rename from library/kademlia/node_id.cpp rename to library/cpp/kademlia/node_id.cpp diff --git a/library/kademlia/refresh.cpp b/library/cpp/kademlia/refresh.cpp similarity index 100% rename from library/kademlia/refresh.cpp rename to library/cpp/kademlia/refresh.cpp diff --git a/library/kademlia/routing_table.cpp b/library/cpp/kademlia/routing_table.cpp similarity index 100% rename from library/kademlia/routing_table.cpp rename to library/cpp/kademlia/routing_table.cpp diff --git a/library/kademlia/rpc_manager.cpp b/library/cpp/kademlia/rpc_manager.cpp similarity index 100% rename from library/kademlia/rpc_manager.cpp rename to library/cpp/kademlia/rpc_manager.cpp diff --git a/library/kademlia/traversal_algorithm.cpp b/library/cpp/kademlia/traversal_algorithm.cpp similarity index 100% rename from library/kademlia/traversal_algorithm.cpp rename to library/cpp/kademlia/traversal_algorithm.cpp diff --git a/library/peer_connection.cpp b/library/cpp/peer_connection.cpp similarity index 100% rename from library/peer_connection.cpp rename to library/cpp/peer_connection.cpp diff --git a/library/piece_picker.cpp b/library/cpp/piece_picker.cpp similarity index 100% rename from library/piece_picker.cpp rename to library/cpp/piece_picker.cpp diff --git a/library/policy.cpp b/library/cpp/policy.cpp similarity index 100% rename from library/policy.cpp rename to library/cpp/policy.cpp diff --git a/library/pytorrent_core.cpp b/library/cpp/pytorrent_core.cpp similarity index 99% rename from library/pytorrent_core.cpp rename to library/cpp/pytorrent_core.cpp index dda1e3965..a28abc210 100755 --- a/library/pytorrent_core.cpp +++ b/library/cpp/pytorrent_core.cpp @@ -281,7 +281,7 @@ static PyObject *torrent_pre_init(PyObject *self, PyObject *args) static PyObject *torrent_init(PyObject *self, PyObject *args) { - printf("pytorrent_core, using libtorrent %s. Compiled with NDEBUG value: %d\r\n", + printf("pytorrent_core; using libtorrent %s. Compiled with NDEBUG value: %d\r\n", LIBTORRENT_VERSION, NDEBUG); @@ -336,12 +336,17 @@ static PyObject *torrent_init(PyObject *self, PyObject *args) static PyObject *torrent_quit(PyObject *self, PyObject *args) { + printf("core: shutting down session...\r\n"); delete M_ses; // SLOWPOKE because of waiting for the trackers before shutting down + printf("core: removing settings...\r\n"); delete M_settings; + printf("core: removing torrents...\r\n"); delete M_torrents; Py_DECREF(M_constants); + printf("core shut down.\r\n"); + Py_INCREF(Py_None); return Py_None; }; @@ -813,22 +818,22 @@ static PyObject *torrent_get_peer_info(PyObject *self, PyObject *args) M_torrents->at(index).handle.get_peer_info(peers); PyObject *peer_info; - PyObject *ret = PyTuple_New(peers.size()); + PyObject *curr_piece, *py_pieces; for (unsigned long i = 0; i < peers.size(); i++) { std::vector &pieces = peers[i].pieces; unsigned long pieces_had = 0; - PyObject *py_pieces = PyTuple_New(pieces.size()); + py_pieces = PyTuple_New(pieces.size()); for (unsigned long piece = 0; piece < pieces.size(); piece++) { if (pieces[piece]) pieces_had++; - curr_piece = Py_BuildValue("i", pieces[piece]); + curr_piece = Py_BuildValue("i", long(pieces[piece])); PyTuple_SetItem(py_pieces, piece, curr_piece); } diff --git a/library/session.cpp b/library/cpp/session.cpp similarity index 100% rename from library/session.cpp rename to library/cpp/session.cpp diff --git a/library/session_impl.cpp b/library/cpp/session_impl.cpp similarity index 100% rename from library/session_impl.cpp rename to library/cpp/session_impl.cpp diff --git a/library/sha1.cpp b/library/cpp/sha1.cpp similarity index 100% rename from library/sha1.cpp rename to library/cpp/sha1.cpp diff --git a/library/stat.cpp b/library/cpp/stat.cpp similarity index 100% rename from library/stat.cpp rename to library/cpp/stat.cpp diff --git a/library/storage.cpp b/library/cpp/storage.cpp similarity index 100% rename from library/storage.cpp rename to library/cpp/storage.cpp diff --git a/library/torrent.cpp b/library/cpp/torrent.cpp similarity index 100% rename from library/torrent.cpp rename to library/cpp/torrent.cpp diff --git a/library/torrent_handle.cpp b/library/cpp/torrent_handle.cpp similarity index 100% rename from library/torrent_handle.cpp rename to library/cpp/torrent_handle.cpp diff --git a/library/torrent_info.cpp b/library/cpp/torrent_info.cpp similarity index 100% rename from library/torrent_info.cpp rename to library/cpp/torrent_info.cpp diff --git a/library/tracker_manager.cpp b/library/cpp/tracker_manager.cpp similarity index 100% rename from library/tracker_manager.cpp rename to library/cpp/tracker_manager.cpp diff --git a/library/udp_tracker_connection.cpp b/library/cpp/udp_tracker_connection.cpp similarity index 100% rename from library/udp_tracker_connection.cpp rename to library/cpp/udp_tracker_connection.cpp diff --git a/library/web_peer_connection.cpp b/library/cpp/web_peer_connection.cpp similarity index 100% rename from library/web_peer_connection.cpp rename to library/cpp/web_peer_connection.cpp diff --git a/library/pytorrent.py b/library/pytorrent.py index 9dc23b65b..729781d70 100644 --- a/library/pytorrent.py +++ b/library/pytorrent.py @@ -110,7 +110,7 @@ class cached_data: def get(self, efficiently=True): if self.timestamp == -1 or time.time() > self.timestamp + CACHED_DATA_EXPIRATION or \ not efficiently: - self.data = self.get_method(key) + self.data = self.get_method(self.key) self.timestamp = time.time() return self.data @@ -127,8 +127,6 @@ class torrent_info: self.user_paused = False # start out unpaused self.uploaded_memory = 0 - self.file_filter = [] - self.delete_me = False # set this to true, to delete it on next sync @@ -472,7 +470,7 @@ class manager: def apply_all_file_filters(self): for unique_ID in self.unique_IDs.keys(): try: - self.set_file_filter(self.unique_IDs[unique_ID].file_filter) + self.set_file_filter(unique_ID, self.unique_IDs[unique_ID].file_filter) except AttributeError: pass @@ -498,11 +496,11 @@ class manager: # Efficient: use a saved state, if it hasn't expired yet def get_core_torrent_state(self, unique_ID, efficiently=True): - if unique_ID not in self.saved_torrent_states.keys() - self.saved_torrent_states[unique_ID] = cached_data(pytorrent_core.get_torrent_state, + if unique_ID not in self.saved_core_torrent_states.keys(): + self.saved_core_torrent_states[unique_ID] = cached_data(pytorrent_core.get_torrent_state, unique_ID) - return self.saved_torrent_states[unique_ID].get(efficiently) + return self.saved_core_torrent_states[unique_ID].get(efficiently) def get_supp_torrent_state(self, unique_ID): try: @@ -520,7 +518,7 @@ class manager: self.supp_torrent_states[unique_ID][key] = val def get_core_torrent_peer_info(self, unique_ID, efficiently=True): - if unique_ID not in self.saved_torrent_peer_infos.keys() + if unique_ID not in self.saved_torrent_peer_infos.keys(): self.saved_torrent_peer_infos[unique_ID] = cached_data(pytorrent_core.get_peer_info, unique_ID) @@ -614,5 +612,7 @@ class manager: return ret def calc_availability(self, unique_ID): + pass def calc_swarm_speed(self, unique_ID): + pass diff --git a/library/setup.py b/library/setup.py index 8c4bd8b8c..259844432 100644 --- a/library/setup.py +++ b/library/setup.py @@ -54,6 +54,8 @@ for line in data: p.close() print "" +# else: +# print "NOT DOING: ", line # Now redo it, for real. Nothing should occur, except for installation, if requested print "Finalizing..." diff --git a/library/setup_naive.py b/library/setup_naive.py index 8d0611c19..ca73564ef 100644 --- a/library/setup_naive.py +++ b/library/setup_naive.py @@ -32,39 +32,39 @@ module1 = Extension('pytorrent_core', 'boost_serialization', 'boost_thread', 'z', 'pthread'], extra_compile_args = ["-Wno-missing-braces"], # extra_link_args = [""], - sources = ['alert.cpp', - 'allocate_resources.cpp', - 'bt_peer_connection.cpp', - 'entry.cpp', - 'escape_string.cpp', - 'file.cpp', - 'http_tracker_connection.cpp', - 'identify_client.cpp', - 'ip_filter.cpp', - 'peer_connection.cpp', - 'piece_picker.cpp', - 'policy.cpp', - 'pytorrent_core.cpp', - 'session.cpp', - 'session_impl.cpp', - 'sha1.cpp', - 'stat.cpp', - 'storage.cpp', - 'torrent.cpp', - 'torrent_handle.cpp', - 'torrent_info.cpp', - 'tracker_manager.cpp', - 'udp_tracker_connection.cpp', - 'web_peer_connection.cpp', - './kademlia/closest_nodes.cpp', - './kademlia/dht_tracker.cpp', - './kademlia/find_data.cpp', - './kademlia/node.cpp', - './kademlia/node_id.cpp', - './kademlia/refresh.cpp', - './kademlia/routing_table.cpp', - './kademlia/rpc_manager.cpp', - './kademlia/traversal_algorithm.cpp']) + sources = ['cpp/alert.cpp', + 'cpp/allocate_resources.cpp', + 'cpp/bt_peer_connection.cpp', + 'cpp/entry.cpp', + 'cpp/escape_string.cpp', + 'cpp/file.cpp', + 'cpp/http_tracker_connection.cpp', + 'cpp/identify_client.cpp', + 'cpp/ip_filter.cpp', + 'cpp/peer_connection.cpp', + 'cpp/piece_picker.cpp', + 'cpp/policy.cpp', + 'cpp/pytorrent_core.cpp', + 'cpp/session.cpp', + 'cpp/session_impl.cpp', + 'cpp/sha1.cpp', + 'cpp/stat.cpp', + 'cpp/storage.cpp', + 'cpp/torrent.cpp', + 'cpp/torrent_handle.cpp', + 'cpp/torrent_info.cpp', + 'cpp/tracker_manager.cpp', + 'cpp/udp_tracker_connection.cpp', + 'cpp/web_peer_connection.cpp', + 'cpp/kademlia/closest_nodes.cpp', + 'cpp/kademlia/dht_tracker.cpp', + 'cpp/kademlia/find_data.cpp', + 'cpp/kademlia/node.cpp', + 'cpp/kademlia/node_id.cpp', + 'cpp/kademlia/refresh.cpp', + 'cpp/kademlia/routing_table.cpp', + 'cpp/kademlia/rpc_manager.cpp', + 'cpp/kademlia/traversal_algorithm.cpp']) setup(name = 'pytorrent_core', version = '0.5.0', diff --git a/library/state.txt b/library/state.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/library/test.py b/library/test.py index a6c3064b9..7cc862b11 100644 --- a/library/test.py +++ b/library/test.py @@ -14,7 +14,7 @@ from time import sleep import os manager = pytorrent.manager("PT", "0500", "pytorrent - testing only", - os.path.expanduser("~") + "/Temp")#, blank_slate=True) + os.path.expanduser("~") + "/Temp")# blank_slate=True) #manager.set_pref('max_upload_rate', 6*1024)