Compare commits
86 Commits
b59ab48407
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
e4988b9e9c
|
|||
|
0183b35acf
|
|||
|
|
faeb599a19 | ||
|
|
a4e72918df | ||
|
|
d7e8dbe0e7 | ||
|
|
71d16f25ff | ||
|
|
c426cef08b | ||
|
|
bda2c6eaa7 | ||
|
|
d68aee8249 | ||
|
|
2f966bb365 | ||
|
|
4a7740f70f | ||
|
|
5be4096452 | ||
|
|
3747aa7abd | ||
|
|
e3eb1f96a5 | ||
|
|
2f5e346532 | ||
|
|
a9fdd76fa3 | ||
|
|
0a9a139409 | ||
|
|
2811e2383f | ||
|
|
ed6cc0e6f6 | ||
|
|
487474a80e | ||
|
|
edb86d27ad | ||
|
|
c0d2118a77 | ||
|
|
70e80f76e0 | ||
|
|
e4092ebebd | ||
|
|
2330e6470e | ||
|
|
7d59eedd39 | ||
|
|
c536bef802 | ||
|
|
23a5cdfe31 | ||
|
|
6894867b9f | ||
|
|
8f11ffa5a4 | ||
|
|
1f18b731c4 | ||
|
|
e3689d29b7 | ||
|
|
2a812f332f | ||
|
|
b16a754713 | ||
|
|
b6238c939e | ||
|
|
6e8a3cef1e | ||
|
|
e56abf5eaa | ||
|
|
6b1881e94c | ||
|
|
7ff46e742b | ||
|
|
a87a277701 | ||
|
|
ef41aa28ce | ||
|
|
d5322e187d | ||
|
|
0a2b23bb88 | ||
|
|
3a30c63eff | ||
|
|
9c27f92f9d | ||
|
|
9e3e2b358b | ||
|
|
a6acb8736c | ||
|
|
3d4e3a8fbe | ||
|
|
97407b2527 | ||
|
|
dc22121739 | ||
|
|
06c0945ac5 | ||
|
|
2b19c80ae3 | ||
|
|
21b15727c5 | ||
|
|
569e712248 | ||
|
|
8c033a12a1 | ||
|
|
6b58ebb993 | ||
|
|
7179de77da | ||
|
|
e6a8c8e013 | ||
|
|
137971e957 | ||
|
|
9abb50a7e2 | ||
|
|
2766a94e3b | ||
|
|
c420e9494a | ||
|
|
407db114c6 | ||
|
|
0537b01d4b | ||
|
|
79dc61e7dc | ||
|
|
67a660117e | ||
|
|
831714e07f | ||
|
|
f047af8148 | ||
|
|
8948d00545 | ||
|
|
2e8a13f135 | ||
|
|
f647519e1c | ||
|
|
94ae912138 | ||
|
|
e3b56376dc | ||
|
|
8c88934763 | ||
|
|
d0dc6076c8 | ||
|
|
842dadad94 | ||
|
|
d086d7869d | ||
|
|
d4d97177eb | ||
|
|
7254e15a02 | ||
|
|
ee4b484a38 | ||
|
|
9a378aea99 | ||
|
|
3db88eb23c | ||
|
|
c4d2ef7d97 | ||
|
|
00f18733d8 | ||
|
|
4d14689ff1 | ||
|
|
027196026b |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.[ios]
|
||||
test
|
||||
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -1,4 +0,0 @@
|
||||
[submodule "aegis256"]
|
||||
path = aegis256
|
||||
url = https://github.com/angt/aegis256
|
||||
ignore = dirty
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2016-2019, Adrien Gallouët <adrien@gallouet.fr>
|
||||
Copyright (c) 2016-2020, Adrien Gallouët <adrien@gallouet.fr>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
8
Makefile
Normal file
8
Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
CFLAGS=-march=native -O2
|
||||
LDLIBS=-lsodium
|
||||
|
||||
test:
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f test
|
||||
1
aegis256
1
aegis256
Submodule aegis256 deleted from 0a7dad4dee
92
mud.h
92
mud.h
@@ -4,8 +4,8 @@
|
||||
#include <inttypes.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define MUD_PATH_MAX (32U)
|
||||
#define MUD_PUB_SIZE (32U)
|
||||
#define MUD_PATH_MAX (32U)
|
||||
#define MUD_PUBKEY_SIZE (32U)
|
||||
|
||||
struct mud;
|
||||
|
||||
@@ -16,67 +16,91 @@ enum mud_state {
|
||||
MUD_UP,
|
||||
};
|
||||
|
||||
struct mud_public {
|
||||
unsigned char remote[MUD_PUB_SIZE];
|
||||
unsigned char local[MUD_PUB_SIZE];
|
||||
};
|
||||
|
||||
struct mud_stat {
|
||||
uint64_t val;
|
||||
uint64_t var;
|
||||
int setup;
|
||||
};
|
||||
|
||||
struct mud_conf {
|
||||
uint64_t keepalive;
|
||||
uint64_t timetolerance;
|
||||
uint64_t kxtimeout;
|
||||
int tc;
|
||||
};
|
||||
|
||||
struct mud_path {
|
||||
enum mud_state state;
|
||||
struct sockaddr_storage local_addr, addr, r_addr;
|
||||
struct mud_stat rtt;
|
||||
uint64_t rate_tx;
|
||||
uint64_t rate_rx;
|
||||
uint64_t window;
|
||||
uint64_t window_time;
|
||||
uint64_t window_size;
|
||||
struct {
|
||||
size_t min;
|
||||
size_t max;
|
||||
size_t probe;
|
||||
size_t ok;
|
||||
} mtu;
|
||||
struct {
|
||||
uint64_t total;
|
||||
uint64_t bytes;
|
||||
uint64_t time;
|
||||
uint64_t msg_time;
|
||||
} send, recv;
|
||||
struct mud_public pub;
|
||||
uint64_t rate;
|
||||
uint64_t loss;
|
||||
} tx, rx;
|
||||
struct {
|
||||
struct {
|
||||
uint64_t total;
|
||||
uint64_t bytes;
|
||||
uint64_t time;
|
||||
uint64_t acc;
|
||||
uint64_t acc_time;
|
||||
} tx, rx;
|
||||
uint64_t time;
|
||||
uint64_t sent;
|
||||
uint64_t set;
|
||||
} msg;
|
||||
struct {
|
||||
size_t min;
|
||||
size_t max;
|
||||
size_t probe;
|
||||
size_t last;
|
||||
size_t ok;
|
||||
} mtu;
|
||||
struct {
|
||||
uint64_t tx_max_rate;
|
||||
uint64_t rx_max_rate;
|
||||
uint64_t beat;
|
||||
unsigned char fixed_rate;
|
||||
unsigned char loss_limit;
|
||||
} conf;
|
||||
uint64_t idle;
|
||||
unsigned char ok;
|
||||
unsigned msg_sent;
|
||||
};
|
||||
|
||||
struct mud_bad {
|
||||
struct {
|
||||
struct sockaddr_storage addr;
|
||||
uint64_t time;
|
||||
uint64_t count;
|
||||
} decrypt, difftime, keyx;
|
||||
};
|
||||
|
||||
struct mud *mud_create (struct sockaddr *);
|
||||
void mud_delete (struct mud *);
|
||||
|
||||
int mud_get_fd (struct mud *);
|
||||
int mud_update (struct mud *);
|
||||
int mud_send_wait (struct mud *);
|
||||
|
||||
int mud_get_fd (struct mud *);
|
||||
size_t mud_get_mtu (struct mud *);
|
||||
int mud_get_bad (struct mud *, struct mud_bad *);
|
||||
|
||||
int mud_set_key (struct mud *, unsigned char *, size_t);
|
||||
int mud_get_key (struct mud *, unsigned char *, size_t *);
|
||||
|
||||
void mud_set_mtu (struct mud *, size_t);
|
||||
size_t mud_get_mtu (struct mud *);
|
||||
|
||||
long mud_send_wait (struct mud *);
|
||||
|
||||
int mud_set_time_tolerance (struct mud *, unsigned long);
|
||||
int mud_set_keyx_timeout (struct mud *, unsigned long);
|
||||
int mud_set_tc (struct mud *, int);
|
||||
int mud_set_aes (struct mud *);
|
||||
int mud_set_aes (struct mud *);
|
||||
int mud_set_conf (struct mud *, struct mud_conf *);
|
||||
|
||||
int mud_set_state (struct mud *, struct sockaddr *, enum mud_state,
|
||||
unsigned long, unsigned long);
|
||||
unsigned long, unsigned long, unsigned long,
|
||||
unsigned char, unsigned char);
|
||||
|
||||
int mud_peer (struct mud *, struct sockaddr *);
|
||||
|
||||
int mud_recv (struct mud *, void *, size_t);
|
||||
int mud_send (struct mud *, const void *, size_t, unsigned);
|
||||
int mud_send (struct mud *, const void *, size_t);
|
||||
|
||||
struct mud_path *mud_get_paths(struct mud *, unsigned *);
|
||||
|
||||
121
test.c
Normal file
121
test.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "mud.c"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <poll.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 2)
|
||||
return -1;
|
||||
|
||||
int client = argc == 2;
|
||||
|
||||
struct sockaddr_in local = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(client + 20000),
|
||||
.sin_addr = {
|
||||
.s_addr = htonl(INADDR_LOOPBACK),
|
||||
},
|
||||
};
|
||||
|
||||
struct mud *mud = mud_create((struct sockaddr *)&local);
|
||||
|
||||
if (!mud) {
|
||||
perror("mud_create");
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char key[] = "0123456789ABCDEF0123456789ABCDEF";
|
||||
|
||||
if (mud_set_key(mud, key, sizeof(key))) {
|
||||
perror("mud_set_key");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// client is little harder to setup
|
||||
if (client) {
|
||||
struct sockaddr_in remote = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(20000),
|
||||
.sin_addr = {
|
||||
.s_addr = htonl(INADDR_LOOPBACK),
|
||||
},
|
||||
};
|
||||
|
||||
// we are going to connect to remote...
|
||||
if (mud_peer(mud, (struct sockaddr *)&remote)) {
|
||||
perror("mud_peer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ...from loopback at 1MBps (not 1Mbps)
|
||||
if (mud_set_state(mud, (struct sockaddr *)&local,
|
||||
MUD_UP, 1000 * 1000, 1000 * 1000, 0, 0, 0)) {
|
||||
perror("mud_set_state");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char buf[1500];
|
||||
|
||||
for (;;) {
|
||||
// mandatory, mud have lot of work to do.
|
||||
if (mud_update(mud))
|
||||
usleep(100000); // don't use all the cpu
|
||||
|
||||
if (client) {
|
||||
// when there is data, mud_recv() is mandatory
|
||||
struct pollfd pollfd = {
|
||||
.fd = mud_get_fd(mud),
|
||||
.events = POLLIN,
|
||||
};
|
||||
|
||||
switch (poll(&pollfd, 1, 0)) {
|
||||
case -1:
|
||||
perror("poll");
|
||||
return -1;
|
||||
case 1:
|
||||
if (mud_recv(mud, buf, sizeof(buf)) == -1) {
|
||||
perror("mud_recv");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// we can safely call mud_send()
|
||||
// even if the link is not ready
|
||||
int r = mud_send(mud, argv[1], strlen(argv[1]));
|
||||
|
||||
if (r == -1) {
|
||||
if (errno == EAGAIN)
|
||||
continue;
|
||||
|
||||
perror("mud_send");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// we sent everything, bye :)
|
||||
if (r)
|
||||
break;
|
||||
} else {
|
||||
int r = mud_recv(mud, buf, sizeof(buf));
|
||||
|
||||
if (r == -1) {
|
||||
if (errno == EAGAIN)
|
||||
continue;
|
||||
|
||||
perror("mud_recv");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (r) {
|
||||
buf[r] = 0;
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mud_delete(mud);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user