1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#ifndef UPSTREAM_H
#define UPSTREAM_H
#include "config.h"
#include "util.h"
#include "rdns.h"
enum rspamd_upstream_rotation {
RSPAMD_UPSTREAM_RANDOM,
RSPAMD_UPSTREAM_HASHED,
RSPAMD_UPSTREAM_ROUND_ROBIN,
RSPAMD_UPSTREAM_MASTER_SLAVE
};
/* Opaque upstream structures */
struct upstream;
struct upstream_list;
/**
* Init upstreams library
* @param resolver
*/
void rspamd_upstreams_library_init (struct rdns_resolver *resolver,
struct event_base *base);
/**
* Upstream error logic
* 1. During error time we count upstream_ok and upstream_fail
* 2. If failcount is more then maxerrors then we mark upstream as unavailable for dead time
* 3. After dead time we mark upstream as alive and go to the step 1
* 4. If all upstreams are dead, marks every upstream as alive
*/
/**
* Add an error to an upstream
*/
void rspamd_upstream_fail (struct upstream *up);
/**
* Increase upstream successes count
*/
void rspamd_upstream_ok (struct upstream *up);
/**
* Create new list of upstreams
* @return
*/
struct upstream_list* rspamd_upstreams_create (void);
/**
* Destroy list of upstreams
* @param ups
*/
void rspamd_upstreams_destroy (struct upstream_list *ups);
/**
* Add upstream from the string
* @param ups upstream list
* @param str string in format "name[:port[:priority]]"
* @param def_port default port number
* @param data optional userdata
* @return TRUE if upstream has been added
*/
gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups,
const gchar *str, guint16 def_port, void *data);
/**
* Add multiple upstreams from comma, semicolon or space separated line
* @param ups upstream list
* @param str string in format "(<ups>([<sep>+]<ups>)*)+"
* @param def_port default port number
* @param data optional userdata
* @return TRUE if **any** of upstreams has been added
*/
gboolean rspamd_upstreams_parse_line (struct upstream_list *ups,
const gchar *str, guint16 def_port, void *data);
/**
* Returns the current IP address of the upstream
* @param up
* @return
*/
rspamd_inet_addr_t* rspamd_upstream_addr (struct upstream *up);
/**
* Returns the symbolic name of the upstream
* @param up
* @return
*/
const gchar* rspamd_upstream_name (struct upstream *up);
/**
* Get new upstream from the list
* @param ups upstream list
* @param type type of rotation algorithm, for `RSPAMD_UPSTREAM_HASHED` it is required to specify `key` and `keylen` as arguments
* @return
*/
struct upstream* rspamd_upstream_get (struct upstream_list *ups,
enum rspamd_upstream_rotation type, ...);
#endif /* UPSTREAM_H */
/*
* vi:ts=4
*/
|