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.43 by pcg, Fri Mar 4 04:52:38 2005 UTC vs.
Revision 1.47 by pcg, Mon Mar 7 01:31:26 2005 UTC

644 { 644 {
645 connection *r = vpn->find_router (); 645 connection *r = vpn->find_router ();
646 646
647 if (r) 647 if (r)
648 { 648 {
649 slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s"), 649 slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s (%s)"),
650 conf->nodename, r->conf->nodename); 650 conf->nodename, r->conf->nodename, (const char *)r->si);
651 return r->si; 651 return r->si;
652 } 652 }
653 else 653 else
654 slog (L_DEBUG, _("%s: node unreachable, no common protocol"), 654 slog (L_DEBUG, _("%s: node unreachable, no common protocol"),
655 conf->nodename); 655 conf->nodename);
659} 659}
660 660
661void 661void
662connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) 662connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos)
663{ 663{
664 bool ok; 664 if (!vpn->send_vpn_packet (pkt, si, tos))
665
666 switch (si.prot)
667 {
668 case PROT_IPv4:
669 ok = vpn->send_ipv4_packet (pkt, si, tos); break;
670 case PROT_UDPv4:
671 ok = vpn->send_udpv4_packet (pkt, si, tos); break;
672#if ENABLE_TCP
673 case PROT_TCPv4:
674 ok = vpn->send_tcpv4_packet (pkt, si, tos); break;
675#endif
676#if ENABLE_ICMP
677 case PROT_ICMPv4:
678 ok = vpn->send_icmpv4_packet (pkt, si, tos); break;
679#endif
680#if ENABLE_DNS
681 case PROT_DNSv4:
682 ok = send_dnsv4_packet (pkt, si, tos); break;
683#endif
684
685 default:
686 slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol"), (const char *)si);
687 ok = false;
688 }
689
690 if (!ok)
691 reset_connection (); 665 reset_connection ();
692} 666}
693 667
694void 668void
695connection::send_ping (const sockinfo &si, u8 pong) 669connection::send_ping (const sockinfo &si, u8 pong)
771 && conf != THISNODE 745 && conf != THISNODE
772 && connectmode != conf_node::C_NEVER 746 && connectmode != conf_node::C_NEVER
773 && connectmode != conf_node::C_DISABLED 747 && connectmode != conf_node::C_DISABLED
774 && NOW > w.at) 748 && NOW > w.at)
775 { 749 {
776 double retry_int = double (retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2)) * 0.6; 750 w.at = TSTAMP_MAX; // first disable this watcher in case of recursion
777 751
778 if (retry_int < conf->max_retry) 752 double retry_int = double (retry_cnt & 3
779 retry_cnt++; 753 ? (retry_cnt & 3) + 1
780 else 754 : 1 << (retry_cnt >> 2));
781 retry_int = conf->max_retry;
782
783 w.start (NOW + retry_int);
784 755
785 reset_si (); 756 reset_si ();
757
758 bool slow = si.prot & PROT_SLOW;
786 759
787 if (si.prot && !si.host) 760 if (si.prot && !si.host)
788 vpn->send_connect_request (conf->id); 761 vpn->send_connect_request (conf->id);
789 else 762 else
790 { 763 {
791 const sockinfo &dsi = forward_si (si); 764 const sockinfo &dsi = forward_si (si);
765
766 slow = slow || (dsi.prot & PROT_SLOW);
792 767
793 if (dsi.valid () && auth_rate_limiter.can (dsi)) 768 if (dsi.valid () && auth_rate_limiter.can (dsi))
794 { 769 {
795 if (retry_cnt < 4) 770 if (retry_cnt < 4)
796 send_auth_request (dsi, true); 771 send_auth_request (dsi, true);
797 else 772 else
798 send_ping (dsi, 0); 773 send_ping (dsi, 0);
799 } 774 }
800 } 775 }
776
777 retry_int *= slow ? 3. : 0.7;
778
779 if (retry_int < conf->max_retry)
780 retry_cnt++;
781 else
782 retry_int = conf->max_retry;
783
784 w.start (NOW + retry_int);
801 } 785 }
802} 786}
803 787
804void 788void
805connection::reset_connection () 789connection::reset_connection ()
813 run_script (run_script_cb (this, &connection::script_node_down), false); 797 run_script (run_script_cb (this, &connection::script_node_down), false);
814 } 798 }
815 799
816 delete ictx; ictx = 0; 800 delete ictx; ictx = 0;
817 delete octx; octx = 0; 801 delete octx; octx = 0;
802#if ENABLE_DNS
803 dnsv4_reset_connection ();
804#endif
818 805
819 si.host = 0; 806 si.host = 0;
820 807
821 last_activity = 0; 808 last_activity = 0;
822 retry_cnt = 0; 809 retry_cnt = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines