… | |
… | |
765 | // from THISNODE to dst |
765 | // from THISNODE to dst |
766 | connection *vpn::find_router_for (const connection *dst) |
766 | connection *vpn::find_router_for (const connection *dst) |
767 | { |
767 | { |
768 | connection *router = 0; |
768 | connection *router = 0; |
769 | |
769 | |
770 | // first try to find a router with a direct connection |
770 | // first try to find a router with a direct connection, route there |
|
|
771 | // regardless of any other considerations. |
771 | { |
772 | { |
772 | u32 prio = 1; |
773 | u32 prio = 1; |
773 | |
774 | |
774 | for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) |
775 | for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) |
775 | { |
776 | { |
776 | connection *c = *i; |
777 | connection *c = *i; |
777 | |
778 | |
778 | if (c->conf->routerprio > prio |
779 | if (c->conf->routerprio > prio |
779 | && c->conf != THISNODE |
780 | && c->conf != THISNODE |
780 | && c != dst |
|
|
781 | && can_direct (c->conf, dst->conf)) |
781 | && can_direct (c->conf, dst->conf) |
|
|
782 | && c->ictx && c->octx) |
782 | { |
783 | { |
783 | if (c->ictx && c->octx) |
|
|
784 | { |
|
|
785 | prio = c->conf->routerprio; |
784 | prio = c->conf->routerprio; |
786 | router = c; |
785 | router = c; |
787 | } |
|
|
788 | else |
|
|
789 | c->establish_connection (); |
|
|
790 | } |
786 | } |
791 | } |
787 | } |
792 | } |
788 | } |
793 | |
789 | |
794 | if (router) |
790 | if (router) |
795 | return router; |
791 | return router; |
796 | |
792 | |
797 | // second try find the router with the highest priority higher than ours |
793 | // second try find the router with the highest priority, higher than ours |
798 | { |
794 | { |
799 | u32 prio = 1; |
795 | u32 prio = THISNODE->routerprio ? THISNODE->routerprio : 1; |
800 | |
796 | |
801 | for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) |
797 | for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) |
802 | { |
798 | { |
803 | connection *c = *i; |
799 | connection *c = *i; |
804 | |
800 | |
805 | if (c->conf->routerprio > prio |
801 | if (c->conf->routerprio > prio |
806 | && c->conf->routerprio > THISNODE->routerprio |
|
|
807 | && c != dst |
802 | && c != dst |
808 | && c->conf != THISNODE) |
803 | && c->conf != THISNODE |
|
|
804 | && c->ictx && c->octx) |
809 | { |
805 | { |
810 | if (c->ictx && c->octx) |
|
|
811 | { |
|
|
812 | prio = c->conf->routerprio; |
806 | prio = c->conf->routerprio; |
813 | router = c; |
807 | router = c; |
814 | } |
|
|
815 | else |
|
|
816 | c->establish_connection (); |
|
|
817 | } |
808 | } |
818 | } |
809 | } |
819 | } |
810 | } |
|
|
811 | |
820 | return router; |
812 | return router; |
821 | } |
813 | } |
822 | |
814 | |
823 | void vpn::connection_established (connection *c) |
815 | void vpn::connection_established (connection *c) |
824 | { |
816 | { |
… | |
… | |
842 | { |
834 | { |
843 | connection *r = find_router_for (c); |
835 | connection *r = find_router_for (c); |
844 | |
836 | |
845 | if (r) |
837 | if (r) |
846 | { |
838 | { |
847 | slog (L_TRACE, _("%s: no way to connect, sending mediated connection request via %s."), |
839 | slog (L_TRACE, _("%s: no address known, sending mediated connection request via %s."), |
848 | c->conf->nodename, r->conf->nodename); |
840 | c->conf->nodename, r->conf->nodename); |
849 | r->send_connect_request (c->conf->id); |
841 | r->send_connect_request (c->conf->id); |
850 | } |
842 | } |
851 | else |
843 | else |
852 | slog (L_DEBUG, _("%s: no way to connect and no router found: unable to connect."), |
844 | slog (L_DEBUG, _("%s: no way to connect and no router found: unable to connect at this time."), |
853 | c->conf->nodename); |
845 | c->conf->nodename); |
854 | } |
846 | } |
855 | |
847 | |
856 | void |
848 | void |
857 | connection::dump_status () |
849 | connection::dump_status () |