]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/send-announce.cc
b414d6aeb6faf2d97bd39ebd52b96d4c26ec61c7
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 27 Cache Announcer */
12 #include "anyp/PortCfg.h"
13 #include "comm/Connection.h"
21 #include "SquidConfig.h"
22 #include "SquidTime.h"
25 static IPH send_announce
;
28 start_announce(void *)
30 if (0 == Config
.onoff
.announce
)
33 if (!Comm::IsConnOpen(icpOutgoingConn
))
36 ipcache_nbgethostbyname(Config
.Announce
.host
, send_announce
, NULL
);
38 eventAdd("send_announce", start_announce
, NULL
, (double) Config
.Announce
.period
, 1);
42 send_announce(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *)
44 LOCAL_ARRAY(char, tbuf
, 256);
45 LOCAL_ARRAY(char, sndbuf
, BUFSIZ
);
47 char *host
= Config
.Announce
.host
;
49 unsigned short port
= Config
.Announce
.port
;
55 debugs(27, DBG_IMPORTANT
, "send_announce: Unknown host '" << host
<< "'");
59 debugs(27, DBG_IMPORTANT
, "Sending Announcement to " << host
);
61 snprintf(tbuf
, 256, "cache_version SQUID/%s\n", version_string
);
63 assert(HttpPortList
!= NULL
);
64 snprintf(tbuf
, 256, "Running on %s %d %d\n",
67 (int) Config
.Port
.icp
);
70 if (Config
.adminEmail
) {
71 snprintf(tbuf
, 256, "cache_admin: %s\n", Config
.adminEmail
);
75 snprintf(tbuf
, 256, "generated %d [%s]\n",
77 Time::FormatHttpd(squid_curtime
));
81 if ((file
= Config
.Announce
.file
) != NULL
) {
82 fd
= file_open(file
, O_RDONLY
| O_TEXT
);
84 if (fd
> -1 && (n
= FD_READ_METHOD(fd
, sndbuf
+ l
, BUFSIZ
- l
- 1)) > 0) {
85 fd_bytes(fd
, n
, FD_READ
);
90 debugs(50, DBG_IMPORTANT
, "send_announce: " << file
<< ": " << xstrerror());
94 Ip::Address S
= ia
->in_addrs
[0];
96 assert(Comm::IsConnOpen(icpOutgoingConn
));
98 if (comm_udp_sendto(icpOutgoingConn
->fd
, S
, sndbuf
, strlen(sndbuf
) + 1) < 0)
99 debugs(27, DBG_IMPORTANT
, "ERROR: Failed to announce to " << S
<< " from " << icpOutgoingConn
->local
<< ": " << xstrerror());