-bool chal_reply_h(connection_t *c, const char *request) {
- char hishash[MAX_STRING_SIZE];
-
- if(sscanf(request, "%*d " MAX_STRING, hishash) != 1) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "CHAL_REPLY", c->name,
- c->hostname);
- return false;
- }
-
- /* Convert the hash to binary format */
-
- int inlen = hex2bin(hishash, hishash, sizeof hishash);
-
- /* Check if the length of the hash is all right */
-
- if(inlen != digest_length(c->outdigest)) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge reply length");
- return false;
- }
-
-
- /* Verify the hash */
-
- if(!digest_verify(c->outdigest, c->hischallenge, rsa_size(c->rsa), hishash)) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge reply");
- return false;
- }
-
- /* Identity has now been positively verified.
- Send an acknowledgement with the rest of the information needed.
- */
-
- free(c->hischallenge);
- c->hischallenge = NULL;
- c->allow_request = ACK;
-
- return send_ack(c);
-}
-
-static bool send_upgrade(connection_t *c) {
- /* Special case when protocol_minor is 1: the other end is ECDSA capable,
- * but doesn't know our key yet. So send it now. */
-
- char *pubkey = ecdsa_get_base64_public_key(myself->connection->ecdsa);
-
- if(!pubkey)
- return false;
-
- bool result = send_request(c, "%d %s", ACK, pubkey);
- free(pubkey);
- return result;
-}
-
-bool send_ack(connection_t *c) {
- if(c->protocol_minor == 1)
- return send_upgrade(c);
-
- /* ACK message contains rest of the information the other end needs
- to create node_t and edge_t structures. */
-
- struct timeval now;
- bool choice;
-
- /* Estimate weight */
-
- gettimeofday(&now, NULL);
- c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000;
-
- /* Check some options */
-
- if((get_config_bool(lookup_config(c->config_tree, "IndirectData"), &choice) && choice) || myself->options & OPTION_INDIRECT)
- c->options |= OPTION_INDIRECT;
-
- if((get_config_bool(lookup_config(c->config_tree, "TCPOnly"), &choice) && choice) || myself->options & OPTION_TCPONLY)
- c->options |= OPTION_TCPONLY | OPTION_INDIRECT;
-
- if(myself->options & OPTION_PMTU_DISCOVERY)
- c->options |= OPTION_PMTU_DISCOVERY;
-
- choice = myself->options & OPTION_CLAMP_MSS;
- get_config_bool(lookup_config(c->config_tree, "ClampMSS"), &choice);
- if(choice)
- c->options |= OPTION_CLAMP_MSS;
-
- if(!get_config_int(lookup_config(c->config_tree, "Weight"), &c->estimated_weight))
- get_config_int(lookup_config(config_tree, "Weight"), &c->estimated_weight);
-
- return send_request(c, "%d %s %d %x", ACK, myport, c->estimated_weight, (c->options & 0xffffff) | (experimental ? (PROT_MINOR << 24) : 0));
-}
-
-static void send_everything(connection_t *c) {