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