]>
Commit | Line | Data |
---|---|---|
7d49daab | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
e25c139f | 3 | * |
bbc27441 AJ |
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. | |
7d49daab | 7 | */ |
090089c4 | 8 | |
bbc27441 AJ |
9 | /* DEBUG: section 27 Cache Announcer */ |
10 | ||
582c2af2 | 11 | #include "squid.h" |
fa720bfb | 12 | #include "anyp/PortCfg.h" |
e0d28505 | 13 | #include "comm/Connection.h" |
438b04d4 | 14 | #include "disk.h" |
a553a5a3 | 15 | #include "event.h" |
c4ad1349 | 16 | #include "fd.h" |
528b2c61 | 17 | #include "fde.h" |
582c2af2 | 18 | #include "globals.h" |
e0d28505 | 19 | #include "ICP.h" |
714e68b7 | 20 | #include "ipcache.h" |
4d5904f7 | 21 | #include "SquidConfig.h" |
985c86bc | 22 | #include "SquidTime.h" |
4e540555 | 23 | #include "tools.h" |
090089c4 | 24 | |
b69f7771 | 25 | static IPH send_announce; |
e924600d | 26 | |
b8d8561b | 27 | void |
ced8def3 | 28 | start_announce(void *) |
e924600d | 29 | { |
9072f1fa | 30 | if (0 == Config.onoff.announce) |
62e76326 | 31 | return; |
32 | ||
e0d28505 | 33 | if (!Comm::IsConnOpen(icpOutgoingConn)) |
62e76326 | 34 | return; |
35 | ||
28c60158 | 36 | ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL); |
62e76326 | 37 | |
52040193 | 38 | eventAdd("send_announce", start_announce, NULL, (double) Config.Announce.period, 1); |
e924600d | 39 | } |
40 | ||
41 | static void | |
ced8def3 | 42 | send_announce(const ipcache_addrs *ia, const DnsLookupDetails &, void *) |
090089c4 | 43 | { |
95d659f0 | 44 | LOCAL_ARRAY(char, tbuf, 256); |
45 | LOCAL_ARRAY(char, sndbuf, BUFSIZ); | |
62e76326 | 46 | |
48f44632 | 47 | char *host = Config.Announce.host; |
7d49daab | 48 | char *file = NULL; |
f45dd259 | 49 | unsigned short port = Config.Announce.port; |
7d49daab | 50 | int l; |
51 | int n; | |
03a1ee42 | 52 | int fd; |
62e76326 | 53 | |
e924600d | 54 | if (ia == NULL) { |
e0236918 | 55 | debugs(27, DBG_IMPORTANT, "send_announce: Unknown host '" << host << "'"); |
62e76326 | 56 | return; |
234967c9 | 57 | } |
62e76326 | 58 | |
e0236918 | 59 | debugs(27, DBG_IMPORTANT, "Sending Announcement to " << host); |
234967c9 | 60 | sndbuf[0] = '\0'; |
56878878 | 61 | snprintf(tbuf, 256, "cache_version SQUID/%s\n", version_string); |
7d49daab | 62 | strcat(sndbuf, tbuf); |
fa720bfb | 63 | assert(HttpPortList != NULL); |
56878878 | 64 | snprintf(tbuf, 256, "Running on %s %d %d\n", |
62e76326 | 65 | getMyHostname(), |
66 | getMyPort(), | |
67 | (int) Config.Port.icp); | |
7d49daab | 68 | strcat(sndbuf, tbuf); |
62e76326 | 69 | |
b6f794d6 | 70 | if (Config.adminEmail) { |
62e76326 | 71 | snprintf(tbuf, 256, "cache_admin: %s\n", Config.adminEmail); |
72 | strcat(sndbuf, tbuf); | |
234967c9 | 73 | } |
62e76326 | 74 | |
042461c3 | 75 | snprintf(tbuf, 256, "generated %d [%s]\n", |
62e76326 | 76 | (int) squid_curtime, |
20efa1c2 | 77 | Time::FormatHttpd(squid_curtime)); |
7d49daab | 78 | strcat(sndbuf, tbuf); |
374b5a2d | 79 | l = strlen(sndbuf); |
62e76326 | 80 | |
79d39a72 | 81 | if ((file = Config.Announce.file) != NULL) { |
62e76326 | 82 | fd = file_open(file, O_RDONLY | O_TEXT); |
83 | ||
84 | if (fd > -1 && (n = FD_READ_METHOD(fd, sndbuf + l, BUFSIZ - l - 1)) > 0) { | |
85 | fd_bytes(fd, n, FD_READ); | |
86 | l += n; | |
87 | sndbuf[l] = '\0'; | |
88 | file_close(fd); | |
89 | } else { | |
e0236918 | 90 | debugs(50, DBG_IMPORTANT, "send_announce: " << file << ": " << xstrerror()); |
62e76326 | 91 | } |
090089c4 | 92 | } |
62e76326 | 93 | |
e0d28505 | 94 | Ip::Address S = ia->in_addrs[0]; |
4dd643d5 | 95 | S.port(port); |
e0d28505 | 96 | assert(Comm::IsConnOpen(icpOutgoingConn)); |
62e76326 | 97 | |
e0d28505 | 98 | if (comm_udp_sendto(icpOutgoingConn->fd, S, sndbuf, strlen(sndbuf) + 1) < 0) |
e0236918 | 99 | debugs(27, DBG_IMPORTANT, "ERROR: Failed to announce to " << S << " from " << icpOutgoingConn->local << ": " << xstrerror()); |
090089c4 | 100 | } |
f53969cc | 101 |