-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainWindow.cpp
52 lines (48 loc) · 1.3 KB
/
MainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <fstream>
#include "util.h"
#include "MainWindow.h"
MainWindow::MainWindow (QWidget* parent):
QMainWindow (parent)
{
// local uid
InitLocalUIDDestination ();
// tray icon
m_TrayIcon = new QSystemTrayIcon (this);
m_TrayIcon->setToolTip("I2Q");
m_TrayIcon->show();
}
MainWindow::~MainWindow()
{
if (m_LocalUIDDestination)
m_LocalUIDDestination->Stop ();
delete m_TrayIcon;
}
void MainWindow::InitLocalUIDDestination ()
{
static const char filename[] = "uid.dat";
i2p::data::PrivateKeys keys;
std::string fullPath = i2p::util::filesystem::GetFullPath (filename);
std::ifstream s(fullPath.c_str (), std::ifstream::binary);
if (s.is_open ())
{
s.seekg (0, std::ios::end);
size_t len = s.tellg();
s.seekg (0, std::ios::beg);
uint8_t * buf = new uint8_t[len];
s.read ((char *)buf, len);
keys.FromBuffer (buf, len);
delete[] buf;
}
else
{
keys = i2p::data::PrivateKeys::CreateRandomKeys (i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
size_t len = keys.GetFullLen ();
uint8_t * buf = new uint8_t[len];
len = keys.ToBuffer (buf, len);
f.write ((char *)buf, len);
delete[] buf;
}
m_LocalUIDDestination = std::make_shared<i2p::client::ClientDestination>(keys, true);
m_LocalUIDDestination->Start ();
}