updates.
[silc.git] / apps / silcd / packet_send.c
index 775ab48ef87305576550b805f30e554189d87269..70911cf0a4db4ba0d2943f3f20c9741be830d49d 100644 (file)
@@ -180,52 +180,6 @@ void silc_server_packet_send_dest(SilcServer server,
     silc_free(packetdata.dst_id);
 }
 
-/* Forwards packet. Packets sent with this function will be marked as
-   forwarded (in the SILC header flags) so that the receiver knows that
-   we have forwarded the packet to it. Forwarded packets are handled
-   specially by the receiver as they are not destined to the receiver
-   originally. However, the receiver knows this because the forwarded
-   flag has been set (and the flag is authenticated). */
-
-void silc_server_packet_forward(SilcServer server,
-                               SilcSocketConnection sock,
-                               unsigned char *data, unsigned int data_len,
-                               int force_send)
-{
-  SilcIDListData idata;
-  SilcCipher cipher = NULL;
-  SilcHmac hmac = NULL;
-
-  SILC_LOG_DEBUG(("Forwarding packet"));
-
-  /* Get data used in the packet sending, keys and stuff */
-  idata = (SilcIDListData)sock->user_data;
-
-  /* Prepare outgoing data buffer for packet sending */
-  silc_packet_send_prepare(sock, 0, 0, data_len);
-
-  /* Put the data to the buffer */
-  if (data && data_len)
-    silc_buffer_put(sock->outbuf, data, data_len);
-
-  /* Add the FORWARDED flag to packet flags */
-  sock->outbuf->data[2] |= (unsigned char)SILC_PACKET_FLAG_FORWARDED;
-
-  if (idata) {
-    cipher = idata->send_key;
-    hmac = idata->hmac;
-  }
-
-  /* Encrypt the packet */
-  silc_packet_encrypt(cipher, hmac, sock->outbuf, sock->outbuf->len);
-
-  SILC_LOG_HEXDUMP(("Forwarded packet, len %d", sock->outbuf->len),
-                  sock->outbuf->data, sock->outbuf->len);
-
-  /* Now actually send the packet */
-  silc_server_packet_send_real(server, sock, force_send);
-}
-
 /* Broadcast received packet to our primary route. This function is used
    by router to further route received broadcast packet. It is expected
    that the broadcast flag from the packet is checked before calling this
@@ -441,6 +395,12 @@ void silc_server_packet_send_to_channel(SilcServer server,
       continue;
     }
 
+    if (server->server_type == SILC_ROUTER && !route)
+      continue;
+
+    if (server->server_type == SILC_SERVER && client->router)
+      continue;
+
     /* Send to locally connected client */
     if (client) {
 
@@ -581,14 +541,15 @@ void silc_server_packet_relay_to_channel(SilcServer server,
        continue;
       }
 
-      /* XXX Check client's mode on the channel. */
+      if (server->server_type == SILC_SERVER && client->router)
+       continue;
 
       /* Get data used in packet header encryption, keys and stuff. */
       sock = (SilcSocketConnection)client->connection;
       idata = (SilcIDListData)client;
 
-      SILC_LOG_DEBUG(("Sending packet to client %s", 
-                     sock->hostname ? sock->hostname : sock->ip));
+      SILC_LOG_DEBUG(("Sending packet to client %s (%s)", 
+                     sock->hostname, sock->ip));
 
       /* Send the packet */
       silc_server_packet_send_to_channel_real(server, sock, &packetdata,
@@ -881,6 +842,9 @@ void silc_server_send_notify_on_channels(SilcServer server,
        continue;
       }
 
+      if (server->server_type == SILC_SERVER && client->router)
+       continue;
+
       /* Send to locally connected client */
       if (c) {
        
@@ -1088,14 +1052,14 @@ void silc_server_send_new_channel_user(SilcServer server,
 
   SILC_LOG_DEBUG(("Start"));
 
-  clid = silc_id_id2str(client_id, SILC_ID_CLIENT);
-  if (!clid)
-    return;
-
   chid = silc_id_id2str(channel_id, SILC_ID_CHANNEL);
   if (!chid)
     return;
 
+  clid = silc_id_id2str(client_id, SILC_ID_CLIENT);
+  if (!clid)
+    return;
+
   packet = silc_buffer_alloc(2 + 2 + channel_id_len + client_id_len);
   silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
   silc_buffer_format(packet,
@@ -1115,10 +1079,10 @@ void silc_server_send_new_channel_user(SilcServer server,
 
 /* Send Channel Key payload to distribute the new channel key. Normal server
    sends this to router when new client joins to existing channel. Router
-   sends this to the local server who forwarded join command in case where
-   the channel did not exist yet.  Both normal and router servers uses this
+   sends this to the local server who sent the join command in case where
+   the channel did not exist yet. Both normal and router servers uses this
    also to send this to locally connected clients on the channel. This
-   must not be broadcasted packet. */
+   must not be broadcasted packet. Routers do not send this to each other. */
 
 void silc_server_send_channel_key(SilcServer server,
                                  SilcChannelEntry channel,
@@ -1164,3 +1128,25 @@ void silc_server_send_command(SilcServer server,
                          packet->data, packet->len, TRUE);
   silc_buffer_free(packet);
 }
+
+/* Function used to send REMOVE_ID packet. The packet is used to notify
+   routers that certain ID should be removed. After that the ID will become
+   invalid.  If the argument `broadcast' is TRUE then the packet is sent as
+   broadcast packet. */
+
+void silc_server_send_remove_id(SilcServer server,
+                               SilcSocketConnection sock,
+                               int broadcast,
+                               void *id, unsigned int id_len,
+                               SilcIdType id_type)
+{
+  SilcBuffer idp;
+
+  SILC_LOG_DEBUG(("Start"));
+
+  idp = silc_id_payload_encode(id, id_type);
+  silc_server_packet_send(server, sock, SILC_PACKET_REMOVE_ID, 
+                         broadcast ? SILC_PACKET_FLAG_BROADCAST : 0, 
+                         idp->data, idp->len, FALSE);
+  silc_buffer_free(idp);
+}