mirror of
https://github.com/haiwen/ccnet-server.git
synced 2025-08-10 17:01:37 +00:00
Delete UNIX SOCKET option under [Client].
This commit is contained in:
parent
e8324b72a2
commit
03a61d939c
@ -90,7 +90,6 @@ struct _CcnetClient
|
|||||||
char *config_file;
|
char *config_file;
|
||||||
|
|
||||||
int daemon_port;
|
int daemon_port;
|
||||||
char *un_path;
|
|
||||||
|
|
||||||
int connected : 1;
|
int connected : 1;
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ int
|
|||||||
ccnet_client_load_confdir (CcnetClient *client, const char *central_config_dir_r, const char *config_dir_r)
|
ccnet_client_load_confdir (CcnetClient *client, const char *central_config_dir_r, const char *config_dir_r)
|
||||||
{
|
{
|
||||||
char *config_file = NULL, *config_dir = NULL, *central_config_dir = NULL;
|
char *config_file = NULL, *config_dir = NULL, *central_config_dir = NULL;
|
||||||
char *id = NULL, *name = NULL, *port_str = NULL, *un_path = NULL,
|
char *id = NULL, *name = NULL, *port_str = NULL,
|
||||||
*user_name = NULL, *service_url = NULL;
|
*user_name = NULL, *service_url = NULL;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
GKeyFile *key_file;
|
GKeyFile *key_file;
|
||||||
@ -174,7 +174,6 @@ ccnet_client_load_confdir (CcnetClient *client, const char *central_config_dir_r
|
|||||||
name = ccnet_util_key_file_get_string (key_file, "General", "NAME");
|
name = ccnet_util_key_file_get_string (key_file, "General", "NAME");
|
||||||
service_url = ccnet_util_key_file_get_string (key_file, "General", "SERVICE_URL");
|
service_url = ccnet_util_key_file_get_string (key_file, "General", "SERVICE_URL");
|
||||||
port_str = ccnet_util_key_file_get_string (key_file, "Client", "PORT");
|
port_str = ccnet_util_key_file_get_string (key_file, "Client", "PORT");
|
||||||
un_path = ccnet_util_key_file_get_string (key_file, "Client", "UNIX_SOCKET");
|
|
||||||
|
|
||||||
if ( (id == NULL) || (strlen (id) != SESSION_ID_LENGTH)
|
if ( (id == NULL) || (strlen (id) != SESSION_ID_LENGTH)
|
||||||
|| (ccnet_util_hex_to_sha1 (id, sha1) < 0) )
|
|| (ccnet_util_hex_to_sha1 (id, sha1) < 0) )
|
||||||
@ -199,7 +198,6 @@ ccnet_client_load_confdir (CcnetClient *client, const char *central_config_dir_r
|
|||||||
|
|
||||||
if (port_str)
|
if (port_str)
|
||||||
client->daemon_port = atoi (port_str);
|
client->daemon_port = atoi (port_str);
|
||||||
client->un_path = un_path;
|
|
||||||
|
|
||||||
g_free (id);
|
g_free (id);
|
||||||
g_free (name);
|
g_free (name);
|
||||||
@ -220,67 +218,6 @@ onerror:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
ccnet_client_connect_daemon (CcnetClient *client, CcnetClientMode mode)
|
|
||||||
{
|
|
||||||
evutil_socket_t sockfd;
|
|
||||||
/* CcnetProcessor *processor; */
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
static int inited = 0;
|
|
||||||
if (inited == 0) {
|
|
||||||
inited = 1;
|
|
||||||
WSADATA wsadata;
|
|
||||||
WSAStartup(0x0101, &wsadata);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_return_val_if_fail (client->connected == 0, -1);
|
|
||||||
|
|
||||||
client->mode = mode;
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
struct sockaddr_in servaddr;
|
|
||||||
memset (&servaddr, 0, sizeof(servaddr));
|
|
||||||
servaddr.sin_family = AF_INET;
|
|
||||||
servaddr.sin_port = htons (client->daemon_port);
|
|
||||||
ccnet_util_inet_pton (AF_INET, "127.0.0.1", &servaddr.sin_addr);
|
|
||||||
if (connect (sockfd, (struct sockaddr *) &servaddr, (socklen_t)sizeof(servaddr)) < 0)
|
|
||||||
return -1;
|
|
||||||
#else
|
|
||||||
char *un_path = NULL;
|
|
||||||
|
|
||||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
struct sockaddr_un servaddr;
|
|
||||||
servaddr.sun_family = AF_UNIX;
|
|
||||||
|
|
||||||
if (!client->un_path)
|
|
||||||
un_path = g_build_filename (client->config_dir, CCNET_PIPE_NAME, NULL);
|
|
||||||
else
|
|
||||||
un_path = g_strdup(client->un_path);
|
|
||||||
|
|
||||||
g_strlcpy (servaddr.sun_path, un_path, sizeof(servaddr.sun_path));
|
|
||||||
g_free (un_path);
|
|
||||||
if (connect(sockfd, (struct sockaddr *)&servaddr, (socklen_t)sizeof(servaddr)) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
client->connfd = sockfd;
|
|
||||||
client->io = ccnet_packet_io_new (client->connfd);
|
|
||||||
|
|
||||||
if (mode == CCNET_CLIENT_ASYNC)
|
|
||||||
ccnet_packet_io_set_callback (client->io, handle_packet, client);
|
|
||||||
|
|
||||||
client->connected = 1;
|
|
||||||
|
|
||||||
g_debug ("connected to daemon\n");
|
|
||||||
|
|
||||||
return client->connfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ccnet_client_run_synchronizer (CcnetClient *client)
|
ccnet_client_run_synchronizer (CcnetClient *client)
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,6 @@ static int load_rsakey(CcnetSession *session)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void listen_on_pipe (CcnetSession *session);
|
|
||||||
static void save_pubinfo (CcnetSession *session);
|
static void save_pubinfo (CcnetSession *session);
|
||||||
|
|
||||||
CcnetSession *
|
CcnetSession *
|
||||||
@ -98,7 +97,6 @@ ccnet_session_load_config (CcnetSession *session,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *config_file = NULL, *config_dir = NULL, *central_config_dir = NULL;
|
char *config_file = NULL, *config_dir = NULL, *central_config_dir = NULL;
|
||||||
char *id = NULL, *name = NULL, *port_str = NULL,
|
char *id = NULL, *name = NULL, *port_str = NULL,
|
||||||
*un_path = NULL,
|
|
||||||
*user_name = NULL;
|
*user_name = NULL;
|
||||||
#ifdef CCNET_SERVER
|
#ifdef CCNET_SERVER
|
||||||
char *service_url;
|
char *service_url;
|
||||||
@ -146,8 +144,6 @@ ccnet_session_load_config (CcnetSession *session,
|
|||||||
#endif
|
#endif
|
||||||
port_str = ccnet_key_file_get_string (key_file, "Network", "PORT");
|
port_str = ccnet_key_file_get_string (key_file, "Network", "PORT");
|
||||||
|
|
||||||
un_path = ccnet_key_file_get_string (key_file, "Client", "UNIX_SOCKET");
|
|
||||||
|
|
||||||
if (port_str == NULL) {
|
if (port_str == NULL) {
|
||||||
port = 0;
|
port = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -175,7 +171,6 @@ ccnet_session_load_config (CcnetSession *session,
|
|||||||
session->config_file = config_file;
|
session->config_file = config_file;
|
||||||
session->config_dir = config_dir;
|
session->config_dir = config_dir;
|
||||||
session->central_config_dir = central_config_dir;
|
session->central_config_dir = central_config_dir;
|
||||||
session->un_path = un_path;
|
|
||||||
session->keyf = key_file;
|
session->keyf = key_file;
|
||||||
|
|
||||||
load_rsakey(session);
|
load_rsakey(session);
|
||||||
@ -245,7 +240,6 @@ ccnet_session_prepare (CcnetSession *session,
|
|||||||
if (test_config) {
|
if (test_config) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
listen_on_pipe (session);
|
|
||||||
/* refresh pubinfo on every startup */
|
/* refresh pubinfo on every startup */
|
||||||
save_pubinfo (session);
|
save_pubinfo (session);
|
||||||
}
|
}
|
||||||
@ -368,100 +362,6 @@ static const char *net_status_string (int status)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void accept_local_client (evutil_socket_t fd, short event, void *vsession)
|
|
||||||
{
|
|
||||||
CcnetSession *session = vsession;
|
|
||||||
CcnetPacketIO *io;
|
|
||||||
int connfd;
|
|
||||||
CcnetPeer *peer;
|
|
||||||
static int local_id = 0;
|
|
||||||
|
|
||||||
connfd = accept (fd, NULL, 0);
|
|
||||||
|
|
||||||
ccnet_message ("Accepted a local client\n");
|
|
||||||
|
|
||||||
io = ccnet_packet_io_new_incoming (session, NULL, connfd);
|
|
||||||
peer = ccnet_peer_new (session->base.id);
|
|
||||||
peer->name = g_strdup_printf("local-%d", local_id++);
|
|
||||||
peer->is_local = TRUE;
|
|
||||||
ccnet_peer_set_io (peer, io);
|
|
||||||
ccnet_peer_set_net_state (peer, PEER_CONNECTED);
|
|
||||||
ccnet_peer_manager_add_local_peer (session->peer_mgr, peer);
|
|
||||||
g_object_unref (peer);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
|
|
||||||
static void listen_on_pipe (CcnetSession *session)
|
|
||||||
{
|
|
||||||
int pipe_fd = socket (AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
char *un_path = NULL;
|
|
||||||
if (pipe_fd < 0) {
|
|
||||||
ccnet_warning ("Failed to create unix socket fd : %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_un saddr;
|
|
||||||
saddr.sun_family = AF_UNIX;
|
|
||||||
|
|
||||||
if (!session->un_path)
|
|
||||||
un_path = g_build_filename (session->config_dir, CCNET_PIPE_NAME, NULL);
|
|
||||||
else
|
|
||||||
un_path = g_strdup(session->un_path);
|
|
||||||
|
|
||||||
if (strlen(un_path) > sizeof(saddr.sun_path)-1) {
|
|
||||||
ccnet_warning ("Unix socket path %s is too long."
|
|
||||||
"Please set or modify UNIX_SOCKET option in ccnet.conf.\n",
|
|
||||||
un_path);
|
|
||||||
g_free (un_path);
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_file_test (un_path, G_FILE_TEST_EXISTS)) {
|
|
||||||
ccnet_warning ("socket file exists, delete it anyway\n");
|
|
||||||
if (g_unlink (un_path) < 0) {
|
|
||||||
ccnet_warning ("delete socket file failed : %s\n", strerror(errno));
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_strlcpy (saddr.sun_path, un_path, sizeof(saddr.sun_path));
|
|
||||||
if (bind(pipe_fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
|
|
||||||
ccnet_warning ("failed to bind unix socket fd to %s : %s\n",
|
|
||||||
un_path, strerror(errno));
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listen(pipe_fd, 3) < 0) {
|
|
||||||
ccnet_warning ("failed to listen to unix socket: %s\n", strerror(errno));
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chmod(un_path, 0700) < 0) {
|
|
||||||
ccnet_warning ("failed to set permisson for unix socket %s: %s\n",
|
|
||||||
un_path, strerror(errno));
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
event_set (&session->local_pipe_event, pipe_fd, EV_READ | EV_PERSIST,
|
|
||||||
accept_local_client, session);
|
|
||||||
event_add (&session->local_pipe_event, NULL);
|
|
||||||
|
|
||||||
ccnet_message ("Listen on %s for local clients\n", un_path);
|
|
||||||
|
|
||||||
g_free (un_path);
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
ccnet_warning ("listen on unix socket failed\n");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // WIN32
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ccnet_session_start_network (CcnetSession *session)
|
ccnet_session_start_network (CcnetSession *session)
|
||||||
{
|
{
|
||||||
|
@ -86,9 +86,7 @@ struct CcnetSession
|
|||||||
unsigned int saving_pub : 1;
|
unsigned int saving_pub : 1;
|
||||||
unsigned int encrypt_channel : 1;
|
unsigned int encrypt_channel : 1;
|
||||||
|
|
||||||
char *un_path;
|
|
||||||
struct event local_event;
|
struct event local_event;
|
||||||
struct event local_pipe_event;
|
|
||||||
|
|
||||||
int start_failure; /* how many times failed
|
int start_failure; /* how many times failed
|
||||||
to start the network */
|
to start the network */
|
||||||
|
Loading…
Reference in New Issue
Block a user