root/src/stratcon_jlog_streamer.h

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

This change should finally fix it. closes #58

  • 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   struct {
90     jlog_id   chkpt;
91     u_int32_t tv_sec;
92     u_int32_t tv_usec;
93     u_int32_t message_len;
94   } header;
95
96   u_int64_t total_events;
97   u_int64_t total_bytes_read;
98
99   void (*push)(stratcon_datastore_op_t, struct sockaddr *, const char *, void *, eventer_t);
100 } jlog_streamer_ctx_t;
101
102 API_EXPORT(void)
103   stratcon_jlog_streamer_init(const char *toplevel);
104 API_EXPORT(void)
105   stratcon_jlog_streamer_reload(const char *toplevel);
106 API_EXPORT(int)
107   stratcon_jlog_recv_handler(eventer_t e, int mask, void *closure,
108                              struct timeval *now);
109 API_EXPORT(jlog_streamer_ctx_t *)
110   stratcon_jlog_streamer_ctx_alloc(void);
111 API_EXPORT(void)
112   jlog_streamer_ctx_free(void *cl);
113 API_EXPORT(int)
114   noit_connection_update_timeout(noit_connection_ctx_t *ctx);
115 API_EXPORT(int)
116   noit_connection_disable_timeout(noit_connection_ctx_t *ctx);
117 API_EXPORT(void)
118   noit_connection_ctx_dealloc(noit_connection_ctx_t *ctx);
119 API_EXPORT(void)
120   stratcon_streamer_connection(const char *toplevel, const char *destination,
121                                eventer_func_t handler,
122                                void *(*handler_alloc)(void), void *handler_ctx,
123                                void (*handler_free)(void *));
124
125 /*! \fn int stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len)
126     \brief find the remote IPv4 address for the cn if it is configured
127     \param cn the remote CN in which you are interested
128     \param ip the buffer where the IP will be stored if it is found
129     \param len the length of the passed buffer
130     \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.
131  */
132
133 API_EXPORT(int)
134   stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len);
135
136
137 #endif
Note: See TracBrowser for help on using the browser.