ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/connection.C
(Generate patch)

Comparing gvpe/src/connection.C (file contents):
Revision 1.69 by pcg, Thu Aug 7 17:54:26 2008 UTC vs.
Revision 1.72 by pcg, Fri Aug 8 16:48:00 2008 UTC

30*/ 30*/
31 31
32#include "config.h" 32#include "config.h"
33 33
34#include <list> 34#include <list>
35#include <queue>
36#include <utility>
35 37
36#include <openssl/rand.h> 38#include <openssl/rand.h>
37#include <openssl/evp.h> 39#include <openssl/evp.h>
38#include <openssl/rsa.h> 40#include <openssl/rsa.h>
39#include <openssl/err.h> 41#include <openssl/err.h>
55#define ULTRA_FAST 1 57#define ULTRA_FAST 1
56#define HLOG 15 58#define HLOG 15
57#include "lzf/lzf.h" 59#include "lzf/lzf.h"
58#include "lzf/lzf_c.c" 60#include "lzf/lzf_c.c"
59#include "lzf/lzf_d.c" 61#include "lzf/lzf_d.c"
62
63//////////////////////////////////////////////////////////////////////////////
64
65static std::queue< std::pair<run_script_cb *, const char *> > rs_queue;
66static ev::child rs_child_ev;
67
68void // c++ requires external linkage here, apparently :(
69rs_child_cb (ev::child &w, int revents)
70{
71 w.stop ();
72
73 if (rs_queue.empty ())
74 return;
75
76 pid_t pid = run_script (*rs_queue.front ().first, false);
77 if (pid)
78 {
79 w.set (pid);
80 w.start ();
81 }
82 else
83 slog (L_WARN, rs_queue.front ().second);
84
85 delete rs_queue.front ().first;
86 rs_queue.pop ();
87}
88
89// despite the fancy name, this is quite a hack
90static void
91run_script_queued (run_script_cb *cb, const char *warnmsg)
92{
93 rs_queue.push (std::make_pair (cb, warnmsg));
94
95 if (!rs_child_ev.is_active ())
96 {
97 rs_child_ev.set<rs_child_cb> ();
98 rs_child_ev ();
99 }
100}
101
102//////////////////////////////////////////////////////////////////////////////
60 103
61struct crypto_ctx 104struct crypto_ctx
62{ 105{
63 EVP_CIPHER_CTX cctx; 106 EVP_CIPHER_CTX cctx;
64 HMAC_CTX hctx; 107 HMAC_CTX hctx;
668void 711void
669connection::reset_si () 712connection::reset_si ()
670{ 713{
671 protocol = best_protocol (THISNODE->protocols & conf->protocols); 714 protocol = best_protocol (THISNODE->protocols & conf->protocols);
672 715
673 // mask out protocols we cannot establish 716 // mask out endpoints we can't connect to
674 if (!conf->udp_port) protocol &= ~PROT_UDPv4; 717 if (!conf->udp_port) protocol &= ~PROT_UDPv4;
675 if (!conf->tcp_port) protocol &= ~PROT_TCPv4; 718 if (!conf->tcp_port) protocol &= ~PROT_TCPv4;
676 if (!conf->dns_port) protocol &= ~PROT_DNSv4; 719 if (!conf->dns_port) protocol &= ~PROT_DNSv4;
677 720
678 if (protocol 721 if (protocol
699 slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s (%s)"), 742 slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s (%s)"),
700 conf->nodename, r->conf->nodename, (const char *)r->si); 743 conf->nodename, r->conf->nodename, (const char *)r->si);
701 return r->si; 744 return r->si;
702 } 745 }
703 else 746 else
704 slog (L_DEBUG, _("%s: node unreachable, no common protocol"), 747 slog (L_DEBUG, _("%s: node unreachable, no common protocol, no router"),
705 conf->nodename); 748 conf->nodename);
706 } 749 }
707 750
708 return si; 751 return si;
709} 752}
858 slog (L_INFO, _("%s(%s): connection lost"), 901 slog (L_INFO, _("%s(%s): connection lost"),
859 conf->nodename, (const char *)si); 902 conf->nodename, (const char *)si);
860 903
861 if (::conf.script_node_down) 904 if (::conf.script_node_down)
862 { 905 {
863 run_script_cb cb; 906 run_script_cb *cb = new run_script_cb;
864 cb.set<connection, &connection::script_node_down> (this); 907 cb->set<connection, &connection::script_node_down> (this);
865 if (!run_script (cb, false))
866 slog (L_WARN, _("node-down command execution failed, continuing.")); 908 run_script_queued (cb, _("node-down command execution failed, continuing."));
867 } 909 }
868 } 910 }
869 911
870 delete ictx; ictx = 0; 912 delete ictx; ictx = 0;
871 delete octx; octx = 0; 913 delete octx; octx = 0;
1104 conf->nodename, (const char *)rsi, 1146 conf->nodename, (const char *)rsi,
1105 p->prot_major, p->prot_minor); 1147 p->prot_major, p->prot_minor);
1106 1148
1107 if (::conf.script_node_up) 1149 if (::conf.script_node_up)
1108 { 1150 {
1109 run_script_cb cb; 1151 run_script_cb *cb = new run_script_cb;
1110 cb.set<connection, &connection::script_node_up> (this); 1152 cb->set<connection, &connection::script_node_up> (this);
1111 if (!run_script (cb, false))
1112 slog (L_WARN, _("node-up command execution failed, continuing.")); 1153 run_script_queued (cb, _("node-up command execution failed, continuing."));
1113 } 1154 }
1114 1155
1115 break; 1156 break;
1116 } 1157 }
1117 else 1158 else
1327connection::connection (struct vpn *vpn, conf_node *conf) 1368connection::connection (struct vpn *vpn, conf_node *conf)
1328: vpn(vpn), conf(conf), 1369: vpn(vpn), conf(conf),
1329#if ENABLE_DNS 1370#if ENABLE_DNS
1330 dns (0), 1371 dns (0),
1331#endif 1372#endif
1332 data_queue(conf->max_ttl, conf->max_queue), 1373 data_queue(conf->max_ttl, conf->max_queue + 1),
1333 vpn_queue(conf->max_ttl, conf->max_queue) 1374 vpn_queue(conf->max_ttl, conf->max_queue + 1)
1334{ 1375{
1335 rekey .set<connection, &connection::rekey_cb > (this); 1376 rekey .set<connection, &connection::rekey_cb > (this);
1336 keepalive .set<connection, &connection::keepalive_cb > (this); 1377 keepalive .set<connection, &connection::keepalive_cb > (this);
1337 establish_connection.set<connection, &connection::establish_connection_cb> (this); 1378 establish_connection.set<connection, &connection::establish_connection_cb> (this);
1338 1379

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines