Skip to content

Commit

Permalink
fix indent with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Feb 7, 2023
1 parent 87b0db8 commit 9217e0e
Show file tree
Hide file tree
Showing 21 changed files with 7,849 additions and 9,168 deletions.
1,738 changes: 780 additions & 958 deletions client.cpp

Large diffs are not rendered by default.

1,944 changes: 882 additions & 1,062 deletions common.cpp

Large diffs are not rendered by default.

668 changes: 313 additions & 355 deletions common.h

Large diffs are not rendered by default.

1,206 changes: 553 additions & 653 deletions connection.cpp

Large diffs are not rendered by default.

550 changes: 256 additions & 294 deletions connection.h

Large diffs are not rendered by default.

989 changes: 504 additions & 485 deletions encrypt.cpp
100755 → 100644

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions encrypt.h
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
#ifndef UDP2RAW_ENCRYPTION_H_
#define UDP2RAW_ENCRYPTION_H_



//#include "aes.h"
//#include "md5.h"
#include "common.h"

// using namespace std;
// extern char key[16];

//using namespace std;
//extern char key[16];

const int aes_key_optimize=1; //if enabled,once you used a key for aes,you cant change it anymore
const int aes_key_optimize = 1; // if enabled,once you used a key for aes,you cant change it anymore
extern int aes128cfb_old;

int my_init_keys(const char *,int);

int my_encrypt(const char *data,char *output,int &len);
int my_decrypt(const char *data,char *output,int &len);


unsigned short csum(const unsigned short *ptr,int nbytes) ;

int my_init_keys(const char *, int);

enum auth_mode_t {auth_none=0,auth_md5,auth_crc32,auth_simple,auth_hmac_sha1,auth_end};
int my_encrypt(const char *data, char *output, int &len);
int my_decrypt(const char *data, char *output, int &len);

unsigned short csum(const unsigned short *ptr, int nbytes);

enum cipher_mode_t {cipher_none=0,cipher_aes128cbc,cipher_xor,cipher_aes128cfb,cipher_end};
enum auth_mode_t { auth_none = 0,
auth_md5,
auth_crc32,
auth_simple,
auth_hmac_sha1,
auth_end };

enum cipher_mode_t { cipher_none = 0,
cipher_aes128cbc,
cipher_xor,
cipher_aes128cfb,
cipher_end };

extern auth_mode_t auth_mode;
extern cipher_mode_t cipher_mode;

extern unordered_map<int, const char *> auth_mode_tostring;
extern unordered_map<int, const char *> cipher_mode_tostring;

extern char gro_xor[256+100];
extern char gro_xor[256 + 100];

int cipher_decrypt(const char *data,char *output,int &len,char * key);//internal interface ,exposed for test only
int cipher_encrypt(const char *data,char *output,int &len,char * key);//internal interface ,exposed for test only
int cipher_decrypt(const char *data, char *output, int &len, char *key); // internal interface ,exposed for test only
int cipher_encrypt(const char *data, char *output, int &len, char *key); // internal interface ,exposed for test only

void aes_ecb_encrypt(const char *data,char *output);
void aes_ecb_decrypt(const char *data,char *output);
void aes_ecb_encrypt(const char *data, char *output);
void aes_ecb_decrypt(const char *data, char *output);

void aes_ecb_encrypt1(char *data);
void aes_ecb_decrypt1(char *data);
Expand Down
99 changes: 44 additions & 55 deletions fd_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,49 @@
* Author: root
*/


#include "fd_manager.h"
int fd_manager_t::fd_exist(int fd)
{
return fd_to_fd64_mp.find(fd)!=fd_to_fd64_mp.end();
}
int fd_manager_t::exist(fd64_t fd64)
{
return fd64_to_fd_mp.find(fd64)!=fd64_to_fd_mp.end();
}
int fd_manager_t::to_fd(fd64_t fd64)
{
assert(exist(fd64));
return fd64_to_fd_mp[fd64];
}
void fd_manager_t::fd64_close(fd64_t fd64)
{
assert(exist(fd64));
int fd=fd64_to_fd_mp[fd64];
fd64_to_fd_mp.erase(fd64);
fd_to_fd64_mp.erase(fd);
if(exist_info(fd64))
{
fd_info_mp.erase(fd64);
}
//assert(close(fd)==0);
sock_close(fd);
}
void fd_manager_t::reserve(int n)
{
fd_to_fd64_mp.reserve(n);
fd64_to_fd_mp.reserve(n);
fd_info_mp.reserve(n);
}
u64_t fd_manager_t::create(int fd)
{
assert(!fd_exist(fd));
fd64_t fd64=counter++;
fd_to_fd64_mp[fd]=fd64;
fd64_to_fd_mp[fd64]=fd;
return fd64;
}
fd_manager_t::fd_manager_t()
{
counter=u32_t(-1);
counter+=100;
reserve(10007);
}
fd_info_t & fd_manager_t::get_info(fd64_t fd64)
{
assert(exist(fd64));
return fd_info_mp[fd64];
}
int fd_manager_t::exist_info(fd64_t fd64)
{
return fd_info_mp.find(fd64)!=fd_info_mp.end();
int fd_manager_t::fd_exist(int fd) {
return fd_to_fd64_mp.find(fd) != fd_to_fd64_mp.end();
}
int fd_manager_t::exist(fd64_t fd64) {
return fd64_to_fd_mp.find(fd64) != fd64_to_fd_mp.end();
}
int fd_manager_t::to_fd(fd64_t fd64) {
assert(exist(fd64));
return fd64_to_fd_mp[fd64];
}
void fd_manager_t::fd64_close(fd64_t fd64) {
assert(exist(fd64));
int fd = fd64_to_fd_mp[fd64];
fd64_to_fd_mp.erase(fd64);
fd_to_fd64_mp.erase(fd);
if (exist_info(fd64)) {
fd_info_mp.erase(fd64);
}
// assert(close(fd)==0);
sock_close(fd);
}
void fd_manager_t::reserve(int n) {
fd_to_fd64_mp.reserve(n);
fd64_to_fd_mp.reserve(n);
fd_info_mp.reserve(n);
}
u64_t fd_manager_t::create(int fd) {
assert(!fd_exist(fd));
fd64_t fd64 = counter++;
fd_to_fd64_mp[fd] = fd64;
fd64_to_fd_mp[fd64] = fd;
return fd64;
}
fd_manager_t::fd_manager_t() {
counter = u32_t(-1);
counter += 100;
reserve(10007);
}
fd_info_t& fd_manager_t::get_info(fd64_t fd64) {
assert(exist(fd64));
return fd_info_mp[fd64];
}
int fd_manager_t::exist_info(fd64_t fd64) {
return fd_info_mp.find(fd64) != fd_info_mp.end();
}
44 changes: 22 additions & 22 deletions fd_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
//#include "packet.h"
#include "connection.h"

struct fd_info_t
{
//ip_port_t ip_port;
conn_info_t *p_conn_info;
struct fd_info_t {
// ip_port_t ip_port;
conn_info_t *p_conn_info;
};

struct fd_manager_t //conver fd to a uniq 64bit number,avoid fd value conflict caused by close and re-create
//this class is not strictly necessary,it just makes epoll fd handling easier
struct fd_manager_t // conver fd to a uniq 64bit number,avoid fd value conflict caused by close and re-create
// this class is not strictly necessary,it just makes epoll fd handling easier
{
fd_info_t & get_info(fd64_t fd64);
int exist_info(fd64_t);
int exist(fd64_t fd64);
int to_fd(fd64_t);
void fd64_close(fd64_t fd64);
void reserve(int n);
u64_t create(int fd);
fd_manager_t();
private:
u64_t counter;
unordered_map<int,fd64_t> fd_to_fd64_mp;
unordered_map<fd64_t,int> fd64_to_fd_mp;
unordered_map<fd64_t,fd_info_t> fd_info_mp;
int fd_exist(int fd);
//void remove_fd(int fd);
//fd64_t fd_to_fd64(int fd);
fd_info_t &get_info(fd64_t fd64);
int exist_info(fd64_t);
int exist(fd64_t fd64);
int to_fd(fd64_t);
void fd64_close(fd64_t fd64);
void reserve(int n);
u64_t create(int fd);
fd_manager_t();

private:
u64_t counter;
unordered_map<int, fd64_t> fd_to_fd64_mp;
unordered_map<fd64_t, int> fd64_to_fd_mp;
unordered_map<fd64_t, fd_info_t> fd_info_mp;
int fd_exist(int fd);
// void remove_fd(int fd);
// fd64_t fd_to_fd64(int fd);
};

extern fd_manager_t fd_manager;
Expand Down
87 changes: 41 additions & 46 deletions log.cpp
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,62 +1,57 @@
#include "log.h"
#include "misc.h"

int log_level=log_info;
int log_level = log_info;

int enable_log_position=0;
int enable_log_color=1;
int enable_log_position = 0;
int enable_log_color = 1;

void log0(const char * file,const char * function,int line,int level,const char* str, ...) {
void log0(const char* file, const char* function, int line, int level, const char* str, ...) {
if (level > log_level) return;
if (level > log_trace || level < 0) return;

if(level>log_level) return ;
if(level>log_trace||level<0) return ;
time_t timer;
char buffer[100];
struct tm* tm_info;

time(&timer);
tm_info = localtime(&timer);

time_t timer;
char buffer[100];
struct tm* tm_info;
if (enable_log_color)
printf("%s", log_color[level]);

time(&timer);
tm_info = localtime(&timer);
strftime(buffer, 100, "%Y-%m-%d %H:%M:%S", tm_info);
printf("[%s][%s]", buffer, log_text[level]);

if(enable_log_color)
printf("%s",log_color[level]);
if (enable_log_position) printf("[%s,func:%s,line:%d]", file, function, line);

strftime(buffer, 100, "%Y-%m-%d %H:%M:%S", tm_info);
printf("[%s][%s]",buffer,log_text[level]);
va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if (enable_log_color)
printf("%s", RESET);

if(enable_log_position)printf("[%s,func:%s,line:%d]",file,function,line);
// printf("\n");
// if(enable_log_color)
// printf(log_color[level]);
fflush(stdout);

va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if(enable_log_color)
printf("%s",RESET);

//printf("\n");
//if(enable_log_color)
//printf(log_color[level]);
fflush(stdout);

if(log_level==log_fatal)
{
about_to_exit=1;
}
if (log_level == log_fatal) {
about_to_exit = 1;
}
}

void log_bare(int level,const char* str, ...)
{
if(level>log_level) return ;
if(level>log_trace||level<0) return ;
if(enable_log_color)
printf("%s",log_color[level]);
va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if(enable_log_color)
printf("%s",RESET);
fflush(stdout);

void log_bare(int level, const char* str, ...) {
if (level > log_level) return;
if (level > log_trace || level < 0) return;
if (enable_log_color)
printf("%s", log_color[level]);
va_list vlist;
va_start(vlist, str);
vfprintf(stdout, str, vlist);
va_end(vlist);
if (enable_log_color)
printf("%s", RESET);
fflush(stdout);
}
Loading

0 comments on commit 9217e0e

Please sign in to comment.