- case SILC_PACKET_KEY_EXCHANGE_1:
- if (sock->protocol && sock->protocol->protocol &&
- (sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_KEY_EXCHANGE ||
- sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_REKEY)) {
-
- if (sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_REKEY) {
- SilcClientRekeyInternalContext *proto_ctx =
- (SilcClientRekeyInternalContext *)sock->protocol->context;
-
- if (proto_ctx->packet)
- silc_packet_context_free(proto_ctx->packet);
-
- proto_ctx->packet = silc_packet_context_dup(packet);
-
- /* Let the protocol handle the packet */
- silc_protocol_execute(sock->protocol, client->schedule, 0, 0);
- } else {
- SilcClientKEInternalContext *proto_ctx =
- (SilcClientKEInternalContext *)sock->protocol->context;
-
- if (proto_ctx->packet)
- silc_packet_context_free(proto_ctx->packet);
-
- proto_ctx->packet = silc_packet_context_dup(packet);
- proto_ctx->dest_id_type = packet->src_id_type;
- proto_ctx->dest_id = silc_id_str2id(packet->src_id, packet->src_id_len,
- packet->src_id_type);
- if (!proto_ctx->dest_id)
- break;
-
- /* Let the protocol handle the packet */
- silc_protocol_execute(sock->protocol, client->schedule, 0, 0);
- }
- } else {
- SILC_LOG_ERROR(("Received Key Exchange 1 packet but no key exchange "
- "protocol active, packet dropped."));
- }
- break;
- case SILC_PACKET_KEY_EXCHANGE_2:
- if (sock->protocol && sock->protocol->protocol &&
- (sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_KEY_EXCHANGE ||
- sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_REKEY)) {
-
- if (sock->protocol->protocol->type == SILC_PROTOCOL_CLIENT_REKEY) {
- SilcClientRekeyInternalContext *proto_ctx =
- (SilcClientRekeyInternalContext *)sock->protocol->context;
-
- if (proto_ctx->packet)
- silc_packet_context_free(proto_ctx->packet);
-
- proto_ctx->packet = silc_packet_context_dup(packet);
-
- /* Let the protocol handle the packet */
- silc_protocol_execute(sock->protocol, client->schedule, 0, 0);
- } else {
- SilcClientKEInternalContext *proto_ctx =
- (SilcClientKEInternalContext *)sock->protocol->context;
-
- if (proto_ctx->packet)
- silc_packet_context_free(proto_ctx->packet);
-
- proto_ctx->packet = silc_packet_context_dup(packet);
- proto_ctx->dest_id_type = packet->src_id_type;
- proto_ctx->dest_id = silc_id_str2id(packet->src_id, packet->src_id_len,
- packet->src_id_type);
- if (!proto_ctx->dest_id)
- break;
-
- /* Let the protocol handle the packet */
- silc_protocol_execute(sock->protocol, client->schedule, 0, 0);
- }
- } else {
- SILC_LOG_ERROR(("Received Key Exchange 2 packet but no key exchange "
- "protocol active, packet dropped."));
- }
- break;
+ conn->client = client;
+ conn->public_key = public_key;
+ conn->private_key = private_key;
+ conn->remote_host = strdup(remote_host);
+ conn->remote_port = port ? port : 706;
+ conn->type = conn_type;
+ conn->callback = callback;
+ conn->callback_context = context;
+
+ conn->internal = silc_calloc(1, sizeof(*conn->internal));
+ if (!conn->internal) {
+ silc_free(conn);
+ return NULL;
+ }
+ conn->internal->retry_timer = SILC_CLIENT_RETRY_MIN;
+ silc_mutex_alloc(&conn->internal->lock);
+ silc_atomic_init16(&conn->internal->cmd_ident, 0);
+
+ if (!silc_hash_alloc("sha1", &conn->internal->sha1hash)) {
+ silc_free(conn);
+ silc_free(conn->internal);
+ return NULL;
+ }