r13111: w2k3 uses the naxVersion id for calculating the notification,
[sfrench/samba-autobuild/.git] / source4 / wrepl_server / wrepl_server.h
1 /* 
2    Unix SMB/CIFS implementation.
3    
4    WINS Replication server
5    
6    Copyright (C) Stefan Metzmacher      2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 struct wreplsrv_service;
24 struct wreplsrv_in_connection;
25 struct wreplsrv_out_connection;
26 struct wreplsrv_partner;
27
28 #define WREPLSRV_VALID_ASSOC_CTX        0x12345678
29 #define WREPLSRV_INVALID_ASSOC_CTX      0x0000000a
30
31 /*
32   state of an incoming wrepl call
33 */
34 struct wreplsrv_in_call {
35         struct wreplsrv_in_connection *wreplconn;
36         struct wrepl_packet req_packet;
37         struct wrepl_packet rep_packet;
38         BOOL terminate_after_send;
39 };
40
41 /*
42   state of an incoming wrepl connection
43 */
44 struct wreplsrv_in_connection {
45         struct wreplsrv_in_connection *prev,*next;
46         struct stream_connection *conn;
47         struct packet_context *packet;
48
49         /* our global service context */
50         struct wreplsrv_service *service;
51
52         /*
53          * the partner that connects us,
54          * can be NULL, when we got a connection
55          * from an unknown address
56          */
57         struct wreplsrv_partner *partner;
58
59         /* keep track of the assoc_ctx's */
60         struct {
61                 BOOL stopped;
62                 uint32_t our_ctx;
63                 uint32_t peer_ctx;
64         } assoc_ctx;
65 };
66
67 /*
68   state of an outcoming wrepl connection
69 */
70 struct wreplsrv_out_connection {
71         /* our global service context */
72         struct wreplsrv_service *service;
73
74         /*
75          * the partner that connects us,
76          * can be NULL, when we got a connection
77          * from an unknown address
78          */
79         struct wreplsrv_partner *partner;
80
81         /* keep track of the assoc_ctx's */
82         struct {
83                 uint32_t our_ctx;
84                 uint32_t peer_ctx;
85         } assoc_ctx;
86
87         /* 
88          * the client socket to the partner,
89          * NULL if not yet connected
90          */
91         struct wrepl_socket *sock;
92 };
93
94 enum winsrepl_partner_type {
95         WINSREPL_PARTNER_NONE = 0x0,
96         WINSREPL_PARTNER_PULL = 0x1,
97         WINSREPL_PARTNER_PUSH = 0x2,
98         WINSREPL_PARTNER_BOTH = (WINSREPL_PARTNER_PULL | WINSREPL_PARTNER_PUSH)
99 };
100
101 #define WINSREPL_DEFAULT_PULL_INTERVAL (30*60)
102 #define WINSREPL_DEFAULT_PULL_RETRY_INTERVAL (30)
103
104 #define WINSREPL_DEFAULT_PUSH_CHANGE_COUNT (0)
105
106 /*
107  this represents one of our configured partners
108 */
109 struct wreplsrv_partner {
110         struct wreplsrv_partner *prev,*next;
111
112         /* our global service context */
113         struct wreplsrv_service *service;
114
115         /* the netbios name of the partner, mostly just for debugging */
116         const char *name;
117
118         /* the ip-address of the partner */
119         const char *address;
120
121         /* 
122          * as wins partners identified by ip-address, we need to use a specific source-ip
123          *  when we want to connect to the partner
124          */
125         const char *our_address;
126
127         /* the type of the partner, pull, push or both */
128         enum winsrepl_partner_type type;
129
130         /* pull specific options */
131         struct {
132                 /* the interval between 2 pull replications to the partner */
133                 uint32_t interval;
134
135                 /* the retry_interval if a pull cycle failed to the partner */
136                 uint32_t retry_interval;
137
138                 /* the error count till the last success */
139                 uint32_t error_count;
140
141                 /* the status of the last pull cycle */
142                 NTSTATUS last_status;
143
144                 /* the timestamp of the next pull try */
145                 struct timeval next_run;
146
147                 /* this is a list of each wins_owner the partner knows about */
148                 struct wreplsrv_owner *table;
149
150                 /* the outgoing connection to the partner */
151                 struct wreplsrv_out_connection *wreplconn;
152
153                 /* the current pending pull cycle request */
154                 struct composite_context *creq;
155
156                 /* the pull cycle io params */
157                 struct wreplsrv_pull_cycle_io *cycle_io;
158
159                 /* the current timed_event to the next pull cycle */
160                 struct timed_event *te;
161         } pull;
162
163         /* push specific options */
164         struct {
165                 /* change count till push notification */
166                 uint32_t change_count;
167
168                 /* the last wins db maxVersion have reported to the partner */
169                 uint64_t maxVersionID;
170
171                 /* we should use WREPL_REPL_INFORM* messages to this partner */
172                 BOOL use_inform;
173
174                 /* the error count till the last success */
175                 uint32_t error_count;
176
177                 /* the status of the last push cycle */
178                 NTSTATUS last_status;
179
180                 /* the outgoing connection to the partner */
181                 struct wreplsrv_out_connection *wreplconn;
182
183                 /* the current push notification */
184                 struct composite_context *creq;
185
186                 /* the pull cycle io params */
187                 struct wreplsrv_push_notify_io *notify_io;
188         } push;
189 };
190
191 struct wreplsrv_owner {
192         struct wreplsrv_owner *prev,*next;
193
194         /* this hold the owner_id (address), min_version, max_version and partner_type */
195         struct wrepl_wins_owner owner;
196
197         /* can be NULL if this owner isn't a configure partner */
198         struct wreplsrv_partner *partner; 
199 };
200
201 /*
202   state of the whole wrepl service
203 */
204 struct wreplsrv_service {
205         /* the whole wrepl service is in one task */
206         struct task_server *task;
207
208         /* the time the service was started */
209         struct timeval startup_time;
210
211         /* the winsdb handle */
212         struct winsdb_handle *wins_db;
213
214         /* some configuration */
215         struct {
216                 /* the wins config db handle */
217                 struct ldb_context *ldb;
218
219                 /* the last wins config db seqnumber we know about */
220                 uint64_t seqnumber;
221
222                 /* 
223                  * the interval (in secs) till an active record will be marked as RELEASED 
224                  */
225                 uint32_t renew_interval;
226
227                 /* 
228                  * the interval (in secs) a record remains in RELEASED state,
229                  * before it will be marked as TOMBSTONE
230                  * (also known as extinction interval)
231                  */
232                 uint32_t tombstone_interval;
233
234                 /* 
235                  * the interval (in secs) a record remains in TOMBSTONE state,
236                  * before it will be removed from the database.
237                  * See also 'tombstone_extra_timeout'.
238                  * (also known as extinction timeout)
239                  */
240                 uint32_t tombstone_timeout;
241
242                 /* 
243                  * the interval (in secs) a record remains in TOMBSTONE state,
244                  * even after 'tombstone_timeout' passes the current timestamp.
245                  * this is the minimum uptime of the wrepl service, before
246                  * we start delete tombstones. This is to prevent deletion of
247                  * tombstones, without replacte them.
248                  */
249                 uint32_t tombstone_extra_timeout;
250
251                 /* 
252                  * the interval (in secs) till a replica record will be verified
253                  * with the owning wins server
254                  */
255                 uint32_t verify_interval;
256
257                 /* 
258                  * the interval (in secs) till a do a database cleanup
259                  */
260                 uint32_t scavenging_interval;
261
262                 /* 
263                  * the interval (in secs) to the next periodic processing
264                  * (this is the maximun interval)
265                  */
266                 uint32_t periodic_interval;
267         } config;
268
269         /* all incoming connections */
270         struct wreplsrv_in_connection *in_connections;
271
272         /* all partners (pull and push) */
273         struct wreplsrv_partner *partners;
274
275         /*
276          * this is our local wins_owner entry, this is also in the table list
277          * but we need a pointer to it, because we need to update it on each 
278          * query to wreplsrv_find_owner(), as the local records can be added
279          * to the wins.ldb from external tools and the winsserver
280          */
281         struct wreplsrv_owner *owner;
282
283         /* this is a list of each wins_owner we know about in our database */
284         struct wreplsrv_owner *table;
285
286         /* some stuff for periodic processing */
287         struct {
288                 /*
289                  * the timestamp for the next event,
290                  * this is the timstamp passed to event_add_timed()
291                  */
292                 struct timeval next_event;
293
294                 /* here we have a reference to the timed event the schedules the periodic stuff */
295                 struct timed_event *te;
296         } periodic;
297
298         /* some stuff for scavenging processing */
299         struct {
300                 /*
301                  * the timestamp for the next scavenging run,
302                  * this is the timstamp passed to event_add_timed()
303                  */
304                 struct timeval next_run;
305
306                 /*
307                  * are we currently inside a scavenging run
308                  */
309                 BOOL processing;        
310         } scavenging;
311 };
312
313 #include "wrepl_server/wrepl_out_helpers.h"
314 #include "wrepl_server/wrepl_server_proto.h"