Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-chain-net
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap-chain-net
Commits
1f513d11
Commit
1f513d11
authored
6 years ago
by
Aleksandr Lysikov
Browse files
Options
Downloads
Patches
Plain Diff
added unix-socket server for execute command from console
parent
53c34c5c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+2
-0
2 additions, 0 deletions
CMakeLists.txt
dap_chain_node_cli.c
+155
-0
155 additions, 0 deletions
dap_chain_node_cli.c
dap_chain_node_cli.h
+39
-0
39 additions, 0 deletions
dap_chain_node_cli.h
with
196 additions
and
0 deletions
CMakeLists.txt
+
2
−
0
View file @
1f513d11
...
...
@@ -5,12 +5,14 @@ set(DAP_CHAIN_NET_SRCS
dap_chain_net.c
dap_chain_node.c
dap_chain_node_ctl.c
dap_chain_node_cli.c
)
set
(
DAP_CHAIN_NET_HEADERS
dap_chain_net.h
dap_chain_node.h
dap_chain_node_ctl.h
dap_chain_node_cli.h
)
set
(
IPUTILS_INCLUDE_DIRS
...
...
This diff is collapsed.
Click to expand it.
dap_chain_node_cli.c
0 → 100644
+
155
−
0
View file @
1f513d11
/*
* Authors:
* Dmitriy A. Gearasimov <naeper@demlabs.net>
* DeM Labs Inc. https://demlabs.net
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<pthread.h>
#include
<stdio.h>
#include
<string.h>
#include
<errno.h>
#ifndef _WIN32
#include
<sys/socket.h>
#include
<sys/types.h>
#include
<arpa/inet.h>
#include
<unistd.h>
// for close
#include
<fcntl.h>
//#include <sys/poll.h>
//#include <sys/select.h>
#include
<netinet/in.h>
#include
<sys/un.h>
#define closesocket close
typedef
int
SOCKET
;
#define SOCKET_ERROR -1 // for win32 = (-1)
#define INVALID_SOCKET -1 // for win32 = (SOCKET)(~0)
// for Windows
#else
#include
<winsock2.h>
#include
<WS2tcpip.h>
#endif
#include
"dap_common.h"
#include
"dap_config.h"
#include
"dap_chain_node_cli.h"
//#include "dap_chain_node_cli.h"
#define LOG_TAG "chain_node_cli"
#define SOCKET_FILE "/opt/kelvin-node/var/run/node_cli.sock"
static
SOCKET
server_sockfd
=
-
1
;
/**
* threading function for processing a request from a client
*/
static
void
*
thread_one_client_func
(
void
*
args
)
{
return
NULL
;
}
/**
* main threading server function
*/
static
void
*
thread_main_func
(
void
*
args
)
{
SOCKET
sockfd
=
(
SOCKET
)
(
intptr_t
)
args
;
SOCKET
newsockfd
;
// wait of clients
while
(
1
)
{
pthread_t
threadId
;
struct
sockaddr_in
peer
;
socklen_t
size
=
sizeof
(
peer
);
// received a new connection request
if
((
newsockfd
=
accept
(
sockfd
,
(
struct
sockaddr
*
)
&
peer
,
&
size
))
==
(
SOCKET
)
-
1
)
{
log_it
(
L_ERROR
,
"new connection break newsockfd=%d"
,
newsockfd
);
break
;
}
log_it
(
L_INFO
,
"new connection newsockfd=%d"
,
newsockfd
);
// create child thread for a client connection
pthread_create
(
&
threadId
,
NULL
,
thread_one_client_func
,
(
void
*
)
(
intptr_t
)
newsockfd
);
// in order to thread not remain in state "dead" after completion
pthread_detach
(
threadId
);
};
// закрыть соединение
int
cs
=
closesocket
(
sockfd
);
log_it
(
L_INFO
,
"Exit server thread socket=%d closesocket=%d
\n
"
,
sockfd
,
cs
);
return
NULL
;
}
/**
* Initialization of the server side of the interaction
* with the console kelvin-node-cli
*
* return 0 if OK, -1 error
*/
int
dap_chain_node_cli_init
(
dap_config_t
*
g_config
)
{
struct
sockaddr_un
server
=
{
AF_UNIX
,
SOCKET_FILE
};
//server.sun_family = AF_UNIX;
//strcpy(server.sun_path, SOCKET_FILE);
SOCKET
sockfd
;
if
(
server_sockfd
>=
0
)
{
dap_chain_node_cli_delete
();
server_sockfd
=
0
;
}
// create socket
if
((
sockfd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
))
==
INVALID_SOCKET
)
return
-
1
;
int
gdsg
=
sizeof
(
struct
sockaddr_un
);
if
(
access
(
SOCKET_FILE
,
R_OK
)
!=
-
1
)
{
unlink
(
SOCKET_FILE
);
}
// connecting the address with a socket
if
(
bind
(
sockfd
,
(
const
struct
sockaddr
*
)
&
server
,
sizeof
(
struct
sockaddr_un
))
==
SOCKET_ERROR
)
{
log_it
(
L_ERROR
,
"Server can't start(err=%d). may be file=%s absent"
,
errno
,
SOCKET_FILE
);
closesocket
(
sockfd
);
return
-
1
;
}
else
log_it
(
L_INFO
,
"Server start sock-file=%s"
,
SOCKET_FILE
);
// turn on reception of connections
if
(
listen
(
sockfd
,
5
)
==
SOCKET_ERROR
)
return
-
1
;
// create thread for waiting of clients
pthread_t
threadId
;
if
(
pthread_create
(
&
threadId
,
NULL
,
thread_main_func
,
(
void
*
)
(
intptr_t
)
sockfd
)
!=
0
)
{
closesocket
(
sockfd
);
return
-
1
;
}
// in order to thread not remain in state "dead" after completion
pthread_detach
(
threadId
);
server_sockfd
=
sockfd
;
return
0
;
}
/**
* Deinitialization of the server side
*
*/
void
dap_chain_node_cli_delete
(
void
)
{
if
(
server_sockfd
>=
0
)
closesocket
(
server_sockfd
);
}
This diff is collapsed.
Click to expand it.
dap_chain_node_cli.h
0 → 100644
+
39
−
0
View file @
1f513d11
/*
* Authors:
* Dmitriy A. Gearasimov <naeper@demlabs.net>
* DeM Labs Inc. https://demlabs.net
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
__BEGIN_DECLS
/**
* Initialization of the server side of the interaction
* with the console kelvin-node-cli
*
*/
int
dap_chain_node_cli_init
(
dap_config_t
*
g_config
);
/**
* Deinitialization of the server side
*
*/
void
dap_chain_node_cli_delete
(
void
);
__END_DECLS
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment