5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 2000 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; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 * Route cache routines. Server uses these to route packets to specific
22 * routes. If route entry doesn't exist for a specific destination, server
23 * uses primary route (default route).
28 * Revision 1.3 2000/07/05 06:14:01 priikone
29 * Global costemic changes.
31 * Revision 1.2 2000/07/04 08:30:24 priikone
32 * Added silc_server_get_route to return communication object
35 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
36 * Imported from internal CVS/Added Log headers.
41 #include "serverincludes.h"
42 #include "server_internal.h"
45 /* Route cache hash table */
46 SilcServerRouteTable silc_route_cache[SILC_SERVER_ROUTE_SIZE];
48 /* Adds new route to the route cache. The argument `index' is the
49 index value generated by silc_server_route_hash. */
51 void silc_server_route_add(unsigned int index, unsigned int dest,
52 SilcServerList *router)
54 silc_route_cache[index].dest = dest;
55 silc_route_cache[index].router = router;
58 /* Checksk whether destination has a specific router. Returns the
59 router data if found, NULL otherwise. */
61 SilcServerList *silc_server_route_check(unsigned int dest,
66 index = silc_server_route_hash(dest, port);
68 if (silc_route_cache[index].router != NULL &&
69 silc_route_cache[index].dest == dest)
70 return silc_route_cache[index].router;
75 /* Returns the connection object for the fastest route for the given ID.
76 If we are normal server then this just returns our primary route. If
77 we are router we will do route lookup. */
79 SilcSocketConnection silc_server_get_route(SilcServer server, void *id,
82 unsigned int dest = 0;
83 unsigned short port = 0;
84 SilcServerList *router = NULL;
86 if (server->server_type == SILC_SERVER)
87 return (SilcSocketConnection)server->id_entry->router->connection;
91 dest = ((SilcClientID *)id)->ip.s_addr;
92 port = server->id->port;
95 dest = ((SilcServerID *)id)->ip.s_addr;
96 port = ((SilcServerID *)id)->port;
99 dest = ((SilcChannelID *)id)->ip.s_addr;
100 port = ((SilcChannelID *)id)->port;
106 router = silc_server_route_check(dest, port);
108 return (SilcSocketConnection)server->id_entry->router->connection;
110 return (SilcSocketConnection)router->connection;