Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 1 | /* |
| 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 Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 30 | #include <common/config.h> |
| 31 | #include <common/mini-clist.h> |
| 32 | #include <common/regex.h> |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 33 | #include <common/tools.h> |
| 34 | #include <eb32tree.h> |
| 35 | |
Frédéric Lécaille | 74167b2 | 2019-05-28 19:02:42 +0200 | [diff] [blame] | 36 | #include <types/dict.h> |
| 37 | |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 38 | struct shared_table { |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 39 | struct stktable *table; /* stick table to sync */ |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 40 | 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écaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 49 | struct shared_table *next; /* next shared table in list */ |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct peer { |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 53 | int local; /* proxy state */ |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 54 | char *id; |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 55 | struct { |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 56 | const char *file; /* file where the section appears */ |
| 57 | int line; /* line where the section appears */ |
| 58 | } conf; /* config information */ |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 59 | time_t last_change; |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 60 | 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 Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 65 | unsigned int statuscode; /* current/last session status code */ |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 66 | unsigned int reconnect; /* next connect timer */ |
| 67 | unsigned int heartbeat; /* next heartbeat timer */ |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 68 | unsigned int confirm; /* confirm message counter */ |
Frédéric Lécaille | 33cab3c | 2019-11-06 11:51:26 +0100 | [diff] [blame^] | 69 | uint32_t rx_hbt; /* received heartbeats counter */ |
| 70 | uint32_t tx_hbt; /* transmitted heartbeats counter */ |
Emeric Brun | b3971ab | 2015-05-12 18:49:09 +0200 | [diff] [blame] | 71 | struct appctx *appctx; /* the appctx running it */ |
| 72 | struct shared_table *remote_table; |
| 73 | struct shared_table *last_local_table; |
| 74 | struct shared_table *tables; |
Frédéric Lécaille | 1055e68 | 2018-04-26 14:35:21 +0200 | [diff] [blame] | 75 | struct server *srv; |
Frédéric Lécaille | 8d78fa7 | 2019-05-20 18:22:52 +0200 | [diff] [blame] | 76 | struct dcache *dcache; /* dictionary cache */ |
Christopher Faulet | 9dcf9b6 | 2017-11-13 10:34:01 +0100 | [diff] [blame] | 77 | __decl_hathreads(HA_SPINLOCK_T lock); /* lock used to handle this peer section */ |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 78 | struct peer *next; /* next peer in the list */ |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | |
| 82 | struct peers { |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 83 | int state; /* proxy state */ |
| 84 | char *id; /* peer section name */ |
| 85 | struct task *sync_task; /* main sync task */ |
| 86 | struct sig_handler *sighandler; /* signal handler */ |
| 87 | struct peer *remote; /* remote peers list */ |
| 88 | struct peer *local; /* local peer list */ |
| 89 | struct proxy *peers_fe; /* peer frontend */ |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 90 | struct { |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 91 | const char *file; /* file where the section appears */ |
| 92 | int line; /* line where the section appears */ |
| 93 | } conf; /* config information */ |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 94 | time_t last_change; |
Frédéric Lécaille | 1673bbd | 2019-05-15 10:49:13 +0200 | [diff] [blame] | 95 | struct peers *next; /* next peer section */ |
| 96 | unsigned int flags; /* current peers section resync state */ |
| 97 | unsigned int resync_timeout; /* resync timeout timer */ |
| 98 | int count; /* total of peers */ |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 99 | }; |
| 100 | |
Frédéric Lécaille | 74167b2 | 2019-05-28 19:02:42 +0200 | [diff] [blame] | 101 | /* LRU cache for dictionaies */ |
| 102 | struct dcache_tx { |
| 103 | /* The last recently used key */ |
| 104 | unsigned int lru_key; |
Frédéric Lécaille | 6c39198 | 2019-06-06 11:34:03 +0200 | [diff] [blame] | 105 | /* An array of entries to store pointers to dictionary entries. */ |
| 106 | struct ebpt_node *entries; |
Frédéric Lécaille | b65717f | 2019-06-07 14:25:25 +0200 | [diff] [blame] | 107 | /* The previous lookup result. */ |
| 108 | struct ebpt_node *prev_lookup; |
Frédéric Lécaille | 6c39198 | 2019-06-06 11:34:03 +0200 | [diff] [blame] | 109 | /* ebtree to store the previous entries. */ |
| 110 | struct eb_root cached_entries; |
Frédéric Lécaille | 74167b2 | 2019-05-28 19:02:42 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | struct dcache_rx { |
| 114 | unsigned int id; |
| 115 | struct dict_entry *de; |
| 116 | }; |
| 117 | |
| 118 | struct dcache_tx_entry { |
Frédéric Lécaille | 6c39198 | 2019-06-06 11:34:03 +0200 | [diff] [blame] | 119 | unsigned int id; |
| 120 | struct ebpt_node entry; |
Frédéric Lécaille | 74167b2 | 2019-05-28 19:02:42 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /* stick-table data type cache */ |
| 124 | struct dcache { |
| 125 | /* Cache used upon transmission */ |
| 126 | struct dcache_tx *tx; |
| 127 | /* Cache used upon receipt */ |
| 128 | struct dcache_rx *rx; |
| 129 | /* Maximum number of entries in this cache */ |
| 130 | size_t max_entries; |
| 131 | }; |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 132 | |
Frédéric Lécaille | ed2b4a6 | 2017-07-13 09:07:09 +0200 | [diff] [blame] | 133 | extern struct peers *cfg_peers; |
Emeric Brun | 2b920a1 | 2010-09-23 18:30:22 +0200 | [diff] [blame] | 134 | |
| 135 | #endif /* _TYPES_PEERS_H */ |
| 136 | |