5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 - 2003, 2007 Pekka Riikonen
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.
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.
20 #ifndef SERVER_BACKUP_H
21 #define SERVER_BACKUP_H
23 /* Backup resuming protocol types */
24 #define SILC_SERVER_BACKUP_START 1 /* Start protocol */
25 #define SILC_SERVER_BACKUP_CONNECTED 2 /* Connected to primary */
26 #define SILC_SERVER_BACKUP_ENDING 3 /* Giving up as primary */
27 #define SILC_SERVER_BACKUP_RESUMED 4 /* Primary is back online */
28 #define SILC_SERVER_BACKUP_REPLACED 20 /* Primary has been replaced */
29 #define SILC_SERVER_BACKUP_START_USE 21 /* Start use backup as primary */
31 /* Adds the `backup_server' to be one of our backup router. This can be
32 called multiple times to set multiple backup routers. The `replacing' is
33 the IP and port that the `backup_router' will replace if the `replacing'
34 will become unresponsive. If `local' is TRUE then the `backup_server' is
35 in the local cell, if FALSE it is in some other cell. */
36 void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server,
37 const char *ip, int port, SilcBool local);
39 /* Returns backup router for IP and port in `server_id' or NULL if there
40 does not exist backup router. */
41 SilcServerEntry silc_server_backup_get(SilcServer server,
42 SilcServerID *server_id);
44 /* Deletes the backup server `server_entry'. */
45 void silc_server_backup_del(SilcServer server, SilcServerEntry server_entry);
47 /* Frees all data allocated for backup routers. Call this after deleting
48 all backup routers and when new routers are added no more, for example
49 when shutting down the server. */
50 void silc_server_backup_free(SilcServer server);
52 /* Marks the IP address and port from the `server_id' as being replaced
53 by backup router indicated by the `server'. If the router connects at
54 a later time we can check whether it has been replaced by an backup
56 void silc_server_backup_replaced_add(SilcServer server,
57 SilcServerID *server_id,
58 SilcServerEntry server_entry);
60 /* Checks whether the IP address and port from the `server_id' has been
61 replaced by an backup router. If it has been then this returns TRUE
62 and the bacup router entry to the `server' pointer if non-NULL. Returns
63 FALSE if the router is not replaced by backup router. */
64 SilcBool silc_server_backup_replaced_get(SilcServer server,
65 SilcServerID *server_id,
66 SilcServerEntry *server_entry);
68 /* Deletes a replaced host by the set `server_entry. */
69 void silc_server_backup_replaced_del(SilcServer server,
70 SilcServerEntry server_entry);
72 /* Broadcast the received packet indicated by `packet' to all of our backup
73 routers. All router wide information is passed using broadcast packets.
74 That is why all backup routers need to get this data too. It is expected
75 that the caller already knows that the `packet' is broadcast packet. */
76 void silc_server_backup_broadcast(SilcServer server,
77 SilcPacketStream sender,
80 /* A generic routine to send data to all backup routers. If the `sender'
81 is provided it will indicate the original sender of the packet and the
82 packet won't be resent to that entity. The `data' is the data that will
83 be assembled to packet context before sending. The packet will be
84 encrypted this function. If the `force_send' is TRUE the data is sent
85 immediately and not put to queue. If `local' is TRUE then the packet
86 will be sent only to local backup routers inside the cell. If false the
87 packet can go from one cell to the other. This function has no effect
88 if there are no any backup routers. */
89 void silc_server_backup_send(SilcServer server,
90 SilcServerEntry sender,
92 SilcPacketFlags flags,
98 /* Same as silc_server_backup_send but sets a specific Destination ID to
99 the packet. The Destination ID is indicated by the `dst_id' and the
100 ID type `dst_id_type'. For example, packets destined to channels must
101 be sent using this function. */
102 void silc_server_backup_send_dest(SilcServer server,
103 SilcServerEntry sender,
105 SilcPacketFlags flags,
107 SilcIdType dst_id_type,
113 /* Send the START_USE indication to remote connection. If `failure' is
114 TRUE then this sends SILC_PACKET_FAILURE. Otherwise it sends
115 SILC_PACKET_RESUME_ROUTER. */
116 void silc_server_backup_send_start_use(SilcServer server,
117 SilcPacketStream sock,
120 /* Send the REPLACED indication to remote router. This is send by the
121 primary router (remote router) of the primary router that came back
122 online. This is not sent by backup router or any other server. */
123 void silc_server_backup_send_replaced(SilcServer server,
124 SilcPacketStream sock);
126 /* Processes incoming RESUME_ROUTER packet. This can give the packet
127 for processing to the protocol handler or allocate new protocol if
128 start command is received. */
129 void silc_server_backup_resume_router(SilcServer server,
130 SilcPacketStream sock,
133 /* Called when we've established connection back to our primary router
134 when we've acting as backup router and have replaced the primary router
135 in the cell. This function will start the backup resuming protocol. */
136 void silc_server_backup_connected(SilcServer server,
137 SilcServerEntry server_entry,
140 /* Backup resuming protocol. This protocol is executed when the primary
141 router wants to resume its position as being primary router. */
142 SILC_TASK_CALLBACK(silc_server_protocol_backup);
144 #endif /* SERVER_BACKUP_H */