Skip to content

Commit

Permalink
ver1.2.8.1, 更新输出信息
Browse files Browse the repository at this point in the history
  • Loading branch information
opengnb committed Jan 1, 2022
1 parent 835a8f8 commit 3bcefc9
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 138 deletions.
62 changes: 58 additions & 4 deletions src/cli/gnb.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <windows.h>
#endif

#ifndef GNB_SKIP_BUILD_TIME
#define GNB_BUILD_STRING "Build ["__DATE__","__TIME__"]"
#endif

gnb_core_t *gnb_core;

int gnb_daemon();
Expand All @@ -41,6 +45,7 @@ gnb_conf_t* gnb_argv(int argc,char *argv[]);

void primary_process_loop(gnb_core_t *gnb_core);

extern gnb_pf_t *gnb_pf_mods[];
extern gnb_arg_list_t *gnb_es_arg_list;

extern int is_self_test;
Expand Down Expand Up @@ -196,6 +201,53 @@ BOOL CALLBACK CosonleHandler(DWORD ev) {
#endif


void log_out_description(gnb_log_ctx_t *log){

GNB_LOG1(log, GNB_LOG_ID_CORE, "%s\n", GNB_VERSION_STRING);
GNB_LOG1(log, GNB_LOG_ID_CORE, "%s\n", GNB_COPYRIGHT_STRING);
GNB_LOG1(log, GNB_LOG_ID_CORE, "Site: %s\n", GNB_URL_STRING);

int idx = 0;

GNB_LOG1(log, GNB_LOG_ID_CORE, "registered packet filter:");

while ( NULL != gnb_pf_mods[idx] ) {
GNB_LOG1(log, GNB_LOG_ID_CORE, " %s",gnb_pf_mods[idx]->name);
idx++;
}

GNB_LOG1(log, GNB_LOG_ID_CORE, "\n");

#ifndef GNB_SKIP_BUILD_TIME
GNB_LOG1(log, GNB_LOG_ID_CORE, "%s\n", GNB_BUILD_STRING);
#endif

}


void show_description(){

printf("%s\n", GNB_VERSION_STRING);
printf("%s\n", GNB_COPYRIGHT_STRING);
printf("Site: %s\n", GNB_URL_STRING);

int idx = 0;

printf("registered packet filter:");

while ( NULL != gnb_pf_mods[idx] ) {
printf(" %s",gnb_pf_mods[idx]->name);
idx++;
}

printf("\n");

#ifndef GNB_SKIP_BUILD_TIME
printf("%s\n", GNB_BUILD_STRING);
#endif

}


int main (int argc,char *argv[]){

Expand All @@ -220,12 +272,14 @@ int main (int argc,char *argv[]){
gnb_core = gnb_core_index_service_create(conf);
}

if (NULL==gnb_core) {
printf("gnb core create error\n");
free(conf);

if ( NULL == gnb_core ) {
printf("gnb core create error!\n");
return 1;
}

free(conf);
GNB_LOG1(gnb_core->log,GNB_LOG_ID_CORE,"gnb core created!\n");

#ifdef __UNIX_LIKE_OS__
if (gnb_core->conf->daemon) {
Expand All @@ -237,7 +291,7 @@ int main (int argc,char *argv[]){

ret = gettimeofday(&gnb_core->now_timeval,NULL);

if ( 1==is_self_test ) {
if ( 1 == is_self_test ) {
self_test();
}

Expand Down
28 changes: 14 additions & 14 deletions src/cli/gnb_es.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static void setup_log_ctx(gnb_log_ctx_t *log_ctx, char *log_udp_sockaddress4_str

log_ctx->log_payload_type = GNB_ES_PAYLOAD_TYPE_UDPLOG;

if( '\0' != log_udp_sockaddress4_string[0] ){
if ( '\0' != log_udp_sockaddress4_string[0] ) {
rc = gnb_log_udp_set_addr4_string(log_ctx, log_udp_sockaddress4_string);
log_ctx->output_type |= GNB_LOG_OUTPUT_UDP;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ int main (int argc,char *argv[]){

case LOG_UDP_TYPE:

if ( !strncmp(optarg, "binary", 16) ){
if ( !strncmp(optarg, "binary", 16) ) {
log_udp_type = GNB_LOG_UDP_TYPE_BINARY;
} else {
log_udp_type = GNB_LOG_UDP_TYPE_TEXT;
Expand Down Expand Up @@ -298,9 +298,9 @@ int main (int argc,char *argv[]){

case LOG_UDP4:

if( NULL != optarg ){
if( NULL != optarg ) {
snprintf(log_udp_sockaddress4_string, 16 + 1 + sizeof("65535"), "%s", optarg);
}else{
} else {
snprintf(log_udp_sockaddress4_string, 16 + 1 + sizeof("65535"), "%s", "127.0.0.1:9000");
}

Expand All @@ -317,19 +317,19 @@ int main (int argc,char *argv[]){
}


if ( NULL == ctl_block_file ){
if ( NULL == ctl_block_file ) {
show_useage(argc,argv);
exit(0);
}


#ifdef __UNIX_LIKE_OS__
if(daemon){
if (daemon) {
gnb_daemon();
}
#endif

if (daemon){
if (daemon) {
service_opt = 1;
}

Expand All @@ -341,7 +341,7 @@ int main (int argc,char *argv[]){

gnb_es_ctx *es_ctx = gnb_es_ctx_init(service_opt, ctl_block_file, log);

if (NULL==es_ctx){
if (NULL==es_ctx) {
printf("es ctx init error [%s]\n",ctl_block_file);
return 1;
}
Expand Down Expand Up @@ -373,17 +373,17 @@ int main (int argc,char *argv[]){

if ( NULL != pid_file ) {

if( 0 == conf->lite_mode ){
if ( 0 == conf->lite_mode ) {
snprintf(es_ctx->pid_file, PATH_MAX+NAME_MAX,"%s", pid_file);
}else{
} else {
snprintf(conf->pid_file, PATH_MAX+NAME_MAX, "%s/gnb_es.%d.pid", conf->binary_dir, conf->udp4_ports[0]);
}

if ( NULL != realpath(es_ctx->pid_file,resolved_path) ){
if ( NULL != realpath(es_ctx->pid_file,resolved_path) ) {
strncpy(es_ctx->pid_file, resolved_path, PATH_MAX);
}

}else{
} else {

snprintf(es_ctx->pid_file, PATH_MAX+NAME_MAX, "%s/gnb_es.pid", conf->conf_dir);

Expand All @@ -397,13 +397,13 @@ int main (int argc,char *argv[]){
snprintf(es_ctx->wan_address6_file, PATH_MAX+NAME_MAX,"%s", wan_address6_file);

#ifdef __UNIX_LIKE_OS__
if ( NULL != realpath(es_ctx->wan_address6_file,resolved_path) ){
if ( NULL != realpath(es_ctx->wan_address6_file,resolved_path) ) {
strncpy(es_ctx->wan_address6_file, resolved_path, PATH_MAX);
}
#endif

#ifdef _WIN32
if ( NULL != _fullpath(resolved_path, es_ctx->wan_address6_file, PATH_MAX) ){
if ( NULL != _fullpath(resolved_path, es_ctx->wan_address6_file, PATH_MAX) ) {
strncpy(es_ctx->wan_address6_file, resolved_path, PATH_MAX);
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/gnb.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ typedef struct _gnb_core_t{
#define GNB_LOG_ID_INDEX_SERVICE_WORKER 5
#define GNB_LOG_ID_DETECT_WORKER 6


#define GNB_VERSION_STRING "GNB version 1.2.8.1 protocol version 1.1.2"
#define GNB_COPYRIGHT_STRING "Copyright (C) 2019 gnbdev<gnbdev@qq.com>"
#define GNB_URL_STRING "https://github.com/gnbdev/opengnb"
#endif

46 changes: 12 additions & 34 deletions src/gnb_argv.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
#include "gnb_config_lite.h"

extern gnb_conf_ext_lite_t gnb_conf_ext_lite;
extern gnb_pf_t *gnb_pf_mods[];
static void show_version_buildtime();

void show_description();

static void show_useage(int argc,char *argv[]);

int check_listen_string(char *listen_string);
Expand Down Expand Up @@ -892,32 +893,9 @@ gnb_conf_t* gnb_argv(int argc,char *argv[]){
}


static void show_version_buildtime(){

printf("GNB version 1.2.8.1 protocol version 1.1.2\n");

#ifndef GNB_SKIP_BUILD_TIME
printf("Build[%s %s]\n", __DATE__, __TIME__);
#endif

printf("Copyright (C) 2019 gnbdev<gnbdev@qq.com>\n");

int idx = 0;

printf("registered packet filter:");

while ( NULL != gnb_pf_mods[idx] ) {
printf(" %s",gnb_pf_mods[idx]->name);
idx++;
}
printf("\n");

}


static void show_useage(int argc,char *argv[]){

show_version_buildtime();
show_description();

printf("Usage: %s [-i IFNAME] -c CONFIG_PATH [OPTION]\n", argv[0]);
printf("Command Summary:\n");
Expand Down Expand Up @@ -987,15 +965,15 @@ static void show_useage(int argc,char *argv[]){

printf(" --help\n");

printf("example:\n");
printf("%s -i gnbtun -c $node_conf_dir -e \"--upnp\"\n",argv[0]);
printf("%s -P\n",argv[0]);
printf("%s -P --console-log-level=3 --index-service-log-level=3\n",argv[0]);
printf("Example:\n");
printf(" %s -i gnbtun -c $node_conf_dir -e \"--upnp\"\n",argv[0]);
printf(" %s -P\n",argv[0]);
printf(" %s -P --console-log-level=3 --index-service-log-level=3\n",argv[0]);

printf("%s -n 1001 -I '$public_index_ip/$port' -p $passcode\n",argv[0]);
printf("%s -n 1002 -I '$public_index_ip/$port' -p $passcode\n",argv[0]);
printf(" %s -n 1001 -I '$public_index_ip/$port' -p $passcode\n",argv[0]);
printf(" %s -n 1002 -I '$public_index_ip/$port' -p $passcode\n",argv[0]);

printf("%s -n 1001 -a 'i/0/$public_index_ip/$port' -p $passcode\n",argv[0]);
printf("%s -n 1002 -a 'i/0/$public_index_ip/$port' -p $passcode\n",argv[0]);
printf(" %s -n 1001 -a 'i/0/$public_index_ip/$port' -p $passcode\n",argv[0]);
printf(" %s -n 1002 -a 'i/0/$public_index_ip/$port' -p $passcode\n",argv[0]);

}
2 changes: 1 addition & 1 deletion src/gnb_conf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ static void local_node_file_config(gnb_core_t *gnb_core){

if ( !strncmp(line_buffer, "es-argv", sizeof("es-argv")-1) ) {

num = sscanf(line_buffer,"%256[^ ] \"%256[^\"]",field, value);
num = sscanf(line_buffer,"%256[^ ] %s",field, value);

if ( 2 != num ) {
printf("config %s error in [%s]\n", "es-argv", node_conf_file);
Expand Down
5 changes: 4 additions & 1 deletion src/gnb_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int main (int argc,char *argv[]){

int option_index = 0;

opt = getopt_long (argc, argv, "ci:k:p:",long_options, &option_index);
opt = getopt_long (argc, argv, "ck:p:h",long_options, &option_index);

if (opt == -1) {
break;
Expand All @@ -131,6 +131,9 @@ int main (int argc,char *argv[]){
public_key_file = optarg;
break;

case 'h':
break;

default:
break;
}
Expand Down
Loading

0 comments on commit 3bcefc9

Please sign in to comment.