- /* Get data used in packet header encryption, keys and stuff. */
- cipher = conn->internal->send_key;
- hmac = conn->internal->hmac_send;
- id_string = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
-
- /* Set the packet context pointers. The destination ID is always
- the Channel ID of the channel. Server and router will handle the
- distribution of the packet. */
- data = payload->data;
- data_len = payload->len;
- packetdata.flags = 0;
- packetdata.type = SILC_PACKET_CHANNEL_MESSAGE;
- packetdata.src_id = conn->local_id_data;
- packetdata.src_id_len = silc_id_get_len(conn->local_id, SILC_ID_CLIENT);
- packetdata.src_id_type = SILC_ID_CLIENT;
- packetdata.dst_id = id_string;
- packetdata.dst_id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL);
- packetdata.dst_id_type = SILC_ID_CHANNEL;
- data_len = SILC_PACKET_DATALEN(data_len, SILC_PACKET_HEADER_LEN +
- packetdata.src_id_len +
- packetdata.dst_id_len);
- packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
- packetdata.src_id_len + packetdata.dst_id_len;
- SILC_PACKET_PADLEN((SILC_PACKET_HEADER_LEN +
- packetdata.src_id_len +
- packetdata.dst_id_len), block_len, packetdata.padlen);
-
- /* Create the outgoing packet */
- if (!silc_packet_assemble(&packetdata, client->rng, cipher, hmac, sock,
- data, data_len, (const SilcBuffer)&packet)) {
- SILC_LOG_ERROR(("Error assembling packet"));
- goto out;
- }
-
- /* Encrypt the header and padding of the packet. This is encrypted
- with normal session key shared with our server. */
- silc_packet_encrypt(cipher, hmac, conn->internal->psn_send++,
- (SilcBuffer)&packet, SILC_PACKET_HEADER_LEN +
- packetdata.src_id_len + packetdata.dst_id_len +
- packetdata.padlen);
-
- SILC_LOG_HEXDUMP(("Packet to channel, len %d", packet.len),
- packet.data, packet.len);
-
- /* Now actually send the packet */
- silc_client_packet_send_real(client, sock, force_send);
-
- /* Check for mandatory rekey */
- if (conn->internal->psn_send == SILC_CLIENT_REKEY_THRESHOLD)
- silc_schedule_task_add(client->schedule, sock->sock,
- silc_client_rekey_callback, sock, 0, 1,
- SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
-
- ret = TRUE;
-
- out:
- silc_buffer_free(payload);
- silc_free(id_string);