+cp
+ /* Generate packet encryption key */
+
+ myself->cipher_pkttype = EVP_bf_cbc();
+
+ myself->cipher_pktkeylength = myself->cipher_pkttype->key_len + myself->cipher_pkttype->iv_len;
+
+ myself->cipher_pktkey = (char *)xmalloc(myself->cipher_pktkeylength);
+ RAND_pseudo_bytes(myself->cipher_pktkey, myself->cipher_pktkeylength);
+
+ if(!(cfg = get_config_val(config, config_keyexpire)))
+ keylifetime = 3600;
+ else
+ keylifetime = cfg->data.val;
+
+ keyexpires = time(NULL) + keylifetime;
+cp
+
+ /* Activate ourselves */
+
+ myself->status.active = 1;
+
+ syslog(LOG_NOTICE, _("Ready: listening on port %hd"), myself->port);
+cp
+ return 0;
+}
+
+RETSIGTYPE
+sigalrm_handler(int a)
+{
+ config_t const *cfg;
+cp
+ cfg = get_config_val(upstreamcfg, config_connectto);
+
+ if(!cfg)
+ {
+ if(upstreamcfg == config)
+ {
+ /* No upstream IP given, we're listen only. */
+ signal(SIGALRM, SIG_IGN);
+ return;
+ }
+ }
+ else
+ {
+ /* We previously tried all the ConnectTo lines. Now wrap back to the first. */
+ cfg = get_config_val(config, config_connectto);
+ }
+
+ while(cfg)
+ {
+ upstreamcfg = cfg->next;
+ if(!setup_outgoing_connection(cfg->data.ptr)) /* function returns 0 when there are no problems */
+ {
+ signal(SIGALRM, SIG_IGN);
+ return;
+ }
+ cfg = get_config_val(upstreamcfg, config_connectto); /* Or else we try the next ConnectTo line */
+ }
+
+ signal(SIGALRM, sigalrm_handler);
+ upstreamcfg = config;
+ seconds_till_retry += 5;
+ if(seconds_till_retry > MAXTIMEOUT) /* Don't wait more than MAXTIMEOUT seconds. */
+ seconds_till_retry = MAXTIMEOUT;
+ syslog(LOG_ERR, _("Still failed to connect to other, will retry in %d seconds"),
+ seconds_till_retry);
+ alarm(seconds_till_retry);
+cp
+}