Integer type name change.
[silc.git] / apps / silcd / server_backup.h
1 /*
2
3   server_backup.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
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 */
19
20 #ifndef SERVER_BACKUP_H
21 #define SERVER_BACKUP_H
22
23 /* Backup resuming protocol types */
24 #define SILC_SERVER_BACKUP_START            1
25 #define SILC_SERVER_BACKUP_START_GLOBAL     2
26 #define SILC_SERVER_BACKUP_CONNECTED        3
27 #define SILC_SERVER_BACKUP_ENDING           4
28 #define SILC_SERVER_BACKUP_RESUMED          5
29 #define SILC_SERVER_BACKUP_RESUMED_GLOBAL   6
30 #define SILC_SERVER_BACKUP_REPLACED         20
31
32 /* Adds the `backup_server' to be one of our backup router. This can be
33    called multiple times to set multiple backup routers. The `replacing' is
34    the IP and port that the `backup_router' will replace if the `replacing'
35    will become unresponsive. If `local' is TRUE then the `backup_server' is
36    in the local cell, if FALSE it is in some other cell. */
37 void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server,
38                             const char *ip, int port, bool local);
39
40 /* Returns backup router for IP and port in `replacing' or NULL if there
41    does not exist backup router. */
42 SilcServerEntry silc_server_backup_get(SilcServer server, 
43                                        SilcServerID *server_id);
44
45 /* Deletes the backup server `server_entry'. */
46 void silc_server_backup_del(SilcServer server, SilcServerEntry server_entry);
47
48 /* Marks the IP address and port from the `server_id' as  being replaced
49    by backup router indicated by the `server'. If the router connects at
50    a later time we can check whether it has been replaced by an backup
51    router. */
52 void silc_server_backup_replaced_add(SilcServer server, 
53                                      SilcServerID *server_id,
54                                      SilcServerEntry server_entry);
55
56 /* Checks whether the IP address and port from the `server_id' has been
57    replaced by an backup router. If it has been then this returns TRUE
58    and the bacup router entry to the `server' pointer if non-NULL. Returns
59    FALSE if the router is not replaced by backup router. */
60 bool silc_server_backup_replaced_get(SilcServer server,
61                                      SilcServerID *server_id,
62                                      SilcServerEntry *server_entry);
63
64 /* Deletes a replaced host by the set `server_entry. */
65 void silc_server_backup_replaced_del(SilcServer server,
66                                      SilcServerEntry server_entry);
67
68 /* Broadcast the received packet indicated by `packet' to all of our backup 
69    routers. All router wide information is passed using broadcast packets. 
70    That is why all backup routers need to get this data too. It is expected
71    that the caller already knows that the `packet' is broadcast packet. */
72 void silc_server_backup_broadcast(SilcServer server, 
73                                   SilcSocketConnection sender,
74                                   SilcPacketContext *packet);
75
76 /* A generic routine to send data to all backup routers. If the `sender'
77    is provided it will indicate the original sender of the packet and the
78    packet won't be resent to that entity. The `data' is the data that will
79    be assembled to packet context before sending. The packet will be
80    encrypted this function. If the `force_send' is TRUE the data is sent
81    immediately and not put to queue. If `local' is TRUE then the packet
82    will be sent only to local backup routers inside the cell. If false the
83    packet can go from one cell to the other. This function has no effect
84    if there are no any backup routers. */
85 void silc_server_backup_send(SilcServer server,
86                              SilcServerEntry sender,
87                              SilcPacketType type,
88                              SilcPacketFlags flags,
89                              unsigned char *data,
90                              SilcUInt32 data_len,
91                              bool force_send,
92                              bool local);
93
94 /* Same as silc_server_backup_send but sets a specific Destination ID to
95    the packet. The Destination ID is indicated by the `dst_id' and the
96    ID type `dst_id_type'. For example, packets destined to channels must
97    be sent using this function. */
98 void silc_server_backup_send_dest(SilcServer server,
99                                   SilcServerEntry sender,
100                                   SilcPacketType type,
101                                   SilcPacketFlags flags,
102                                   void *dst_id,
103                                   SilcIdType dst_id_type,
104                                   unsigned char *data,
105                                   SilcUInt32 data_len,
106                                   bool force_send,
107                                   bool local);
108
109 /* Processes incoming RESUME_ROUTER packet. This can give the packet
110    for processing to the protocol handler or allocate new protocol if
111    start command is received. */
112 void silc_server_backup_resume_router(SilcServer server, 
113                                       SilcSocketConnection sock, 
114                                       SilcPacketContext *packet);
115
116 /* Constantly tries to reconnect to a primary router indicated by the
117    `ip' and `port'. The `connected' callback will be called when the
118    connection is created. */
119 void silc_server_backup_reconnect(SilcServer server,
120                                   const char *ip, SilcUInt16 port,
121                                   SilcServerConnectRouterCallback callback,
122                                   void *context);
123
124 /* Called when we've established connection back to our primary router
125    when we've acting as backup router and have replaced the primary router
126    in the cell. This function will start the backup resuming protocol. */
127 void silc_server_backup_connected(SilcServer server,
128                                   SilcServerEntry server_entry,
129                                   void *context);
130
131 /* Backup resuming protocol. This protocol is executed when the primary
132    router wants to resume its position as being primary router. */
133 SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup);
134
135 #endif /* SERVER_BACKUP_H */