Moved silc_client_ch[u]mode[_char] to client library from silc/.
[silc.git] / apps / silcd / route.c
index 43b60d380b639ce4de0f8cad10525a58d94eb641..5edd731512182d2c9a3a1a4d1d4bbf9f759b145d 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.4  2000/07/12 05:59:41  priikone
+ *     Major rewrite of ID Cache system. Support added for the new
+ *     ID cache system. Major rewrite of ID List stuff on server.  All
+ *     SilcXXXList's are now called SilcXXXEntry's and they are pointers
+ *     by default. A lot rewritten ID list functions.
+ *
+ * Revision 1.3  2000/07/05 06:14:01  priikone
+ *     Global costemic changes.
+ *
+ * Revision 1.2  2000/07/04 08:30:24  priikone
+ *     Added silc_server_get_route to return communication object
+ *     for fastest route.
+ *
  * Revision 1.1.1.1  2000/06/27 11:36:56  priikone
- *     Importet from internal CVS/Added Log headers.
+ *     Imported from internal CVS/Added Log headers.
  *
  *
  */
 
 #include "serverincludes.h"
+#include "server_internal.h"
 #include "route.h"
 
 /* Route cache hash table */
@@ -41,7 +55,7 @@ SilcServerRouteTable silc_route_cache[SILC_SERVER_ROUTE_SIZE];
    index value generated by silc_server_route_hash. */
 
 void silc_server_route_add(unsigned int index, unsigned int dest,
-                          SilcServerList *router)
+                          SilcServerEntry router)
 {
   silc_route_cache[index].dest = dest;
   silc_route_cache[index].router = router;
@@ -50,7 +64,7 @@ void silc_server_route_add(unsigned int index, unsigned int dest,
 /* Checksk whether destination has a specific router. Returns the
    router data if found, NULL otherwise. */
 
-SilcServerList *silc_server_route_check(unsigned int dest, 
+SilcServerEntry silc_server_route_check(unsigned int dest, 
                                        unsigned short port)
 {
   unsigned int index;
@@ -63,3 +77,41 @@ SilcServerList *silc_server_route_check(unsigned int dest,
 
   return NULL;
 }
+
+/* Returns the connection object for the fastest route for the given ID.
+   If we are normal server then this just returns our primary route. If
+   we are router we will do route lookup. */
+
+SilcSocketConnection silc_server_get_route(SilcServer server, void *id,
+                                          SilcIdType id_type)
+{
+  unsigned int dest = 0;
+  unsigned short port = 0;
+  SilcServerEntry router = NULL;
+
+  if (server->server_type == SILC_SERVER)
+    return (SilcSocketConnection)server->id_entry->router->connection;
+  
+  switch(id_type) {
+  case SILC_ID_CLIENT:
+    dest = ((SilcClientID *)id)->ip.s_addr;
+    port = server->id->port;
+    break;
+  case SILC_ID_SERVER:
+    dest = ((SilcServerID *)id)->ip.s_addr;
+    port = ((SilcServerID *)id)->port;
+    break;
+  case SILC_ID_CHANNEL:
+    dest = ((SilcChannelID *)id)->ip.s_addr;
+    port = ((SilcChannelID *)id)->port;
+    break;
+  default:
+    return NULL;
+  }
+
+  router = silc_server_route_check(dest, port);
+  if (!router)
+    return (SilcSocketConnection)server->id_entry->router->connection;
+
+  return (SilcSocketConnection)router->connection;
+}