Browse Source

introducing libtorrent, first try

master
nkls 1 month ago
parent
commit
0a6a8a6fb9
4 changed files with 166 additions and 2 deletions
  1. +43
    -0
      notes.txt.save
  2. BIN
      src/mix
  3. +23
    -2
      src/mix.cpp
  4. +100
    -0
      src/mix.cpp.save

+ 43
- 0
notes.txt.save View File

@ -0,0 +1,43 @@
libtorrent:
settings_pack
session
add_torrent_params
torrent_handle
alert
torrent_finished_alert
torrent_error_alert
alert_cast
0x41727101980
public subscribe pattern
https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern
double identifiers
ID = nickname
Negative Tracker
IRC
magnet link
.torrent file
DHT (Kademlia)
PEX
tracker
peer ID
uTP
magnet:?xt=urn:btih:716E3D502B49B128781D12F7C8B58B1770CC5DE1&dn=Doctor%20Who%201963%20Season%2022%20Complete%20x264%20%5Bi_c%5D&tr=udp%3A%2F%2F
tracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F
tracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2F
tracker.dler.org%3A6969%2Fannounce&tr=udp%3A%2F%2F
opentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2F47.ip-51-68-199.eu%3A6969%2Fannounce
magnet:?xt=urn:btih:D540FC48EB12F2833163EED6421D449DD8F1CE1F&dn=Ubuntu%20desktop%2019.04%20(64bit)

BIN
src/mix View File


+ 23
- 2
src/mix.cpp View File

@ -9,6 +9,18 @@
#include <gpgme.h>
#include <boost/program_options.hpp>
#include <libtorrent/session.hpp>
#include <libtorrent/session_params.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 +28,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,6 +42,7 @@ class mix
std::cout << "name = " << name << std::endl;
std::cout << "id = " << id << std::endl;
// read_keys();
start_peer();
}
else
{
@ -90,6 +101,16 @@ class mix
}
}
void start_peer()
{
lt::settings_pack p;
lt::session ses(p);
std::vector<lt::alert*> alerts;
ses.pop_alerts(&alerts);
// lt::alert a;
std::cout << "Alert: " << alerts[0] << std::endl;
}
};


+ 100
- 0
src/mix.cpp.save View File

@ -0,0 +1,100 @@
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <fstream>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <exception>
#include <gpgme.h>
#include <boost/program_options.hpp>
namespace po=boost::program_options;
class mix
{
public:
int id;
std::string name;
char *privkey;
char *pubkey;
gpgme_data_t keydata;
gpgme_ctx_t context;
gpgme_error_t error;
gpgme_key_t key;
void init()
{
std::cout << "Mix starting..." << std::endl;
if(std::ifstream("mix.conf"))
{
std::cout << "Config file existing" << std::endl;
this->read_settings();
std::cout << "name = " << name << std::endl;
std::cout << "id = " << id << std::endl;
// read_keys();
create_keys();
}
else
{
std::cout << "Config file does not exist. Exiting." << std::endl;
std::exit(1);
}
}
void read_settings()
{
po::options_description desc("Options");
desc.add_options() ("name", po::value<std::string>(&name), "name");
desc.add_options() ("id", po::value<int>(&id), "id");
po::variables_map vm;
std::ifstream settings_file("mix.conf");
vm = po::variables_map();
po::store(po::parse_config_file(settings_file , desc), vm);
po::notify(vm);
}
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)
{
error = gpgme_op_keylist_next (context, &key);
if (error){break;}
std::cout << key->subkeys->keyid << std::endl;
if (key->uids && key->uids->name)
{
std::cout << key->uids->name << std::endl;
}
if (key->uids && key->uids->email)
{
std::cout << key->uids->email << std::endl;
}
}
}
void create_keys()
{
error=gpgme_op_createkey(context,"mix@pep.foundation","default",0,0,NULL,0);
if(error)
{
std::cout << "Key generated successfully" << std::endl;
}
else
}
};
int main()
{
mix mix1;
mix1.init();
}

Loading…
Cancel
Save