… | |
… | |
793 | { |
793 | { |
794 | reset_connection (); |
794 | reset_connection (); |
795 | return; |
795 | return; |
796 | } |
796 | } |
797 | |
797 | |
|
|
798 | last_establish_attempt = ev_now (); |
|
|
799 | |
798 | ev::tstamp retry_int = ev::tstamp (retry_cnt & 3 |
800 | ev::tstamp retry_int = ev::tstamp (retry_cnt & 3 |
799 | ? (retry_cnt & 3) + 1 |
801 | ? (retry_cnt & 3) + 1 |
800 | : 1 << (retry_cnt >> 2)); |
802 | : 1 << (retry_cnt >> 2)); |
801 | |
803 | |
802 | reset_si (); |
804 | reset_si (); |
… | |
… | |
825 | else |
827 | else |
826 | send_ping (dsi, 0); |
828 | send_ping (dsi, 0); |
827 | } |
829 | } |
828 | } |
830 | } |
829 | |
831 | |
830 | retry_int *= slow ? 8. : 0.7; |
832 | retry_int *= slow ? 8. : 0.9; |
831 | |
833 | |
832 | if (retry_int < conf->max_retry) |
834 | if (retry_int < conf->max_retry) |
833 | retry_cnt++; |
835 | retry_cnt++; |
834 | else |
836 | else |
835 | retry_int = conf->max_retry; |
837 | retry_int = conf->max_retry; |
… | |
… | |
905 | if (oseqno > MAX_SEQNO) |
907 | if (oseqno > MAX_SEQNO) |
906 | rekey (); |
908 | rekey (); |
907 | } |
909 | } |
908 | |
910 | |
909 | void |
911 | void |
|
|
912 | connection::post_inject_queue () |
|
|
913 | { |
|
|
914 | // force a connection every now and when when packets are sent (max 1/s) |
|
|
915 | if (ev_now () - last_establish_attempt >= 0.95) // arbitrary |
|
|
916 | establish_connection.stop (); |
|
|
917 | |
|
|
918 | establish_connection (); |
|
|
919 | } |
|
|
920 | |
|
|
921 | void |
910 | connection::inject_data_packet (tap_packet *pkt, bool broadcast/*TODO DDD*/) |
922 | connection::inject_data_packet (tap_packet *pkt) |
911 | { |
923 | { |
912 | if (ictx && octx) |
924 | if (ictx && octx) |
913 | send_data_packet (pkt); |
925 | send_data_packet (pkt); |
914 | else |
926 | else |
915 | { |
927 | { |
916 | if (!broadcast) |
|
|
917 | data_queue.put (new tap_packet (*pkt)); |
928 | data_queue.put (new tap_packet (*pkt)); |
918 | |
929 | post_inject_queue (); |
919 | establish_connection (); |
|
|
920 | } |
930 | } |
921 | } |
931 | } |
922 | |
932 | |
923 | void connection::inject_vpn_packet (vpn_packet *pkt, int tos) |
933 | void connection::inject_vpn_packet (vpn_packet *pkt, int tos) |
924 | { |
934 | { |
925 | if (ictx && octx) |
935 | if (ictx && octx) |
926 | send_vpn_packet (pkt, si, tos); |
936 | send_vpn_packet (pkt, si, tos); |
927 | else |
937 | else |
928 | { |
938 | { |
929 | vpn_queue.put ((vpn_packet *)new data_packet (*(data_packet *)pkt)); |
939 | vpn_queue.put ((vpn_packet *)new data_packet (*(data_packet *)pkt)); |
930 | |
940 | post_inject_queue (); |
931 | establish_connection (); |
|
|
932 | } |
941 | } |
933 | } |
942 | } |
934 | |
943 | |
935 | void |
944 | void |
936 | connection::recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi) |
945 | connection::recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi) |
… | |
… | |
1315 | { |
1324 | { |
1316 | rekey .set<connection, &connection::rekey_cb > (this); |
1325 | rekey .set<connection, &connection::rekey_cb > (this); |
1317 | keepalive .set<connection, &connection::keepalive_cb > (this); |
1326 | keepalive .set<connection, &connection::keepalive_cb > (this); |
1318 | establish_connection.set<connection, &connection::establish_connection_cb> (this); |
1327 | establish_connection.set<connection, &connection::establish_connection_cb> (this); |
1319 | |
1328 | |
|
|
1329 | last_establish_attempt = 0.; |
1320 | octx = ictx = 0; |
1330 | octx = ictx = 0; |
1321 | retry_cnt = 0; |
|
|
1322 | |
1331 | |
1323 | if (!conf->protocols) // make sure some protocol is enabled |
1332 | if (!conf->protocols) // make sure some protocol is enabled |
1324 | conf->protocols = PROT_UDPv4; |
1333 | conf->protocols = PROT_UDPv4; |
1325 | |
1334 | |
1326 | connectmode = conf->connectmode; |
1335 | connectmode = conf->connectmode; |
1327 | |
1336 | |
1328 | // queue a dummy packet to force an initial connection attempt |
1337 | // queue a dummy packet to force an initial connection attempt |
1329 | if (connectmode != conf_node::C_ALWAYS && connectmode != conf_node::C_DISABLED) |
1338 | if (connectmode != conf_node::C_ALWAYS && connectmode != conf_node::C_DISABLED) |
1330 | { |
1339 | vpn_queue.put (new net_packet); |
1331 | net_packet *p = new net_packet; |
|
|
1332 | p->len = 0; |
|
|
1333 | vpn_queue.put (p); |
|
|
1334 | } |
|
|
1335 | |
1340 | |
1336 | reset_connection (); |
1341 | reset_connection (); |
1337 | } |
1342 | } |
1338 | |
1343 | |
1339 | connection::~connection () |
1344 | connection::~connection () |