blob: 0139edc0518cd6c863ff92d9f1fb14762c1b1312 [file] [log] [blame]
Emeric Brun2b920a12010-09-23 18:30:22 +02001/*
2 * include/types/peers.h
3 * This file defines everything related to peers.
4 *
5 * Copyright 2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _TYPES_PEERS_H
23#define _TYPES_PEERS_H
24
25#include <sys/types.h>
26#include <sys/socket.h>
27#include <netinet/in.h>
28#include <arpa/inet.h>
29
Emeric Brun2b920a12010-09-23 18:30:22 +020030#include <common/config.h>
31#include <common/mini-clist.h>
32#include <common/regex.h>
Emeric Brun2b920a12010-09-23 18:30:22 +020033#include <common/tools.h>
34#include <eb32tree.h>
35
Frédéric Lécaille74167b22019-05-28 19:02:42 +020036#include <types/dict.h>
37
Emeric Brun2b920a12010-09-23 18:30:22 +020038struct shared_table {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020039 struct stktable *table; /* stick table to sync */
Emeric Brunb3971ab2015-05-12 18:49:09 +020040 int local_id;
41 int remote_id;
42 int flags;
43 uint64_t remote_data;
44 unsigned int last_acked;
45 unsigned int last_pushed;
46 unsigned int last_get;
47 unsigned int teaching_origin;
48 unsigned int update;
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020049 struct shared_table *next; /* next shared table in list */
Emeric Brun2b920a12010-09-23 18:30:22 +020050};
51
52struct peer {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020053 int local; /* proxy state */
Emeric Brun2b920a12010-09-23 18:30:22 +020054 char *id;
Emeric Brun2b920a12010-09-23 18:30:22 +020055 struct {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020056 const char *file; /* file where the section appears */
57 int line; /* line where the section appears */
58 } conf; /* config information */
Emeric Brun2b920a12010-09-23 18:30:22 +020059 time_t last_change;
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020060 struct sockaddr_storage addr; /* peer address */
61 struct protocol *proto; /* peer address protocol */
62 struct xprt_ops *xprt; /* peer socket operations at transport layer */
63 void *sock_init_arg; /* socket operations's opaque init argument if needed */
64 unsigned int flags; /* peer session flags */
Emeric Brunb3971ab2015-05-12 18:49:09 +020065 unsigned int statuscode; /* current/last session status code */
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020066 unsigned int reconnect; /* next connect timer */
67 unsigned int heartbeat; /* next heartbeat timer */
Emeric Brunb3971ab2015-05-12 18:49:09 +020068 unsigned int confirm; /* confirm message counter */
Emeric Brunb3971ab2015-05-12 18:49:09 +020069 struct appctx *appctx; /* the appctx running it */
70 struct shared_table *remote_table;
71 struct shared_table *last_local_table;
72 struct shared_table *tables;
Frédéric Lécaille1055e682018-04-26 14:35:21 +020073 struct server *srv;
Christopher Faulet9dcf9b62017-11-13 10:34:01 +010074 __decl_hathreads(HA_SPINLOCK_T lock); /* lock used to handle this peer section */
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020075 struct peer *next; /* next peer in the list */
Emeric Brun2b920a12010-09-23 18:30:22 +020076};
77
78
79struct peers {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020080 int state; /* proxy state */
81 char *id; /* peer section name */
82 struct task *sync_task; /* main sync task */
83 struct sig_handler *sighandler; /* signal handler */
84 struct peer *remote; /* remote peers list */
85 struct peer *local; /* local peer list */
86 struct proxy *peers_fe; /* peer frontend */
Emeric Brun2b920a12010-09-23 18:30:22 +020087 struct {
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020088 const char *file; /* file where the section appears */
89 int line; /* line where the section appears */
90 } conf; /* config information */
Emeric Brun2b920a12010-09-23 18:30:22 +020091 time_t last_change;
Frédéric Lécaille1673bbd2019-05-15 10:49:13 +020092 struct peers *next; /* next peer section */
93 unsigned int flags; /* current peers section resync state */
94 unsigned int resync_timeout; /* resync timeout timer */
95 int count; /* total of peers */
Emeric Brun2b920a12010-09-23 18:30:22 +020096};
97
Frédéric Lécaille74167b22019-05-28 19:02:42 +020098/* LRU cache for dictionaies */
99struct dcache_tx {
100 /* The last recently used key */
101 unsigned int lru_key;
102 /* The maximum number of entries in this cache */
103 size_t max_entries;
104 /* ebtree for keys (eb32_nodes from 0 included up to <max_entries> excluded) */
105 struct eb_root keys;
106 /* ebtree for values (ebpt_node, pointers to dict struct entries) */
107 struct eb_root values;
108};
109
110struct dcache_rx {
111 unsigned int id;
112 struct dict_entry *de;
113};
114
115struct dcache_tx_entry {
116 struct eb32_node key;
117 struct ebpt_node value;
118};
119
120/* stick-table data type cache */
121struct dcache {
122 /* Cache used upon transmission */
123 struct dcache_tx *tx;
124 /* Cache used upon receipt */
125 struct dcache_rx *rx;
126 /* Maximum number of entries in this cache */
127 size_t max_entries;
128};
Emeric Brun2b920a12010-09-23 18:30:22 +0200129
Frédéric Lécailleed2b4a62017-07-13 09:07:09 +0200130extern struct peers *cfg_peers;
Emeric Brun2b920a12010-09-23 18:30:22 +0200131
132#endif /* _TYPES_PEERS_H */
133