-
Notifications
You must be signed in to change notification settings - Fork 10
/
n2nworker.cpp
66 lines (57 loc) · 1.78 KB
/
n2nworker.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "n2nworker.h"
#include <QDebug>
N2NWorker::N2NWorker(int* keep_on_running, QObject *parent) : QObject(parent)
{
this->keep_on_running = keep_on_running;
}
void N2NWorker::connect(
QString supernode_addr,
QString community_name,
QString secret_key,
QString subnet,
QString virtual_ip
)
{
QByteArray ip = virtual_ip.toLatin1();
QByteArray secret = secret_key.toLatin1();
QByteArray addr = supernode_addr.toLatin1();
QByteArray subnet_mask = subnet.toLatin1();
QByteArray community = community_name.toLatin1();
int rv;
/* Setup the configuration */
n2n_edge_t *eee;
tuntap_dev tuntap;
n2n_edge_conf_t conf;
edge_init_conf_defaults(&conf);
conf.encrypt_key = secret.data();
conf.transop_id = N2N_TRANSFORM_ID_TWOFISH;
snprintf((char*)conf.community_name, sizeof(conf.community_name), "%s", community.data());
edge_conf_add_supernode(&conf, addr.data());
qDebug() << "N2NWorker: Finish setup configuration.";
/* Validate configuration */
if(edge_verify_conf(&conf) != 0){
qDebug() << "N2NWorker: Configuration error.";
emit error(N2NWorkerError::CONFIG);
return;
}
if(tuntap_open(&tuntap,
(char*) "",
"static",
ip.data(),
subnet_mask.data(),
(char*) "",
DEFAULT_MTU) < 0){
emit error(N2NWorkerError::WINTAP);
emit disconnected();
return;
}
/* Init edge */
if((eee = edge_init(&tuntap, &conf, &rv)) == NULL)
goto quick_edge_init_end;
emit connected();
rv = run_edge_loop(eee, keep_on_running);
edge_term(eee);
quick_edge_init_end:
emit disconnected();
tuntap_close(&tuntap);
}