mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-04-03 18:49:32 +08:00
Merge dfc6ac0d8ce12a7c7220cfd6e04987e6e2253a91 into 17694ecaa9681b04498709ba7526c8a8f022b512
This commit is contained in:
commit
e692f313ed
1245
crc32/Crc32.cpp
Normal file
1245
crc32/Crc32.cpp
Normal file
File diff suppressed because it is too large
Load Diff
69
crc32/Crc32.h
Normal file
69
crc32/Crc32.h
Normal file
@ -0,0 +1,69 @@
|
||||
// //////////////////////////////////////////////////////////
|
||||
// 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
|
10
crc32/LICENSE
Normal file
10
crc32/LICENSE
Normal file
@ -0,0 +1,10 @@
|
||||
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.
|
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++
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
SOURCES=${SOURCES0} my_ev.cpp -isystem libev
|
||||
NAME=speederv2
|
||||
|
||||
|
35
packet.cpp
35
packet.cpp
@ -9,6 +9,7 @@
|
||||
#include "log.h"
|
||||
#include "packet.h"
|
||||
#include "misc.h"
|
||||
#include "crc32/Crc32.h"
|
||||
|
||||
int iv_min = 4;
|
||||
int iv_max = 32; //< 256;
|
||||
@ -230,32 +231,6 @@ int my_send(const dest_t &dest, char *data, int len) {
|
||||
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) {
|
||||
assert(len_in >= 0);
|
||||
static char buf[buf_len];
|
||||
@ -263,7 +238,7 @@ int put_conv0(u32_t conv, const char *input, int len_in, char *&output, int &len
|
||||
u32_t n_conv = htonl(conv);
|
||||
memcpy(output, &n_conv, sizeof(n_conv));
|
||||
memcpy(output + sizeof(n_conv), input, len_in);
|
||||
u32_t crc32 = crc32h((unsigned char *)output, len_in + sizeof(crc32));
|
||||
u32_t crc32 = (u32_t)crc32_fast(output, len_in + sizeof(crc32));
|
||||
u32_t crc32_n = htonl(crc32);
|
||||
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));
|
||||
@ -283,7 +258,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));
|
||||
u32_t crc32 = ntohl(crc32_n);
|
||||
if (crc32 != crc32h((unsigned char *)input, len_in - (int)sizeof(crc32_n))) {
|
||||
if (crc32 != (u32_t)crc32_fast(input, len_in - sizeof(crc32_n))) {
|
||||
mylog(log_debug, "crc32 check failed\n");
|
||||
return -1;
|
||||
}
|
||||
@ -293,7 +268,7 @@ int put_crc32(char *s, int &len) {
|
||||
if (disable_checksum) return 0;
|
||||
assert(len >= 0);
|
||||
// if(len<0) return -1;
|
||||
u32_t crc32 = crc32h((unsigned char *)s, len);
|
||||
u32_t crc32 = (u32_t)crc32_fast(s, len);
|
||||
write_u32(s + len, crc32);
|
||||
len += sizeof(u32_t);
|
||||
|
||||
@ -329,7 +304,7 @@ int rm_crc32(char *s, int &len) {
|
||||
len -= sizeof(u32_t);
|
||||
if (len < 0) return -1;
|
||||
u32_t crc32_in = read_u32(s + len);
|
||||
u32_t crc32 = crc32h((unsigned char *)s, len);
|
||||
u32_t crc32 = (u32_t)crc32_fast(s, len);
|
||||
if (crc32 != crc32_in) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user