mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-06-30 22:26:08 +08:00
Compare commits
No commits in common. "branch_libev" and "20230206.0" have entirely different histories.
branch_lib
...
20230206.0
@ -1,6 +1,4 @@
|
|||||||
#note: experimental
|
#note: experimental
|
||||||
# currently only used for generating `compile_commands.json` for clangd
|
|
||||||
# to build this project, it's suggested to use `makefile` instead
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.7)
|
||||||
project(speederv2)
|
project(speederv2)
|
||||||
|
@ -1 +1 @@
|
|||||||
English Only.
|
English Only (except for bug reporting).
|
||||||
|
@ -895,8 +895,8 @@ int new_connected_socket2(int &fd, address_t &addr, address_t *bind_addr, char *
|
|||||||
u32_t djb2(unsigned char *str, int len) {
|
u32_t djb2(unsigned char *str, int len) {
|
||||||
u32_t hash = 5381;
|
u32_t hash = 5381;
|
||||||
int c;
|
int c;
|
||||||
for (int i=0; i<len ;i++) {
|
int i = 0;
|
||||||
c = *(str++);
|
while (c = *str++, i++ != len) {
|
||||||
hash = ((hash << 5) + hash) ^ c; /* (hash * 33) ^ c */
|
hash = ((hash << 5) + hash) ^ c; /* (hash * 33) ^ c */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -907,15 +907,14 @@ u32_t djb2(unsigned char *str, int len) {
|
|||||||
u32_t sdbm(unsigned char *str, int len) {
|
u32_t sdbm(unsigned char *str, int len) {
|
||||||
u32_t hash = 0;
|
u32_t hash = 0;
|
||||||
int c;
|
int c;
|
||||||
for (int i=0; i<len ;i++) {
|
int i = 0;
|
||||||
c = *(str++);
|
while (c = *str++, i++ != len) {
|
||||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||||
}
|
}
|
||||||
// hash=htonl(hash);
|
// hash=htonl(hash);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vector<string> string_to_vec(const char *s, const char *sp) {
|
vector<string> string_to_vec(const char *s, const char *sp) {
|
||||||
vector<string> res;
|
vector<string> res;
|
||||||
string str = s;
|
string str = s;
|
||||||
|
1245
crc32/Crc32.cpp
1245
crc32/Crc32.cpp
File diff suppressed because it is too large
Load Diff
@ -1,69 +0,0 @@
|
|||||||
// //////////////////////////////////////////////////////////
|
|
||||||
// Crc32.h
|
|
||||||
// Copyright (c) 2011-2019 Stephan Brumme. All rights reserved.
|
|
||||||
// Slicing-by-16 contributed by Bulat Ziganshin
|
|
||||||
// Tableless bytewise CRC contributed by Hagai Gold
|
|
||||||
// see http://create.stephan-brumme.com/disclaimer.html
|
|
||||||
//
|
|
||||||
|
|
||||||
// if running on an embedded system, you might consider shrinking the
|
|
||||||
// big Crc32Lookup table by undefining these lines:
|
|
||||||
#define CRC32_USE_LOOKUP_TABLE_BYTE
|
|
||||||
#define CRC32_USE_LOOKUP_TABLE_SLICING_BY_4
|
|
||||||
#define CRC32_USE_LOOKUP_TABLE_SLICING_BY_8
|
|
||||||
#define CRC32_USE_LOOKUP_TABLE_SLICING_BY_16
|
|
||||||
// - crc32_bitwise doesn't need it at all
|
|
||||||
// - crc32_halfbyte has its own small lookup table
|
|
||||||
// - crc32_1byte_tableless and crc32_1byte_tableless2 don't need it at all
|
|
||||||
// - crc32_1byte needs only Crc32Lookup[0]
|
|
||||||
// - crc32_4bytes needs only Crc32Lookup[0..3]
|
|
||||||
// - crc32_8bytes needs only Crc32Lookup[0..7]
|
|
||||||
// - crc32_4x8bytes needs only Crc32Lookup[0..7]
|
|
||||||
// - crc32_16bytes needs all of Crc32Lookup
|
|
||||||
// using the aforementioned #defines the table is automatically fitted to your needs
|
|
||||||
|
|
||||||
// uint8_t, uint32_t, int32_t
|
|
||||||
#include <stdint.h>
|
|
||||||
// size_t
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
// crc32_fast selects the fastest algorithm depending on flags (CRC32_USE_LOOKUP_...)
|
|
||||||
/// compute CRC32 using the fastest algorithm for large datasets on modern CPUs
|
|
||||||
uint32_t crc32_fast (const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
|
|
||||||
/// merge two CRC32 such that result = crc32(dataB, lengthB, crc32(dataA, lengthA))
|
|
||||||
uint32_t crc32_combine (uint32_t crcA, uint32_t crcB, size_t lengthB);
|
|
||||||
|
|
||||||
/// compute CRC32 (bitwise algorithm)
|
|
||||||
uint32_t crc32_bitwise (const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
/// compute CRC32 (half-byte algoritm)
|
|
||||||
uint32_t crc32_halfbyte(const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
|
|
||||||
#ifdef CRC32_USE_LOOKUP_TABLE_BYTE
|
|
||||||
/// compute CRC32 (standard algorithm)
|
|
||||||
uint32_t crc32_1byte (const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// compute CRC32 (byte algorithm) without lookup tables
|
|
||||||
uint32_t crc32_1byte_tableless (const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
/// compute CRC32 (byte algorithm) without lookup tables
|
|
||||||
uint32_t crc32_1byte_tableless2(const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
|
|
||||||
#ifdef CRC32_USE_LOOKUP_TABLE_SLICING_BY_4
|
|
||||||
/// compute CRC32 (Slicing-by-4 algorithm)
|
|
||||||
uint32_t crc32_4bytes (const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CRC32_USE_LOOKUP_TABLE_SLICING_BY_8
|
|
||||||
/// compute CRC32 (Slicing-by-8 algorithm)
|
|
||||||
uint32_t crc32_8bytes (const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
/// compute CRC32 (Slicing-by-8 algorithm), unroll inner loop 4 times
|
|
||||||
uint32_t crc32_4x8bytes(const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CRC32_USE_LOOKUP_TABLE_SLICING_BY_16
|
|
||||||
/// compute CRC32 (Slicing-by-16 algorithm)
|
|
||||||
uint32_t crc32_16bytes (const void* data, size_t length, uint32_t previousCrc32 = 0);
|
|
||||||
/// compute CRC32 (Slicing-by-16 algorithm, prefetch upcoming data blocks)
|
|
||||||
uint32_t crc32_16bytes_prefetch(const void* data, size_t length, uint32_t previousCrc32 = 0, size_t prefetchAhead = 256);
|
|
||||||
#endif
|
|
@ -1,10 +0,0 @@
|
|||||||
zlib License
|
|
||||||
|
|
||||||
Copyright (c) 2011-2016 Stephan Brumme
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
|
||||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
|
|
||||||
If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
@ -413,7 +413,7 @@ class fec_decode_manager_t : not_copy_able_t {
|
|||||||
mylog(log_debug, "fec_decode_manager destroyed\n");
|
mylog(log_debug, "fec_decode_manager destroyed\n");
|
||||||
if (fec_data != 0) {
|
if (fec_data != 0) {
|
||||||
mylog(log_debug, "fec_data freed\n");
|
mylog(log_debug, "fec_data freed\n");
|
||||||
delete[] fec_data;
|
delete fec_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int clear() {
|
int clear() {
|
||||||
|
2
makefile
2
makefile
@ -10,7 +10,7 @@ cc_amd64=/toolchains/lede-sdk-17.01.2-x86-64_gcc-5.4.0_musl-1.1.16.Linux-x86_64/
|
|||||||
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
||||||
|
|
||||||
|
|
||||||
SOURCES0=main.cpp log.cpp common.cpp lib/fec.cpp lib/rs.cpp crc32/Crc32.cpp packet.cpp delay_manager.cpp fd_manager.cpp connection.cpp fec_manager.cpp misc.cpp tunnel_client.cpp tunnel_server.cpp
|
SOURCES0=main.cpp log.cpp common.cpp lib/fec.cpp lib/rs.cpp packet.cpp delay_manager.cpp fd_manager.cpp connection.cpp fec_manager.cpp misc.cpp tunnel_client.cpp tunnel_server.cpp
|
||||||
SOURCES=${SOURCES0} my_ev.cpp -isystem libev
|
SOURCES=${SOURCES0} my_ev.cpp -isystem libev
|
||||||
NAME=speederv2
|
NAME=speederv2
|
||||||
|
|
||||||
|
35
packet.cpp
35
packet.cpp
@ -9,7 +9,6 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "crc32/Crc32.h"
|
|
||||||
|
|
||||||
int iv_min = 4;
|
int iv_min = 4;
|
||||||
int iv_max = 32; //< 256;
|
int iv_max = 32; //< 256;
|
||||||
@ -231,6 +230,32 @@ int my_send(const dest_t &dest, char *data, int len) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this function comes from http://www.hackersdelight.org/hdcodetxt/crc.c.txt
|
||||||
|
*/
|
||||||
|
unsigned int crc32h(unsigned char *message, int len) {
|
||||||
|
assert(len >= 0);
|
||||||
|
int i, crc;
|
||||||
|
unsigned int byte, c;
|
||||||
|
const unsigned int g0 = 0xEDB88320, g1 = g0 >> 1,
|
||||||
|
g2 = g0 >> 2, g3 = g0 >> 3, g4 = g0 >> 4, g5 = g0 >> 5,
|
||||||
|
g6 = (g0 >> 6) ^ g0, g7 = ((g0 >> 6) ^ g0) >> 1;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
crc = 0xFFFFFFFF;
|
||||||
|
while (i != len) { // Get next byte.
|
||||||
|
byte = message[i];
|
||||||
|
crc = crc ^ byte;
|
||||||
|
c = ((crc << 31 >> 31) & g7) ^ ((crc << 30 >> 31) & g6) ^
|
||||||
|
((crc << 29 >> 31) & g5) ^ ((crc << 28 >> 31) & g4) ^
|
||||||
|
((crc << 27 >> 31) & g3) ^ ((crc << 26 >> 31) & g2) ^
|
||||||
|
((crc << 25 >> 31) & g1) ^ ((crc << 24 >> 31) & g0);
|
||||||
|
crc = ((unsigned)crc >> 8) ^ c;
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
return ~crc;
|
||||||
|
}
|
||||||
|
|
||||||
int put_conv0(u32_t conv, const char *input, int len_in, char *&output, int &len_out) {
|
int put_conv0(u32_t conv, const char *input, int len_in, char *&output, int &len_out) {
|
||||||
assert(len_in >= 0);
|
assert(len_in >= 0);
|
||||||
static char buf[buf_len];
|
static char buf[buf_len];
|
||||||
@ -238,7 +263,7 @@ int put_conv0(u32_t conv, const char *input, int len_in, char *&output, int &len
|
|||||||
u32_t n_conv = htonl(conv);
|
u32_t n_conv = htonl(conv);
|
||||||
memcpy(output, &n_conv, sizeof(n_conv));
|
memcpy(output, &n_conv, sizeof(n_conv));
|
||||||
memcpy(output + sizeof(n_conv), input, len_in);
|
memcpy(output + sizeof(n_conv), input, len_in);
|
||||||
u32_t crc32 = (u32_t)crc32_fast(output, len_in + sizeof(crc32));
|
u32_t crc32 = crc32h((unsigned char *)output, len_in + sizeof(crc32));
|
||||||
u32_t crc32_n = htonl(crc32);
|
u32_t crc32_n = htonl(crc32);
|
||||||
len_out = len_in + (int)(sizeof(n_conv)) + (int)sizeof(crc32_n);
|
len_out = len_in + (int)(sizeof(n_conv)) + (int)sizeof(crc32_n);
|
||||||
memcpy(output + len_in + (int)(sizeof(n_conv)), &crc32_n, sizeof(crc32_n));
|
memcpy(output + len_in + (int)(sizeof(n_conv)), &crc32_n, sizeof(crc32_n));
|
||||||
@ -258,7 +283,7 @@ int get_conv0(u32_t &conv, const char *input, int len_in, char *&output, int &le
|
|||||||
}
|
}
|
||||||
memcpy(&crc32_n, input + len_in - (int)sizeof(crc32_n), sizeof(crc32_n));
|
memcpy(&crc32_n, input + len_in - (int)sizeof(crc32_n), sizeof(crc32_n));
|
||||||
u32_t crc32 = ntohl(crc32_n);
|
u32_t crc32 = ntohl(crc32_n);
|
||||||
if (crc32 != (u32_t)crc32_fast(input, len_in - sizeof(crc32_n))) {
|
if (crc32 != crc32h((unsigned char *)input, len_in - (int)sizeof(crc32_n))) {
|
||||||
mylog(log_debug, "crc32 check failed\n");
|
mylog(log_debug, "crc32 check failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -268,7 +293,7 @@ int put_crc32(char *s, int &len) {
|
|||||||
if (disable_checksum) return 0;
|
if (disable_checksum) return 0;
|
||||||
assert(len >= 0);
|
assert(len >= 0);
|
||||||
// if(len<0) return -1;
|
// if(len<0) return -1;
|
||||||
u32_t crc32 = (u32_t)crc32_fast(s, len);
|
u32_t crc32 = crc32h((unsigned char *)s, len);
|
||||||
write_u32(s + len, crc32);
|
write_u32(s + len, crc32);
|
||||||
len += sizeof(u32_t);
|
len += sizeof(u32_t);
|
||||||
|
|
||||||
@ -304,7 +329,7 @@ int rm_crc32(char *s, int &len) {
|
|||||||
len -= sizeof(u32_t);
|
len -= sizeof(u32_t);
|
||||||
if (len < 0) return -1;
|
if (len < 0) return -1;
|
||||||
u32_t crc32_in = read_u32(s + len);
|
u32_t crc32_in = read_u32(s + len);
|
||||||
u32_t crc32 = (u32_t)crc32_fast(s, len);
|
u32_t crc32 = crc32h((unsigned char *)s, len);
|
||||||
if (crc32 != crc32_in) return -1;
|
if (crc32 != crc32_in) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user