Repository navigation
Expand file tree
/
Copy pathconsole.ic
More file actions
77 lines (71 loc) · 2.68 KB
/
Copy pathconsole.ic
File metadata and controls
77 lines (71 loc) · 2.68 KB
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
/***************************************************************************
* Copyright (C) 2012 by Tobias Volk *
* mail@tobiasvolk.de *
* *
* 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[8192];
p2psecStatus(g_p2psec, str, 8192);
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_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] == 'I' || pa[0] == 'i') {
// INSERTPEER <address>
if(ioGetUDPAddress(&iostate, new_peeraddr.addr, pb, pc)) {
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] == '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");
}
}
}