15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
|
*/ |
21 |
|
|
42 |
|
#include "packet.h" |
43 |
|
|
44 |
|
|
45 |
< |
static unsigned int current_serial = 0; |
45 |
> |
static uint64_t current_serial; |
46 |
|
|
47 |
|
|
48 |
|
/* send_format() |
71 |
|
*/ |
72 |
|
dbuf_put_args(buffer, pattern, args); |
73 |
|
|
74 |
< |
if (buffer->size > sizeof(buffer->data) - 2) |
75 |
< |
buffer->size = sizeof(buffer->data) - 2; |
74 |
> |
if (buffer->size > IRCD_BUFSIZE - 2) |
75 |
> |
buffer->size = IRCD_BUFSIZE - 2; |
76 |
|
|
77 |
|
buffer->data[buffer->size++] = '\r'; |
78 |
|
buffer->data[buffer->size++] = '\n'; |
89 |
|
assert(!IsMe(to)); |
90 |
|
assert(to != &me); |
91 |
|
|
92 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs)) |
92 |
> |
if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs)) |
93 |
|
{ |
94 |
|
if (IsServer(to)) |
95 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
96 |
|
"Max SendQ limit exceeded for %s: %lu > %u", |
97 |
|
get_client_name(to, HIDE_IP), |
98 |
< |
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size), |
99 |
< |
get_sendq(&to->localClient->confs)); |
98 |
> |
(unsigned long)(dbuf_length(&to->connection->buf_sendq) + buf->size), |
99 |
> |
get_sendq(&to->connection->confs)); |
100 |
|
if (IsClient(to)) |
101 |
|
SetSendQExceeded(to); |
102 |
|
|
104 |
|
return; |
105 |
|
} |
106 |
|
|
107 |
< |
dbuf_add(&to->localClient->buf_sendq, buf); |
107 |
> |
dbuf_add(&to->connection->buf_sendq, buf); |
108 |
|
|
109 |
|
/* |
110 |
|
* Update statistics. The following is slightly incorrect because |
111 |
|
* it counts messages even if queued, but bytes only really sent. |
112 |
|
* Queued bytes get updated in send_queued_write(). |
113 |
|
*/ |
114 |
< |
++to->localClient->send.messages; |
115 |
< |
++me.localClient->send.messages; |
114 |
> |
++to->connection->send.messages; |
115 |
> |
++me.connection->send.messages; |
116 |
|
|
117 |
|
send_queued_write(to); |
118 |
|
} |
182 |
|
** Called when a socket is ready for writing. |
183 |
|
*/ |
184 |
|
void |
185 |
< |
sendq_unblocked(fde_t *fd, struct Client *client_p) |
185 |
> |
sendq_unblocked(fde_t *fd, void *data) |
186 |
|
{ |
187 |
< |
assert(fd == &client_p->localClient->fd); |
187 |
> |
struct Client *client_p = data; |
188 |
> |
assert(fd == &client_p->connection->fd); |
189 |
|
|
190 |
|
DelFlag(client_p, FLAGS_BLOCKED); |
191 |
|
send_queued_write(client_p); |
210 |
|
return; /* no use calling send() now */ |
211 |
|
|
212 |
|
/* Next, lets try to write some data */ |
213 |
< |
if (dbuf_length(&to->localClient->buf_sendq)) |
213 |
> |
if (dbuf_length(&to->connection->buf_sendq)) |
214 |
|
{ |
215 |
|
do |
216 |
|
{ |
217 |
< |
struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data; |
217 |
> |
struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data; |
218 |
|
|
219 |
|
#ifdef HAVE_LIBCRYPTO |
220 |
< |
if (to->localClient->fd.ssl) |
220 |
> |
if (to->connection->fd.ssl) |
221 |
|
{ |
222 |
< |
retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos); |
222 |
> |
retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos); |
223 |
|
|
224 |
|
/* translate openssl error codes, sigh */ |
225 |
|
if (retlen < 0) |
226 |
|
{ |
227 |
< |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
227 |
> |
switch (SSL_get_error(to->connection->fd.ssl, retlen)) |
228 |
|
{ |
229 |
|
case SSL_ERROR_WANT_READ: |
230 |
|
return; /* retry later, don't register for write events */ |
242 |
|
} |
243 |
|
else |
244 |
|
#endif |
245 |
< |
retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0); |
245 |
> |
retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0); |
246 |
|
|
247 |
|
if (retlen <= 0) |
248 |
|
break; |
249 |
|
|
250 |
< |
dbuf_delete(&to->localClient->buf_sendq, retlen); |
250 |
> |
dbuf_delete(&to->connection->buf_sendq, retlen); |
251 |
|
|
252 |
|
/* We have some data written .. update counters */ |
253 |
< |
to->localClient->send.bytes += retlen; |
254 |
< |
me.localClient->send.bytes += retlen; |
255 |
< |
} while (dbuf_length(&to->localClient->buf_sendq)); |
253 |
> |
to->connection->send.bytes += retlen; |
254 |
> |
me.connection->send.bytes += retlen; |
255 |
> |
} while (dbuf_length(&to->connection->buf_sendq)); |
256 |
|
|
257 |
|
if (retlen < 0 && ignoreErrno(errno)) |
258 |
|
{ |
259 |
|
AddFlag(to, FLAGS_BLOCKED); |
260 |
|
|
261 |
|
/* we have a non-fatal error, reschedule a write */ |
262 |
< |
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
263 |
< |
(PF *)sendq_unblocked, to, 0); |
262 |
> |
comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, |
263 |
> |
sendq_unblocked, to, 0); |
264 |
|
} |
265 |
|
else if (retlen <= 0) |
266 |
|
{ |
284 |
|
/* Servers are processed first, mainly because this can generate |
285 |
|
* a notice to opers, which is to be delivered by this function. |
286 |
|
*/ |
287 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
287 |
> |
DLINK_FOREACH(ptr, local_server_list.head) |
288 |
|
send_queued_write(ptr->data); |
289 |
|
|
290 |
|
DLINK_FOREACH(ptr, unknown_list.head) |
353 |
|
numstr = va_arg(args, const char *); |
354 |
|
else |
355 |
|
numstr = numeric_form(numeric); |
356 |
+ |
|
357 |
|
send_format(buffer, numstr, args); |
358 |
|
va_end(args); |
359 |
|
|
445 |
|
|
446 |
|
if (MyConnect(target_p)) |
447 |
|
send_message(target_p, local_buf); |
448 |
< |
else if (target_p->from->localClient->serial != current_serial) |
448 |
> |
else if (target_p->from->connection->serial != current_serial) |
449 |
|
send_message_remote(target_p->from, from, remote_buf); |
450 |
< |
target_p->from->localClient->serial = current_serial; |
450 |
> |
target_p->from->connection->serial = current_serial; |
451 |
|
} |
452 |
|
|
453 |
|
dbuf_ref_free(local_buf); |
488 |
|
send_format(buffer, format, args); |
489 |
|
va_end(args); |
490 |
|
|
491 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
491 |
> |
DLINK_FOREACH(ptr, local_server_list.head) |
492 |
|
{ |
493 |
|
struct Client *client_p = ptr->data; |
494 |
|
|
499 |
|
if (one && (client_p == one->from)) |
500 |
|
continue; |
501 |
|
/* check we have required capabs */ |
502 |
< |
if ((client_p->localClient->caps & caps) != caps) |
502 |
> |
if ((client_p->connection->caps & caps) != caps) |
503 |
|
continue; |
504 |
|
/* check we don't have any forbidden capabs */ |
505 |
< |
if ((client_p->localClient->caps & nocaps)) |
505 |
> |
if ((client_p->connection->caps & nocaps)) |
506 |
|
continue; |
507 |
|
|
508 |
|
send_message(client_p, buffer); |
550 |
|
target_p = ms->client_p; |
551 |
|
|
552 |
|
if (target_p == user || IsDefunct(target_p) || |
553 |
< |
target_p->localClient->serial == current_serial) |
553 |
> |
target_p->connection->serial == current_serial) |
554 |
|
continue; |
555 |
|
|
556 |
|
if (HasCap(target_p, cap) != cap) |
557 |
|
continue; |
558 |
|
|
559 |
< |
target_p->localClient->serial = current_serial; |
559 |
> |
target_p->connection->serial = current_serial; |
560 |
|
send_message(target_p, buffer); |
561 |
|
} |
562 |
|
} |
563 |
|
|
564 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
565 |
< |
user->localClient->serial != current_serial) |
565 |
> |
user->connection->serial != current_serial) |
566 |
|
if (HasCap(user, cap) == cap) |
567 |
|
send_message(user, buffer); |
568 |
|
|
724 |
|
} |
725 |
|
|
726 |
|
/* Now scan servers */ |
727 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
727 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, local_server_list.head) |
728 |
|
{ |
729 |
|
struct Client *client_p = ptr->data; |
730 |
|
|
794 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
795 |
|
continue; |
796 |
|
|
797 |
< |
if (target_p->from->localClient->serial == current_serial) |
797 |
> |
if (target_p->from->connection->serial == current_serial) |
798 |
|
continue; |
799 |
|
|
800 |
|
if (!match(mask, target_p->name)) |
803 |
|
* if we set the serial here, then we'll never do a |
804 |
|
* match() again, if !IsCapable() |
805 |
|
*/ |
806 |
< |
target_p->from->localClient->serial = current_serial; |
806 |
> |
target_p->from->connection->serial = current_serial; |
807 |
|
|
808 |
|
if (!IsCapable(target_p->from, cap)) |
809 |
|
continue; |
918 |
|
* (at most 5 warnings every 5 seconds) |
919 |
|
*/ |
920 |
|
void |
921 |
< |
sendto_realops_flags_ratelimited(const char *pattern, ...) |
921 |
> |
sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...) |
922 |
|
{ |
923 |
|
va_list args; |
924 |
|
char buffer[IRCD_BUFSIZE] = ""; |
923 |
– |
static time_t last = 0; |
924 |
– |
static int warnings = 0; |
925 |
|
|
926 |
< |
if (CurrentTime - last < 5) |
927 |
< |
{ |
928 |
< |
if (++warnings > 5) |
929 |
< |
return; |
930 |
< |
} |
931 |
< |
else |
932 |
< |
{ |
933 |
< |
last = CurrentTime; |
934 |
< |
warnings = 0; |
935 |
< |
} |
926 |
> |
if ((CurrentTime - *rate) < 20) |
927 |
> |
return; |
928 |
> |
*rate = CurrentTime; |
929 |
|
|
930 |
|
va_start(args, pattern); |
931 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |