root/src/stratcon_jlog_streamer.h

Revision 581db2477ea3eaaf110a4a18e3cc68b74e03ca42, 4.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 years ago)

fixes #311

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _STRATCON_LOG_STREAMER_H
34 #define _STRATCON_LOG_STREAMER_H
35
36 #include "noit_conf.h"
37 #include "utils/noit_atomic.h"
38 #include "jlog/jlog.h"
39 #include <netinet/in.h>
40 #include <sys/un.h>
41 #include <arpa/inet.h>
42 #include "stratcon_datastore.h"
43
44 #define DEFAULT_NOIT_CONNECTION_TIMEOUT 60000 /* 60 seconds */
45
46 typedef struct noit_connection_ctx_t {
47   noit_atomic32_t refcnt;
48   union {
49     struct sockaddr remote;
50     struct sockaddr_un remote_un;
51     struct sockaddr_in remote_in;
52     struct sockaddr_in6 remote_in6;
53   } r;
54   socklen_t remote_len;
55   char *remote_str;
56   char *remote_cn;
57   u_int32_t current_backoff;
58   int wants_shutdown;
59   int wants_permanent_shutdown;
60   int max_silence;
61   noit_hash_table *config;
62   noit_hash_table *sslconfig;
63   struct timeval last_connect;
64   eventer_t timeout_event;
65   eventer_t retry_event;
66   eventer_t e;
67
68   eventer_func_t consumer_callback;
69   void (*consumer_free)(void *);
70   void *consumer_ctx;
71 } noit_connection_ctx_t;
72
73 typedef struct jlog_streamer_ctx_t {
74   u_int32_t jlog_feed_cmd;
75   int bytes_expected;
76   int bytes_read;
77   char *buffer;         /* These guys are for doing partial reads */
78
79   enum {
80     JLOG_STREAMER_WANT_INITIATE = 0,
81     JLOG_STREAMER_WANT_COUNT = 1,
82     JLOG_STREAMER_WANT_HEADER = 2,
83     JLOG_STREAMER_WANT_BODY = 3,
84     JLOG_STREAMER_IS_ASYNC = 4,
85     JLOG_STREAMER_WANT_CHKPT = 5,
86     JLOG_STREAMER_WANT_ERROR = 6,
87   } state;
88   int count;            /* Number of jlog messages we need to read */
89   int needs_chkpt;
90   struct {
91     jlog_id   chkpt;
92     u_int32_t tv_sec;
93     u_int32_t tv_usec;
94     u_int32_t message_len;
95   } header;
96
97   u_int64_t total_events;
98   u_int64_t total_bytes_read;
99
100   void (*push)(stratcon_datastore_op_t, struct sockaddr *, const char *, void *, eventer_t);
101 } jlog_streamer_ctx_t;
102
103 API_EXPORT(void)
104   stratcon_jlog_streamer_init(const char *toplevel);
105 API_EXPORT(void)
106   stratcon_jlog_streamer_reload(const char *toplevel);
107 API_EXPORT(int)
108   stratcon_jlog_recv_handler(eventer_t e, int mask, void *closure,
109                              struct timeval *now);
110 API_EXPORT(jlog_streamer_ctx_t *)
111   stratcon_jlog_streamer_ctx_alloc(void);
112 API_EXPORT(void)
113   jlog_streamer_ctx_free(void *cl);
114 API_EXPORT(int)
115   noit_connection_update_timeout(noit_connection_ctx_t *ctx);
116 API_EXPORT(int)
117   noit_connection_disable_timeout(noit_connection_ctx_t *ctx);
118 API_EXPORT(void)
119   noit_connection_ctx_dealloc(noit_connection_ctx_t *ctx);
120 API_EXPORT(void)
121   stratcon_streamer_connection(const char *toplevel, const char *destination,
122                                eventer_func_t handler,
123                                void *(*handler_alloc)(void), void *handler_ctx,
124                                void (*handler_free)(void *));
125
126 /*! \fn int stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len)
127     \brief find the remote IPv4 address for the cn if it is configured
128     \param cn the remote CN in which you are interested
129     \param ip the buffer where the IP will be stored if it is found
130     \param len the length of the passed buffer
131     \return 0 on success, -1 if the CN is not in the cache, > 0 represents the size needed if the supplied buffer is too short.
132  */
133
134 API_EXPORT(int)
135   stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len);
136
137
138 #endif
Note: See TracBrowser for help on using the browser.