r11547: - don't do pull replication when pullIntervall is 0
[kai/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 };
39
40 /*
41   state of an incoming wrepl connection
42 */
43 struct wreplsrv_in_connection {
44         struct wreplsrv_in_connection *prev,*next;
45         struct stream_connection *conn;
46
47         /* our global service context */
48         struct wreplsrv_service *service;
49
50         /*
51          * the partner that connects us,
52          * can be NULL, when we got a connection
53          * from an unknown address
54          */
55         struct wreplsrv_partner *partner;
56
57         /*
58          * we need to take care of our own ip address,
59          * as this is the WINS-Owner ID the peer expect
60          * from us.
61          */
62         const char *our_ip;
63
64         /* keep track of the assoc_ctx's */
65         struct {
66                 BOOL stopped;
67                 uint32_t our_ctx;
68                 uint32_t peer_ctx;
69         } assoc_ctx;
70
71         /* the partial input on the connection */
72         DATA_BLOB partial;
73         size_t partial_read;
74
75         /*
76          * are we currently processing a request?
77          * this prevents loops, with half async code
78          */
79         BOOL processing;
80
81         /*
82          * if this is set we no longer accept incoming packets
83          * and terminate the connection after we have send all packets
84          */
85         BOOL terminate;
86
87         /* the list of outgoing DATA_BLOB's that needs to be send */
88         struct data_blob_list_item *send_queue;
89 };
90
91 /*
92   state of an outcoming wrepl connection
93 */
94 struct wreplsrv_out_connection {
95         /* our global service context */
96         struct wreplsrv_service *service;
97
98         /*
99          * the partner that connects us,
100          * can be NULL, when we got a connection
101          * from an unknown address
102          */
103         struct wreplsrv_partner *partner;
104
105         /* keep track of the assoc_ctx's */
106         struct {
107                 uint32_t our_ctx;
108                 uint32_t peer_ctx;
109         } assoc_ctx;
110
111         /* 
112          * the client socket to the partner,
113          * NULL if not yet connected
114          */
115         struct wrepl_socket *sock;
116 };
117
118 enum winsrepl_partner_type {
119         WINSREPL_PARTNER_NONE = 0x0,
120         WINSREPL_PARTNER_PULL = 0x1,
121         WINSREPL_PARTNER_PUSH = 0x2,
122         WINSREPL_PARTNER_BOTH = (WINSREPL_PARTNER_PULL | WINSREPL_PARTNER_PUSH)
123 };
124
125 #define WINSREPL_DEFAULT_PULL_INTERVAL (30*60)
126 #define WINSREPL_DEFAULT_PULL_RETRY_INTERVAL (30)
127
128 #define WINSREPL_DEFAULT_PUSH_CHANGE_COUNT (0)
129
130 /*
131  this represents one of our configured partners
132 */
133 struct wreplsrv_partner {
134         struct wreplsrv_partner *prev,*next;
135
136         /* our global service context */
137         struct wreplsrv_service *service;
138
139         /* the netbios name of the partner, mostly just for debugging */
140         const char *name;
141
142         /* the ip-address of the partner */
143         const char *address;
144
145         /* 
146          * as wins partners identified by ip-address, we need to use a specific source-ip
147          *  when we want to connect to the partner
148          */
149         const char *our_address;
150
151         /* the type of the partner, pull, push or both */
152         enum winsrepl_partner_type type;
153
154         /* pull specific options */
155         struct {
156                 /* the interval between 2 pull replications to the partner */
157                 uint32_t interval;
158
159                 /* the retry_interval if a pull cycle failed to the partner */
160                 uint32_t retry_interval;
161
162                 /* the error count till the last success */
163                 uint32_t error_count;
164
165                 /* the status of the last pull cycle */
166                 NTSTATUS last_status;
167
168                 /* this is a list of each wins_owner the partner knows about */
169                 struct wreplsrv_owner *table;
170
171                 /* the outgoing connection to the partner */
172                 struct wreplsrv_out_connection *wreplconn;
173
174                 /* the current pending pull cycle request */
175                 struct composite_context *creq;
176
177                 /* the pull cycle io params */
178                 struct wreplsrv_pull_cycle_io *cycle_io;
179
180                 /* the current timed_event to the next pull cycle */
181                 struct timed_event *te;
182         } pull;
183
184         /* push specific options */
185         struct {
186                 /* change count till push notification */
187                 uint32_t change_count;
188
189                 /* the status of the last push cycle */
190                 NTSTATUS last_status;
191
192                 /* the outgoing connection to the partner */
193                 struct wreplsrv_out_connection *wreplconn;
194
195                 /* the current push notification */
196                 struct composite_context *creq;
197
198                 /* the pull cycle io params */
199                 struct wreplsrv_push_notify_io *notify_io;
200
201                 /* the current timed_event to the next push notify */
202                 struct timed_event *te;
203         } push;
204 };
205
206 struct wreplsrv_owner {
207         struct wreplsrv_owner *prev,*next;
208
209         /* this hold the owner_id (address), min_version, max_version and partner_type */
210         struct wrepl_wins_owner owner;
211
212         /* can be NULL if this owner isn't a configure partner */
213         struct wreplsrv_partner *partner; 
214 };
215
216 /*
217   state of the whole wrepl service
218 */
219 struct wreplsrv_service {
220         /* the whole wrepl service is in one task */
221         struct task_server *task;
222
223         /* the winsdb handle */
224         struct ldb_context *wins_db;
225
226         /* all incoming connections */
227         struct wreplsrv_in_connection *in_connections;
228
229         /* all partners (pull and push) */
230         struct wreplsrv_partner *partners;
231
232         /* this is a list of each wins_owner we know about in our database */
233         struct wreplsrv_owner *table;
234 };