y_socket: add other address: all excluding local address

This commit is contained in:
2025-10-18 13:59:26 +02:00
parent 807269035d
commit 1f4dd9cc4c
4 changed files with 80 additions and 1 deletions
@@ -27,6 +27,7 @@ struct arg_send_file{
void* y_socket_send_file_for_all_nodes(void* arg); void* y_socket_send_file_for_all_nodes(void* arg);
void* y_socket_send_file_for_node(void* arg); void* y_socket_send_file_for_node(void* arg);
void* y_send_buf_for_all_(void* arg); void* y_send_buf_for_all_(void* arg);
void* y_send_buf_for_other_(void* arg);
enum cmd_type { enum cmd_type {
cmd_update_kill, cmd_update_kill,
@@ -679,6 +679,62 @@ void* y_send_buf_for_all_(void* arg){
return NULL; return NULL;
} }
void* y_send_buf_for_other_(void* arg){
struct arg_send_file *argS=(struct arg_send_file*)arg;
struct pollfd *fds=argS->fds;
struct main_list_y_NODE_T *nodes=argS->nodes;
// if(export_nodes_to_file("file_nodes_name", nodes)==-1){
// fprintf(stderr, "error export_nodes_to_file\n");
// }
char * buf_send=argS->filename;
#if TEMP_ADDR
char tempAddr[64];
#endif
int c_af;
// char host[NI_MAXHOST], service[NI_MAXSERV];
#if 0
int status = getnameinfo((struct sockaddr*)&(node.addr), node.addr_len, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICHOST);
if(status)
// printf("debug: status ==0 : success: Received successfully from %s:%s\n", host,service);
// else
fprintf(stderr, "getnameinfo: %s\n", gai_strerror(status));
if(NULL == search_node_in_list_y_NODE_T(nodes, node))
push_back_list_y_NODE_T(nodes, node);
#endif
size_t len_buf_send=strlen(buf_send);
for(struct list_y_NODE_T *local_list_current = nodes->begin_list; local_list_current; local_list_current=local_list_current->next ){
if(local_list_current->value.local_addr == 0){
set_addr_str_from_node(tempAddr, local_list_current->value);
c_af=(local_list_current->value).addr.ss_family;
if(sendto(fds[(c_af==AF_INET6)].fd,
buf_send, len_buf_send,
0,
(struct sockaddr*)&((local_list_current->value).addr),
(local_list_current->value).addr_len) !=
len_buf_send
){
fprintf(stderr, "Error sending %s to %s\n", tempAddr, buf_send);
}/*else{
printf("debug: sending [%s] -> < %s >",buf_send,tempAddr);
}*/
///printf("debug: for index = %ld\n",local_list_current->index);
}
}
return NULL;
}
/// /// /// ///
+3 -1
View File
@@ -167,7 +167,9 @@ struct main_list_y_ptr_STRING * split_str_to_main_list_y_ptr_STRING(char *str_or
void usage_cmdl(){ void usage_cmdl(){
printf("usage:\n" printf("usage:\n"
"sendto [addr] { \"cmd\" : \"[command]\" }\n" "sendto [addr] { \"cmd\" : \"[command]\" }\n"
"addr: ipv4 address or ipv6 address or all to send cmd to all nodes already in the list.\n" "addr: ipv4 address or ipv6 address \n"
"\tor all to send cmd to all nodes already in the list.\n"
"\tor other to send cmd to all nodes excluding local address in the list.\n"
"command: \n" "command: \n"
"\tupdate kill: to gracefully shutdown socket server.\n" "\tupdate kill: to gracefully shutdown socket server.\n"
"\tupdate standby: to suspend all workers, but can receive all task but in queu tasks.\n" "\tupdate standby: to suspend all workers, but can receive all task but in queu tasks.\n"
+20
View File
@@ -557,6 +557,26 @@ void *y_socket_poll_fds(void *arg){
push_tasQ(argx->tasQ, task_handl); push_tasQ(argx->tasQ, task_handl);
}else if(strcmp(dst_addr, "other" ) == 0){
struct arg_send_file *argS = malloc(sizeof(struct arg_send_file));
argS->fds=fds;
argS->nodes=argSock->nodes;
argS->node=node;
argS->filename=malloc(buf_len-index_buf+1); /* put here message to send for all */
memcpy(argS->filename, buf+index_buf, buf_len-index_buf);
argS->filename[buf_len-index_buf] = '\0';
argS->m_ok_head_l_t=m_ok_head_l_t;
push_back_list_TYPE_PTR(list_arg, argS);
push_back_list_TYPE_PTR(list_arg, argS->filename);
struct y_task_t task_handl = {
.func=y_send_buf_for_other_,
.arg=argS,
.status=TASK_PENDING,
};
push_tasQ(argx->tasQ, task_handl);
} }
else if(set_addr_y_NODE_T_from_str_addr(&node, dst_addr)){ else if(set_addr_y_NODE_T_from_str_addr(&node, dst_addr)){
///printf("debug : set_addr_y_NODE_T done\n"); ///printf("debug : set_addr_y_NODE_T done\n");