5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 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
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
32 /* Adds the `backup_server' to be one of our backup router. This can be
33 called multiple times to set multiple backup routers. If `local' is
34 TRUE then the `backup_server' is in the local cell, if FALSE it is
35 in some other cell. */
36 void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server,
39 /* Returns the first backup router context. Returns NULL if we do not have
40 any backup servers. This removes the returned server from being
41 backup router and needs to be added later with silc_server_backup_add
42 if it needs to be backup router again. */
43 SilcServerEntry silc_server_backup_get(SilcServer server);
45 /* Deletes the backup server `server_entry. */
46 void silc_server_backup_del(SilcServer server,
47 SilcServerEntry server_entry);
49 /* Marks the IP address and port from the `server_id' as being replaced
50 by backup router indicated by the `server'. If the router connects at
51 a later time we can check whether it has been replaced by an backup
53 void silc_server_backup_replaced_add(SilcServer server,
54 SilcServerID *server_id,
55 SilcServerEntry server_entry);
57 /* Checks whether the IP address and port from the `server_id' has been
58 replaced by an backup router. If it has been then this returns TRUE
59 and the bacup router entry to the `server' pointer if non-NULL. Returns
60 FALSE if the router is not replaced by backup router. */
61 bool silc_server_backup_replaced_get(SilcServer server,
62 SilcServerID *server_id,
63 SilcServerEntry *server_entry);
65 /* Deletes a replaced host by the set `server_entry. */
66 void silc_server_backup_replaced_del(SilcServer server,
67 SilcServerEntry server_entry);
69 /* Broadcast the received packet indicated by `packet' to all of our backup
70 routers. All router wide information is passed using broadcast packets.
71 That is why all backup routers need to get this data too. It is expected
72 that the caller already knows that the `packet' is broadcast packet. */
73 void silc_server_backup_broadcast(SilcServer server,
74 SilcSocketConnection sender,
75 SilcPacketContext *packet);
77 /* A generic routine to send data to all backup routers. If the `sender'
78 is provided it will indicate the original sender of the packet and the
79 packet won't be resent to that entity. The `data' is the data that will
80 be assembled to packet context before sending. The packet will be
81 encrypted this function. If the `force_send' is TRUE the data is sent
82 immediately and not put to queue. If `local' is TRUE then the packet
83 will be sent only to local backup routers inside the cell. If false the
84 packet can go from one cell to the other. This function has no effect
85 if there are no any backup routers. */
86 void silc_server_backup_send(SilcServer server,
87 SilcServerEntry sender,
89 SilcPacketFlags flags,
95 /* Same as silc_server_backup_send but sets a specific Destination ID to
96 the packet. The Destination ID is indicated by the `dst_id' and the
97 ID type `dst_id_type'. For example, packets destined to channels must
98 be sent using this function. */
99 void silc_server_backup_send_dest(SilcServer server,
100 SilcServerEntry sender,
102 SilcPacketFlags flags,
104 SilcIdType dst_id_type,
110 /* Processes incoming RESUME_ROUTER packet. This can give the packet
111 for processing to the protocol handler or allocate new protocol if
112 start command is received. */
113 void silc_server_backup_resume_router(SilcServer server,
114 SilcSocketConnection sock,
115 SilcPacketContext *packet);
117 /* Constantly tries to reconnect to a primary router indicated by the
118 `ip' and `port'. The `connected' callback will be called when the
119 connection is created. */
120 void silc_server_backup_reconnect(SilcServer server,
121 const char *ip, uint16 port,
122 SilcServerConnectRouterCallback callback,
125 /* Called when we've established connection back to our primary router
126 when we've acting as backup router and have replaced the primary router
127 in the cell. This function will start the backup resuming protocol. */
128 void silc_server_backup_connected(SilcServer server,
129 SilcServerEntry server_entry,
132 /* Backup resuming protocol. This protocol is executed when the primary
133 router wants to resume its position as being primary router. */
134 SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup);
136 #endif /* SERVER_BACKUP_H */