2 * Copyright (C) 2006-2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file dccp_send.c paraslash's dccp sender */
10 * based on server.c of dccp-cs-0.01.tar.bz2,
11 * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
14 #include <sys/types.h>
28 #include "close_on_fork.h"
29 #include "chunk_queue.h"
30 #include "server.cmdline.h"
33 /** the list of connected clients **/
34 static struct list_head clients;
35 /** The whitelist/blacklist. */
36 static struct list_head dccp_acl;
37 static int listen_fd = -1;
39 /** Maximal number of bytes in a chunk queue. */
40 #define DCCP_MAX_PENDING_BYTES 40000
42 /** Do not write more than that many bytes at once. */
43 #define DCCP_MAX_BYTES_PER_WRITE 1024
45 static void dccp_pre_select(int *max_fileno, fd_set *rfds,
46 __a_unused fd_set *wfds)
49 para_fd_set(listen_fd, rfds, max_fileno);
52 static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds)
54 struct sender_client *sc;
57 if (listen_fd < 0 || !FD_ISSET(listen_fd, rfds))
59 ret = para_accept(listen_fd, NULL, 0);
61 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
66 * Bypass unused CCID paths: the sender does not receive application data
67 * from the client; by shutting down this unused communication path we can
68 * reduce processing costs a bit. See analogous comment in dccp_recv.c.
70 if (shutdown(fd, SHUT_RD) < 0) {
71 ret = -ERRNO_TO_PARA_ERROR(errno);
74 ret = mark_fd_nonblocking(fd);
77 ret = acl_check_access(fd, &dccp_acl, conf.dccp_default_deny_given);
80 sc = para_calloc(sizeof(*sc));
82 sc->name = make_message("%s", remote_name(sc->fd));
83 PARA_NOTICE_LOG("connection from %s\n", sc->name);
84 para_list_add(&sc->node, &clients);
85 add_close_on_fork_list(sc->fd);
86 sc->cq = cq_new(DCCP_MAX_PENDING_BYTES);
89 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
93 static void dccp_send(long unsigned current_chunk,
94 __a_unused long unsigned chunks_sent, const char *buf, size_t len)
96 struct sender_client *sc, *tmp;
98 list_for_each_entry_safe(sc, tmp, &clients, node)
99 send_chunk(sc, DCCP_MAX_BYTES_PER_WRITE, current_chunk, buf,
103 static void dccp_shutdown_clients(void)
105 struct sender_client *sc, *tmp;
107 list_for_each_entry_safe(sc, tmp, &clients, node)
111 static int dccp_com_deny(struct sender_command_data *scd)
113 acl_deny(scd->addr, scd->netmask, &dccp_acl,
114 conf.dccp_default_deny_given);
118 static int dccp_com_allow(struct sender_command_data *scd)
120 acl_allow(scd->addr, scd->netmask, &dccp_acl,
121 conf.dccp_default_deny_given);
125 static char *dccp_info(void)
128 struct sender_client *sc, *tmp;
130 list_for_each_entry_safe(sc, tmp, &clients, node)
132 return make_message("dccp connected clients: %d\n", num_clients);
135 static char *dccp_help(void)
137 return make_message("no help available\n");
141 * The init function of the dccp sender.
143 * \param s pointer to the dccp sender struct.
145 * It initializes all function pointers of \a s and starts
146 * listening on the given port.
148 void dccp_send_init(struct sender *s)
152 INIT_LIST_HEAD(&clients);
155 s->pre_select = dccp_pre_select;
156 s->post_select = dccp_post_select;
157 s->shutdown_clients = dccp_shutdown_clients;
159 s->client_cmds[SENDER_ON] = NULL;
160 s->client_cmds[SENDER_OFF] = NULL;
161 s->client_cmds[SENDER_DENY] = dccp_com_deny;
162 s->client_cmds[SENDER_ALLOW] = dccp_com_allow;
163 s->client_cmds[SENDER_ADD] = NULL;
164 s->client_cmds[SENDER_DELETE] = NULL;
165 acl_init(&dccp_acl, conf.dccp_access_arg, conf.dccp_access_given);
166 ret = open_sender(IPPROTO_DCCP, conf.dccp_port_arg);
168 PARA_ERROR_LOG("%s\n", para_strerror(-ret));