You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.2 KiB
C++

#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>
#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
{
public:
int id;
std::string name;
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();
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()
{
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_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",NULL,0,0,NULL,0);
if(error)
{
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)");
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;
}
};
int main()
{
mix mix1;
mix1.init();
}