From b79286ec96f5853ba53a73b62b985b12d87d8af0 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 17 Feb 2014 19:50:36 +0100 Subject: BigInteger arithmetic is slow as hell. Cache getFirst/Last address --- main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java | 10 ++++++++-- main/src/main/res/values/strings.xml | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'main/src') diff --git a/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java b/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java index c7d09065..54470962 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java +++ b/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java @@ -15,6 +15,8 @@ public class NetworkSpace { public int networkMask; private boolean included; private boolean isV4; + private BigInteger firstaddr; + private BigInteger lastaddr; @Override @@ -55,12 +57,16 @@ public class NetworkSpace { } public BigInteger getLastAddress() { - return getMaskedAddress(true); + if(lastaddr==null) + lastaddr= getMaskedAddress(true); + return lastaddr; } public BigInteger getFirstAddress() { - return getMaskedAddress(false); + if (firstaddr==null) + firstaddr=getMaskedAddress(false); + return firstaddr; } diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index 8c643f6d..3b9b9c0f 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -220,7 +220,7 @@ OpenVPN Log Import OpenVPN configuration Battery consumption - In my personal tests the main reason for high battery consumption of OpenVPN are the keepalive packets. Most OpenVPN servers have a configuration directive like \'keepalive 10 60\' which causes the client and server to exchange keepalive packets every ten seconds. <p> While these packets are small and do not use much traffic, they keep the mobile radio network busy and increase the energy consumption. (See also <a href="http://developer.android.com/training/efficient-downloads/efficient-network-access.html#RadioStateMachine">The Radio State Machine | Android Developers</a>) <p> This keepalive setting cannot be changed on the client. Only the system administrator of the OpenVPN can change the setting. <p> Unfortunately using a keepalive larger than 60 seconds with UDP can cause some NAT gateways to drop the connection due to an inactivity timeout. Using TCP with a long keepalive timeout works, but tunneling TCP over TCP performs extremely poorly on connections with high packet loss. (See <a href="http://sites.inka.de/bigred/devel/tcp-tcp.html">Why TCP Over TCP Is A Bad Idea</a>) + In my personal tests the main reason for high battery consumption of OpenVPN are the keepalive packets. Most OpenVPN servers have a configuration directive like \'keepalive 10 60\' which causes the client and server to exchange keepalive packets every ten seconds. <p> While these packets are small and do not use much traffic, they keep the mobile radio network busy and increase the energy consumption. (See also <a href="http://developer.android.com/training/efficient-downloads/efficient-network-access.html#RadioStateMachine">The Radio State Machine | Android Developers</a>) <p> This keepalive setting cannot be changed on the client. Only the system administrator of the OpenVPN can change the setting. <p> Unfortunately using a keepalive larger than 60 seconds with UDP can cause some NAT gateways to drop the connection due to an inactivity timeout. Using TCP with a long keep alive timeout works, but tunneling TCP over TCP performs extremely poorly on connections with high packet loss. (See <a href="http://sites.inka.de/bigred/devel/tcp-tcp.html">Why TCP Over TCP Is A Bad Idea</a>) The Android Tethering feature (over WiFi, USB or Bluetooth) and the VPNService API (used by this program) do not work together. For more details see the <a href=\"http://code.google.com/p/ics-openvpn/issues/detail?id=34\">issue #34</a> VPN and Tethering Connection retries -- cgit v1.2.3