Browse Source

learning more about libtorrent

master
nkls 1 month ago
parent
commit
7ba80aeddf
5 changed files with 73 additions and 28 deletions
  1. +1
    -0
      Dockerfile.peer
  2. BIN
      src/.mix.cpp.swp
  3. BIN
      src/mix
  4. +25
    -14
      src/mix.cpp
  5. +47
    -14
      src/mix.cpp.save

+ 1
- 0
Dockerfile.peer View File

@ -25,6 +25,7 @@ RUN git clone --recurse-submodules https://github.com/arvidn/libtorrent
WORKDIR /code/libtorrent
RUN b2
RUN b2 install
WORKDIR /code/libtorrent/examples
RUN b2


BIN
src/.mix.cpp.swp View File


BIN
src/mix View File


+ 25
- 14
src/mix.cpp View File

@ -2,19 +2,20 @@
#include <iostream>
#include <cstring>
#include <fstream>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
//#include <openssl/rsa.h>
//#include <openssl/pem.h>
//#include <openssl/err.h>
#include <exception>
#include <gpgme.h>
#include <boost/program_options.hpp>
#include <libtorrent/session.hpp>
#include <libtorrent/session_params.hpp>
#include <libtorrent/kademlia/dht_state.hpp>
//#include <libtorrent/add_torrent_params.hpp>
//#include <libtorrent/torrent_handle.hpp>
//#include <libtorrent/alert_types.hpp>
//#include <libtorrent/magnet_uri.hpp>
#include <libtorrent/magnet_uri.hpp>
//#include <thread>
//#include <chrono>
@ -42,17 +43,17 @@ class mix
std::cout << "name = " << name << std::endl;
std::cout << "id = " << id << std::endl;
// read_keys();
start_peer();
start_peer();
}
else
{
std::cout << "Config file does not exist. Exiting." << std::endl;
std::exit(1);
}
std::cout << "Looking for keys" << std::endl;
gpgme_check_version(NULL);
gpgme_new(&context);
create_keys();
// std::cout << "Looking for keys" << std::endl;
// gpgme_check_version(NULL);
// gpgme_new(&context);
// create_keys();
}
void read_settings()
@ -97,19 +98,29 @@ class mix
}
else
{
std::cout << "Key generated successfully" << std::endl;
std::cout << "Keys generated successfully" << std::endl;
}
}
void start_peer()
{
lt::settings_pack p;
p.set_int(lt::settings_pack::alert_mask,lt::alert_category::status | lt::alert_category::error);
lt::session ses(p);
std::vector<lt::alert*> alerts;
ses.pop_alerts(&alerts);
lt::add_torrent_params atp = lt::parse_magnet_uri("magnet:?xt=urn:btih:D540FC48EB12F2833163EED6421D449DD8F1CE1F&dn=Ubuntu%20desktop%2019.04%20(64bit)");
atp.save_path=".";
lt::torrent_handle h = ses.add_torrent(std::move(atp));
// lt::dht::dht_state dst;
// dst=ses.dht_state();
// std::cout << ses.dht_state << std::endl;
// std::vector<lt::alert*> alerts; ses.pop_alerts(&alerts);
// lt::alert a;
std::cout << "Alert: " << alerts[0] << std::endl;
}
};


+ 47
- 14
src/mix.cpp.save View File

@ -2,13 +2,26 @@
#include <iostream>
#include <cstring>
#include <fstream>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
//#include <openssl/rsa.h>
//#include <openssl/pem.h>
//#include <openssl/err.h>
#include <exception>
#include <gpgme.h>
#include <boost/program_options.hpp>
#include <libtorrent/session.hpp>
#include <libtorrent/session_params.hpp>
#include <libtorrent/kademlia/dht_state.hpp>
//#include <libtorrent/add_torrent_params.hpp>
//#include <libtorrent/torrent_handle.hpp>
//#include <libtorrent/alert_types.hpp>
//#include <libtorrent/magnet_uri.hpp>
//#include <thread>
//#include <chrono>
namespace po=boost::program_options;
class mix
@ -16,8 +29,6 @@ class mix
public:
int id;
std::string name;
char *privkey;
char *pubkey;
gpgme_data_t keydata;
gpgme_ctx_t context;
gpgme_error_t error;
@ -32,15 +43,19 @@ class mix
std::cout << "name = " << name << std::endl;
std::cout << "id = " << id << std::endl;
// read_keys();
create_keys();
start_peer();
}
else
{
std::cout << "Config file does not exist. Exiting." << std::endl;
std::exit(1);
}
// std::cout << "Looking for keys" << std::endl;
// gpgme_check_version(NULL);
// gpgme_new(&context);
// create_keys();
}
void read_settings()
{
@ -57,8 +72,6 @@ class mix
void read_keys()
{
gpgme_data_new_from_file(&keydata, "keys.gpg", 1);
gpgme_check_version(NULL);
gpgme_new(&context);
gpgme_op_import(context, keydata);
gpgme_op_keylist_start (context, "mix", 0);
while(!error)
@ -78,16 +91,36 @@ class mix
}
void create_keys()
{
error=gpgme_op_createkey(context,"mix@pep.foundation","default",0,0,NULL,0);
error=gpgme_op_createkey(context,"mix@pep.foundation",NULL,0,0,NULL,0);
if(error)
{
std::cout << "Key generated successfully" << std::endl;
{
std::cout << "Error generating keys" << error << std::endl;
}
else
{
std::cout << "Keys generated successfully" << std::endl;
}
}
void start_peer()
{
lt::settings_pack p;
p.set_int(lt::settings_pack::alert_mask,lt::alert_category::status | lt::alert_category::error);
lt::session ses(p);
lt::add_torrent_params atp = lt::parse_magnet_uri("magnet:?xt=urn:btih:D540FC48EB12F2833163EED6421D449DD8F1CE1F&dn=Ubuntu%20desktop%2019.04%20(64bit)%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce");
// lt::dht::dht_state dst;
// dst=ses.dht_state();
// std::cout << ses.dht_state << std::endl;
// std::vector<lt::alert*> alerts; ses.pop_alerts(&alerts);
// lt::alert a;
}
};


Loading…
Cancel
Save