*** empty log message ***

This commit is contained in:
Arvid Norberg 2003-10-26 17:35:23 +00:00
parent d2f7be1608
commit fca86964f8
7 changed files with 148 additions and 118 deletions

View File

@ -136,7 +136,7 @@ The <tt>session</tt> class has the following synopsis:
<pre>
class session: public boost::noncopyable
{
session(int listen_port);
session(int listen_port, const std::string&amp; fingerprint = std::string());
torrent_handle add_torrent(const torrent_info&amp; t, const std::string&amp; save_path);
@ -153,6 +153,13 @@ want to save the files. The <tt>save_path</tt> will be prepended to the director
structure in the torrent-file.
</p>
<p>
<tt>fingerprint</tt> is a short string that will be used in the peer_id to
identify the client. If you want your fingerprint to be shorter than 4
characters, you can terminate the string with a null. The default is an
empty string.
</p>
<p>
How to parse a torrent file and create a <tt>torrent_info</tt> object is described below.
</p>
@ -597,7 +604,6 @@ struct http_settings
std::string user_agent;
int tracker_timeout;
int tracker_maximum_response_length;
char fingerprint[4];
};
</pre>
@ -617,13 +623,6 @@ uncompressed (given your limit is lower than 2 megs). Default limit is
1 megabyte.
</p>
<p>
<tt>fingerprint</tt> is a short string that will be used in the peer_id to
identify the client. If you want your fingerprint to be shorter than 4
characters, you can terminate the string with a null. The default is an
empty string.
</p>
<h2><a name="big_number"></a>big_number</h2>
<p>

View File

@ -59,13 +59,10 @@ int main(int argc, char* argv[])
// settings.proxy_password = "foobar";
settings.user_agent = "example";
const char* fingerprint = "ex01";
std::copy(fingerprint, fingerprint+4, settings.fingerprint);
try
{
std::vector<torrent_handle> handles;
session s(6881);
session s(6881, "ex-01");
s.set_http_settings(settings);
for (int i = 0; i < argc-1; ++i)

View File

@ -45,7 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_SESION_HPP_INCLUDED
#ifndef TORRENT_SESSION_HPP_INCLUDED
#define TORRENT_SESSION_HPP_INCLUDED
#include <ctime>
@ -59,6 +59,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem/path.hpp>
#include <boost/thread.hpp>
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/torrent.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/torrent_info.hpp"
@ -115,10 +116,7 @@ namespace libtorrent
{
typedef std::map<boost::shared_ptr<socket>, boost::shared_ptr<peer_connection> > connection_map;
session_impl()
: m_abort(false)
, m_tracker_manager(m_settings)
{}
session_impl(const std::string& fingerprint);
// must be locked to access the data
// in this struct
@ -191,42 +189,13 @@ namespace libtorrent
std::string extract_fingerprint(const peer_id& p);
struct torrent_handle
{
friend class session;
torrent_handle(): m_ses(0) {}
float progress() const;
void get_peer_info(std::vector<peer_info>& v);
void abort();
enum state_t
{
checking_files,
connecting_to_tracker,
downloading,
seeding
};
// state_t state() const;
private:
torrent_handle(detail::session_impl* s, const sha1_hash& h)
: m_ses(s)
, m_info_hash(h)
{}
detail::session_impl* m_ses;
sha1_hash m_info_hash; // should be replaced with a torrent*?
};
class session: public boost::noncopyable
{
public:
session(int listen_port)
: m_thread(detail::main_loop_thread(listen_port, &m_impl)) {}
session(int listen_port, const std::string& fingerprint = std::string())
: m_impl(fingerprint)
, m_thread(detail::main_loop_thread(listen_port, &m_impl)) {}
~session();

View File

@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem/path.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/socket.hpp"
@ -119,13 +120,7 @@ namespace libtorrent
int bytes_uploaded() const { return m_bytes_uploaded; }
int bytes_left() const { return m_storage.bytes_left(); }
// TODO: temporary implementation. Should count the actually
// verified pieces and should support the different states
// a torrent can be in.
float progress() const
{
return bytes_downloaded() / static_cast<float>(m_torrent_file.total_size());
}
std::pair<torrent_handle::state_t, float> status() const;
void connect_to_peer(const address& a, const peer_id& id);

View File

@ -0,0 +1,82 @@
/*
Copyright (c) 2003, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_TORRENT_HANDLE_HPP_INCLUDED
#define TORRENT_TORRENT_HANDLE_HPP_INCLUDED
#include <vector>
#include "libtorrent/peer_id.hpp"
#include "libtorrent/peer_info.hpp"
namespace libtorrent
{
namespace detail
{
struct session_impl;
}
struct torrent_handle
{
friend class session;
torrent_handle(): m_ses(0) {}
void get_peer_info(std::vector<peer_info>& v);
void abort();
enum state_t
{
invalid_handle,
checking_files,
connecting_to_tracker,
downloading,
seeding
};
std::pair<state_t, float> status() const;
private:
torrent_handle(detail::session_impl* s, const sha1_hash& h)
: m_ses(s)
, m_info_hash(h)
{}
detail::session_impl* m_ses;
sha1_hash m_info_hash; // should be replaced with a torrent*?
};
}
#endif // TORRENT_TORRENT_HANDLE_HPP_INCLUDED

View File

@ -70,74 +70,53 @@ but also CPU-wise. This goal has a number of implications:
to scale better when having many peer connections.
*
*/
namespace
{
using namespace libtorrent;
peer_id generate_peer_id(const http_settings& s)
{
peer_id ret;
std::srand(std::time(0));
/*
std::fill(ret.begin(), ret.end(), 0);
std::copy(s.fingerprint, s.fingerprint+4, std::ostream_iterator<int>(std::cout, " "));
std::cout << "\n";
*/
// libtorrent's fingerprint
unsigned char fingerprint[] = "lt.";
const int len = 3-(s.fingerprint[0] == 0?1:0);
std::copy(fingerprint, fingerprint+len, ret.begin());
// std::copy(ret.begin(), ret.end(), std::ostream_iterator<int>(std::cout, " "));
// std::cout << "\n";
// the client's fingerprint
const int len2 = std::find(s.fingerprint, s.fingerprint+sizeof(s.fingerprint), 0)
- s.fingerprint;
// std::cout << "len: " << len << "\n";
// std::cout << "len2: " << len2 << "\n";
std::copy(s.fingerprint, s.fingerprint+len2, ret.begin()+len);
// std::copy(ret.begin(), ret.end(), std::ostream_iterator<int>(std::cout, " "));
// std::cout << "\n";
// the zeros
std::fill(ret.begin()+len+len2, ret.begin()+len+len2+3, 0);
// std::copy(ret.begin(), ret.end(), std::ostream_iterator<int>(std::cout, " "));
// std::cout << "\n";
// the random number
for (unsigned char* i = ret.begin()+len+len2+3;
i != ret.end();
++i)
{
*i = rand();
}
// std::copy(ret.begin(), ret.end(), std::ostream_iterator<int>(std::cout, " "));
// std::cout << "\n";
return ret;
}
}
namespace libtorrent
{
namespace detail
{
session_impl::session_impl(const std::string& cl_fprint)
: m_abort(false)
, m_tracker_manager(m_settings)
{
// ---- generate a peer id ----
std::srand(std::time(0));
// libtorrent's fingerprint
unsigned char fingerprint[] = "lt.";
const int len2 = std::min(cl_fprint.length(), (long)7);
const int len1 = (len2 == 0?2:3);
const int len3 = 12 - len1 - len2;
std::copy(fingerprint, fingerprint+len1, m_peer_id.begin());
// the client's fingerprint
std::copy(cl_fprint.begin(), cl_fprint.begin()+len2, m_peer_id.begin()+len1);
// the zeros
std::fill(m_peer_id.begin()+len1+len2, m_peer_id.begin()+len1+len2+len3, 0);
assert(len1 + len2 + len3 == 12);
// the random number
for (unsigned char* i = m_peer_id.begin()+len1+len2+len3;
i != m_peer_id.end();
++i)
{
*i = rand();
}
}
void session_impl::run(int listen_port)
{
#if defined(TORRENT_VERBOSE_LOGGING)
m_logger = create_log("main session");
#endif
// TODO: don't generate peer id until we need it
// this way it's possible to set the fingerprint
m_peer_id = generate_peer_id(m_settings);
boost::shared_ptr<socket> listener(new socket(socket::tcp, false));
int max_port = listen_port + 9;
@ -509,15 +488,15 @@ namespace libtorrent
m_thread.join();
}
float torrent_handle::progress() const
std::pair<torrent_handle::state_t, float> torrent_handle::status() const
{
if (m_ses == 0) return 0.f;
if (m_ses == 0) return std::make_pair(invalid_handle, 0.f);
boost::mutex::scoped_lock l(m_ses->m_mutex);
std::map<sha1_hash, boost::shared_ptr<torrent> >::iterator i = m_ses->m_torrents.find(m_info_hash);
if (i == m_ses->m_torrents.end()) return 0.f;
return i->second->progress();
if (i == m_ses->m_torrents.end()) return std::make_pair(invalid_handle, 0.f);
return i->second->status();
}
void torrent_handle::get_peer_info(std::vector<peer_info>& v)

View File

@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/convenience.hpp>
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/url_handler.hpp"
@ -400,5 +401,13 @@ namespace libtorrent
}
}
// TODO: temporary implementation. Should count the actually
// verified pieces and should support the different states
// a torrent can be in.
std::pair<torrent_handle::state_t, float> torrent::status() const
{
return std::make_pair(torrent_handle::downloading, 0.f);
}
}