Merge branch 'master' of ssh://jra@git.samba.org/data/git/samba
[kai/samba.git] / source4 / wrepl_server / wrepl_server.h
index 7025bff49679be35a41be284e4ac1803cbb89fdc..a001c6b3ae5258f964c026a367fdc4a66d30f2a5 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 struct wreplsrv_service;
@@ -35,6 +34,7 @@ struct wreplsrv_in_call {
        struct wreplsrv_in_connection *wreplconn;
        struct wrepl_packet req_packet;
        struct wrepl_packet rep_packet;
+       bool terminate_after_send;
 };
 
 /*
@@ -43,6 +43,7 @@ struct wreplsrv_in_call {
 struct wreplsrv_in_connection {
        struct wreplsrv_in_connection *prev,*next;
        struct stream_connection *conn;
+       struct packet_context *packet;
 
        /* our global service context */
        struct wreplsrv_service *service;
@@ -54,51 +55,23 @@ struct wreplsrv_in_connection {
         */
        struct wreplsrv_partner *partner;
 
-       /*
-        * we need to take care of our own ip address,
-        * as this is the WINS-Owner ID the peer expect
-        * from us.
-        */
-       const char *our_ip;
-
        /* keep track of the assoc_ctx's */
        struct {
-               BOOL stopped;
+               bool stopped;
                uint32_t our_ctx;
                uint32_t peer_ctx;
        } assoc_ctx;
-
-       /* the partial input on the connection */
-       DATA_BLOB partial;
-       size_t partial_read;
-
-       /*
-        * are we currently processing a request?
-        * this prevents loops, with half async code
-        */
-       BOOL processing;
-
-       /*
-        * if this is set we no longer accept incoming packets
-        * and terminate the connection after we have send all packets
-        */
-       BOOL terminate;
-
-       /* the list of outgoing DATA_BLOB's that needs to be send */
-       struct data_blob_list_item *send_queue;
 };
 
 /*
-  state of an outcoming wrepl connection
+  state of an outgoing wrepl connection
 */
 struct wreplsrv_out_connection {
        /* our global service context */
        struct wreplsrv_service *service;
 
        /*
-        * the partner that connects us,
-        * can be NULL, when we got a connection
-        * from an unknown address
+        * the partner we connect
         */
        struct wreplsrv_partner *partner;
 
@@ -165,6 +138,9 @@ struct wreplsrv_partner {
                /* the status of the last pull cycle */
                NTSTATUS last_status;
 
+               /* the timestamp of the next pull try */
+               struct timeval next_run;
+
                /* this is a list of each wins_owner the partner knows about */
                struct wreplsrv_owner *table;
 
@@ -186,6 +162,15 @@ struct wreplsrv_partner {
                /* change count till push notification */
                uint32_t change_count;
 
+               /* the last wins db maxVersion have reported to the partner */
+               uint64_t maxVersionID;
+
+               /* we should use WREPL_REPL_INFORM* messages to this partner */
+               bool use_inform;
+
+               /* the error count till the last success */
+               uint32_t error_count;
+
                /* the status of the last push cycle */
                NTSTATUS last_status;
 
@@ -197,9 +182,6 @@ struct wreplsrv_partner {
 
                /* the pull cycle io params */
                struct wreplsrv_push_notify_io *notify_io;
-
-               /* the current timed_event to the next push notify */
-               struct timed_event *te;
        } push;
 };
 
@@ -220,11 +202,20 @@ struct wreplsrv_service {
        /* the whole wrepl service is in one task */
        struct task_server *task;
 
+       /* the time the service was started */
+       struct timeval startup_time;
+
        /* the winsdb handle */
-       struct ldb_context *wins_db;
+       struct winsdb_handle *wins_db;
 
        /* some configuration */
        struct {
+               /* the wins config db handle */
+               struct ldb_context *ldb;
+
+               /* the last wins config db seqnumber we know about */
+               uint64_t seqnumber;
+
                /* 
                 * the interval (in secs) till an active record will be marked as RELEASED 
                 */
@@ -240,15 +231,36 @@ struct wreplsrv_service {
                /* 
                 * the interval (in secs) a record remains in TOMBSTONE state,
                 * before it will be removed from the database.
+                * See also 'tombstone_extra_timeout'.
                 * (also known as extinction timeout)
                 */
                uint32_t tombstone_timeout;
 
+               /* 
+                * the interval (in secs) a record remains in TOMBSTONE state,
+                * even after 'tombstone_timeout' passes the current timestamp.
+                * this is the minimum uptime of the wrepl service, before
+                * we start delete tombstones. This is to prevent deletion of
+                * tombstones, without replacte them.
+                */
+               uint32_t tombstone_extra_timeout;
+
                /* 
                 * the interval (in secs) till a replica record will be verified
                 * with the owning wins server
                 */
                uint32_t verify_interval;
+
+               /* 
+                * the interval (in secs) till a do a database cleanup
+                */
+               uint32_t scavenging_interval;
+
+               /* 
+                * the interval (in secs) to the next periodic processing
+                * (this is the maximun interval)
+                */
+               uint32_t periodic_interval;
        } config;
 
        /* all incoming connections */
@@ -257,6 +269,45 @@ struct wreplsrv_service {
        /* all partners (pull and push) */
        struct wreplsrv_partner *partners;
 
+       /*
+        * this is our local wins_owner entry, this is also in the table list
+        * but we need a pointer to it, because we need to update it on each 
+        * query to wreplsrv_find_owner(), as the local records can be added
+        * to the wins.ldb from external tools and the winsserver
+        */
+       struct wreplsrv_owner *owner;
+
        /* this is a list of each wins_owner we know about in our database */
        struct wreplsrv_owner *table;
+
+       /* some stuff for periodic processing */
+       struct {
+               /*
+                * the timestamp for the next event,
+                * this is the timstamp passed to event_add_timed()
+                */
+               struct timeval next_event;
+
+               /* here we have a reference to the timed event the schedules the periodic stuff */
+               struct timed_event *te;
+       } periodic;
+
+       /* some stuff for scavenging processing */
+       struct {
+               /*
+                * the timestamp for the next scavenging run,
+                * this is the timstamp passed to event_add_timed()
+                */
+               struct timeval next_run;
+
+               /*
+                * are we currently inside a scavenging run
+                */
+               bool processing;        
+       } scavenging;
 };
+
+struct socket_context;
+struct wrepl_name;
+#include "wrepl_server/wrepl_out_helpers.h"
+#include "wrepl_server/wrepl_server_proto.h"