new .cpp directory

This commit is contained in:
Alon Zakai
2006-12-08 14:17:36 +00:00
parent 460dfd76a5
commit 406135df66
38 changed files with 53 additions and 46 deletions

View File

@@ -281,7 +281,7 @@ static PyObject *torrent_pre_init(PyObject *self, PyObject *args)
static PyObject *torrent_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, LIBTORRENT_VERSION,
NDEBUG); NDEBUG);
@@ -336,12 +336,17 @@ static PyObject *torrent_init(PyObject *self, PyObject *args)
static PyObject *torrent_quit(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 delete M_ses; // SLOWPOKE because of waiting for the trackers before shutting down
printf("core: removing settings...\r\n");
delete M_settings; delete M_settings;
printf("core: removing torrents...\r\n");
delete M_torrents; delete M_torrents;
Py_DECREF(M_constants); Py_DECREF(M_constants);
printf("core shut down.\r\n");
Py_INCREF(Py_None); return Py_None; 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); M_torrents->at(index).handle.get_peer_info(peers);
PyObject *peer_info; PyObject *peer_info;
PyObject *ret = PyTuple_New(peers.size()); PyObject *ret = PyTuple_New(peers.size());
PyObject *curr_piece, *py_pieces;
for (unsigned long i = 0; i < peers.size(); i++) for (unsigned long i = 0; i < peers.size(); i++)
{ {
std::vector<bool> &pieces = peers[i].pieces; std::vector<bool> &pieces = peers[i].pieces;
unsigned long pieces_had = 0; 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++) for (unsigned long piece = 0; piece < pieces.size(); piece++)
{ {
if (pieces[piece]) if (pieces[piece])
pieces_had++; pieces_had++;
curr_piece = Py_BuildValue("i", pieces[piece]); curr_piece = Py_BuildValue("i", long(pieces[piece]));
PyTuple_SetItem(py_pieces, piece, curr_piece); PyTuple_SetItem(py_pieces, piece, curr_piece);
} }

View File

@@ -110,7 +110,7 @@ class cached_data:
def get(self, efficiently=True): def get(self, efficiently=True):
if self.timestamp == -1 or time.time() > self.timestamp + CACHED_DATA_EXPIRATION or \ if self.timestamp == -1 or time.time() > self.timestamp + CACHED_DATA_EXPIRATION or \
not efficiently: not efficiently:
self.data = self.get_method(key) self.data = self.get_method(self.key)
self.timestamp = time.time() self.timestamp = time.time()
return self.data return self.data
@@ -127,8 +127,6 @@ class torrent_info:
self.user_paused = False # start out unpaused self.user_paused = False # start out unpaused
self.uploaded_memory = 0 self.uploaded_memory = 0
self.file_filter = []
self.delete_me = False # set this to true, to delete it on next sync 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): def apply_all_file_filters(self):
for unique_ID in self.unique_IDs.keys(): for unique_ID in self.unique_IDs.keys():
try: 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: except AttributeError:
pass pass
@@ -498,11 +496,11 @@ class manager:
# Efficient: use a saved state, if it hasn't expired yet # Efficient: use a saved state, if it hasn't expired yet
def get_core_torrent_state(self, unique_ID, efficiently=True): def get_core_torrent_state(self, unique_ID, efficiently=True):
if unique_ID not in self.saved_torrent_states.keys() if unique_ID not in self.saved_core_torrent_states.keys():
self.saved_torrent_states[unique_ID] = cached_data(pytorrent_core.get_torrent_state, self.saved_core_torrent_states[unique_ID] = cached_data(pytorrent_core.get_torrent_state,
unique_ID) 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): def get_supp_torrent_state(self, unique_ID):
try: try:
@@ -520,7 +518,7 @@ class manager:
self.supp_torrent_states[unique_ID][key] = val self.supp_torrent_states[unique_ID][key] = val
def get_core_torrent_peer_info(self, unique_ID, efficiently=True): 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, self.saved_torrent_peer_infos[unique_ID] = cached_data(pytorrent_core.get_peer_info,
unique_ID) unique_ID)
@@ -614,5 +612,7 @@ class manager:
return ret return ret
def calc_availability(self, unique_ID): def calc_availability(self, unique_ID):
pass
def calc_swarm_speed(self, unique_ID): def calc_swarm_speed(self, unique_ID):
pass

View File

@@ -54,6 +54,8 @@ for line in data:
p.close() p.close()
print "" print ""
# else:
# print "NOT DOING: ", line
# Now redo it, for real. Nothing should occur, except for installation, if requested # Now redo it, for real. Nothing should occur, except for installation, if requested
print "Finalizing..." print "Finalizing..."

View File

@@ -32,39 +32,39 @@ module1 = Extension('pytorrent_core',
'boost_serialization', 'boost_thread', 'z', 'pthread'], 'boost_serialization', 'boost_thread', 'z', 'pthread'],
extra_compile_args = ["-Wno-missing-braces"], extra_compile_args = ["-Wno-missing-braces"],
# extra_link_args = [""], # extra_link_args = [""],
sources = ['alert.cpp', sources = ['cpp/alert.cpp',
'allocate_resources.cpp', 'cpp/allocate_resources.cpp',
'bt_peer_connection.cpp', 'cpp/bt_peer_connection.cpp',
'entry.cpp', 'cpp/entry.cpp',
'escape_string.cpp', 'cpp/escape_string.cpp',
'file.cpp', 'cpp/file.cpp',
'http_tracker_connection.cpp', 'cpp/http_tracker_connection.cpp',
'identify_client.cpp', 'cpp/identify_client.cpp',
'ip_filter.cpp', 'cpp/ip_filter.cpp',
'peer_connection.cpp', 'cpp/peer_connection.cpp',
'piece_picker.cpp', 'cpp/piece_picker.cpp',
'policy.cpp', 'cpp/policy.cpp',
'pytorrent_core.cpp', 'cpp/pytorrent_core.cpp',
'session.cpp', 'cpp/session.cpp',
'session_impl.cpp', 'cpp/session_impl.cpp',
'sha1.cpp', 'cpp/sha1.cpp',
'stat.cpp', 'cpp/stat.cpp',
'storage.cpp', 'cpp/storage.cpp',
'torrent.cpp', 'cpp/torrent.cpp',
'torrent_handle.cpp', 'cpp/torrent_handle.cpp',
'torrent_info.cpp', 'cpp/torrent_info.cpp',
'tracker_manager.cpp', 'cpp/tracker_manager.cpp',
'udp_tracker_connection.cpp', 'cpp/udp_tracker_connection.cpp',
'web_peer_connection.cpp', 'cpp/web_peer_connection.cpp',
'./kademlia/closest_nodes.cpp', 'cpp/kademlia/closest_nodes.cpp',
'./kademlia/dht_tracker.cpp', 'cpp/kademlia/dht_tracker.cpp',
'./kademlia/find_data.cpp', 'cpp/kademlia/find_data.cpp',
'./kademlia/node.cpp', 'cpp/kademlia/node.cpp',
'./kademlia/node_id.cpp', 'cpp/kademlia/node_id.cpp',
'./kademlia/refresh.cpp', 'cpp/kademlia/refresh.cpp',
'./kademlia/routing_table.cpp', 'cpp/kademlia/routing_table.cpp',
'./kademlia/rpc_manager.cpp', 'cpp/kademlia/rpc_manager.cpp',
'./kademlia/traversal_algorithm.cpp']) 'cpp/kademlia/traversal_algorithm.cpp'])
setup(name = 'pytorrent_core', setup(name = 'pytorrent_core',
version = '0.5.0', version = '0.5.0',

View File

View File

@@ -14,7 +14,7 @@ from time import sleep
import os import os
manager = pytorrent.manager("PT", "0500", "pytorrent - testing only", 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) #manager.set_pref('max_upload_rate', 6*1024)