- client->ops->say(client, conn, SILC_CLIENT_MESSAGE_AUDIT,
- "Connecting to port %d of server %s", port, host);
-
- /* Allocate internal context for connection process. This is
- needed as we are doing async connecting. */
- ctx = silc_calloc(1, sizeof(*ctx));
- ctx->client = client;
- ctx->conn = conn;
- ctx->host = strdup(host);
- ctx->port = port;
- ctx->tries = 0;
-
- /* Do the actual connecting process */
- sock = silc_client_connect_to_server_internal(ctx);
- if (sock == -1)
- silc_client_del_connection(client, conn);
- return sock;
-}
-
-/* Start SILC Key Exchange (SKE) protocol to negotiate shared secret
- key material between client and server. This function can be called
- directly if application is performing its own connecting and does not
- use the connecting provided by this library. This function is normally
- used only if the application performed the connecting outside the library.
- The library however may use this internally. */
-
-bool silc_client_start_key_exchange(SilcClient client,
- SilcClientConnection conn,
- int fd)
-{
- SilcProtocol protocol;
- SilcClientKEInternalContext *proto_ctx;
- void *context;
-
- /* Allocate new socket connection object */
- silc_socket_alloc(fd, SILC_SOCKET_TYPE_SERVER, (void *)conn, &conn->sock);
-
- /* Sometimes when doing quick reconnects the new socket may be same as
- the old one and there might be pending stuff for the old socket.
- If new one is same then those pending sutff might cause problems.
- Make sure they do not do that. */
- silc_schedule_task_del_by_fd(client->schedule, fd);
-
- conn->nickname = strdup(client->username);
- conn->sock->hostname = conn->remote_host;
- conn->sock->ip = strdup(conn->remote_host);
- conn->sock->port = conn->remote_port;
-
- /* Allocate internal Key Exchange context. This is sent to the
- protocol as context. */
- proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
- proto_ctx->client = (void *)client;
- proto_ctx->sock = silc_socket_dup(conn->sock);
- proto_ctx->rng = client->rng;
- proto_ctx->responder = FALSE;
- proto_ctx->send_packet = silc_client_protocol_ke_send_packet;
- proto_ctx->verify = silc_client_protocol_ke_verify_key;
-
- /* Perform key exchange protocol. silc_client_connect_to_server_final
- will be called after the protocol is finished. */
- silc_protocol_alloc(SILC_PROTOCOL_CLIENT_KEY_EXCHANGE,
- &protocol, (void *)proto_ctx,
- silc_client_connect_to_server_second);
- if (!protocol) {
- client->ops->say(client, conn, SILC_CLIENT_MESSAGE_ERROR,
- "Error: Could not start key exchange protocol");
- return FALSE;