-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.c
77 lines (59 loc) · 1.37 KB
/
test.c
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
#include "lnsocket.h"
#include "endian.h"
#include "typedefs.h"
#include <stdio.h>
#include <assert.h>
#include <sodium/randombytes.h>
static void print_data(unsigned char *buf, int len)
{
int i;
for (i = 0; i < len; i++) {
printf("%02x", buf[i]);
}
printf("\n");
}
int main(int argc, const char *argv[])
{
static u8 msgbuf[4096];
u8 *buf;
u16 msgtype;
struct lnsocket *ln;
static unsigned char key[32] = {0};
u16 len;
int ok = 1;
ln = lnsocket_create();
assert(ln);
if (lnsocket_setkey(ln, key)) {
// key with 0s should be an error
ok = 0;
goto done;
}
randombytes_buf(key, sizeof(key));
if (!(ok = lnsocket_setkey(ln, key)))
goto done;
const char *nodeid = "03f3c108ccd536b8526841f0a5c58212bb9e6584a1eb493080e7c1cc34f82dad71";
if (!(ok = lnsocket_connect(ln, nodeid, "24.84.152.187")))
goto done;
if (!(ok = lnsocket_perform_init(ln)))
goto done;
printf("init ok!\n");
if (!(ok = len = lnsocket_make_ping_msg(msgbuf, sizeof(msgbuf), 1, 1)))
goto done;
if (!(ok = lnsocket_write(ln, msgbuf, len)))
goto done;
printf("sent ping ");
print_data(msgbuf, len);
for (int packets = 0; packets < 3; packets++) {
if (!(ok = lnsocket_recv(ln, &msgtype, &buf, &len)))
goto done;
if (msgtype == WIRE_PONG) {
printf("got pong! ");
print_data(buf, len);
break;
}
}
done:
lnsocket_print_errors(ln);
lnsocket_destroy(ln);
return !ok;
}