forked from strfry/peervpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.ic
132 lines (118 loc) · 3.65 KB
/
console.ic
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
* Copyright (C) 2015 by Tobias Volk *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
// print table of active peers
static void printActivePeerTable() {
char str[32768];
p2psecStatus(g_p2psec, str, 32768);
printf("%s\n", str);
}
// print NodeDB
static void printNodeDB() {
char str[32768];
p2psecNodeDBStatus(g_p2psec, str, 32768);
printf("%s\n", str);
}
// print RelayDB
static void printRelayDB() {
char str[32768];
nodedbStatus(&g_p2psec->mgt.relaydb, str, 32768);
printf("%s\n", str);
}
// print table of mac addrs
static void printMacTable() {
char str[32768];
switchStatus(&g_switchstate, str, 32768);
printf("%s\n", str);
}
// print table of ndp cache
static void printNDPTable() {
char str[32768];
ndp6Status(&g_ndpstate, str, 32768);
printf("%s\n", str);
}
// parse command
static void decodeConsole(char *cmd, int cmdlen) {
char text[4096];
char pa[1024];
char pb[1024];
char pc[1024];
int i, j;
struct s_io_addrinfo new_peeraddrs;
struct s_peeraddr new_peeraddr;
pa[0] = '\0';
pb[0] = '\0';
pc[0] = '\0';
sscanf(cmd,"%s %s %s",pa,pb,pc);
if(pa[0] == 'A' || pa[0] == 'a') {
// ACTIVEPEERTABLE
printActivePeerTable();
}
if(pa[0] == 'D' || pa[0] == 'd') {
// DB
printNodeDB();
}
if(pa[0] == 'F' || pa[0] == 'f') {
// FDB
printRelayDB();
}
if(pa[0] == 'I' || pa[0] == 'i') {
// INSERTPEER <address>
if(ioResolveName(&new_peeraddrs, pb, pc)) {
for(i=0; i<new_peeraddrs.count; i++) {
if(p2psecConnect(g_p2psec, new_peeraddrs.item[i].addr)) {
utilByteArrayToHexstring(text, 4096, new_peeraddrs.item[i].addr, peeraddr_SIZE);
printf("connecting to %s...\n", text);
}
}
}
else {
printf("could not get peer address.\n");
}
}
if(pa[0] == 'M' || pa[0] == 'm') {
// MACTABLE
printMacTable();
}
if(pa[0] == 'N' || pa[0] == 'n') {
// NDPTABLE
printNDPTable();
}
if(pa[0] == 'P' || pa[0] == 'p') {
// PEERTABLE
printActivePeerTable();
}
if(pa[0] == 'R' || pa[0] == 'r') {
// RELAYEDINSERTPEER <relayid> <relaypeerid>
sscanf(pb,"%d",&i);
sscanf(pc,"%d",&j);
if(peermgtIsActiveRemoteID(&g_p2psec->mgt, i)) {
peeraddrSetIndirect(&new_peeraddr, i, g_p2psec->mgt.data[i].conntime, j);
if(p2psecConnect(g_p2psec, new_peeraddr.addr)) {
utilByteArrayToHexstring(text, 4096, new_peeraddr.addr, peeraddr_SIZE);
printf("connecting to %s...\n", text);
}
}
else {
printf("could not get peer address.\n");
}
}
if(pa[0] == 'Q' || pa[0] == 'q') {
// QUIT
g_mainloop = 0;
}
}