while true try socket openSocket ByteBuffer welcomePacket handshake so

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
while(true) try {
socket = openSocket();
ByteBuffer welcomePacket = handshake(socket);
InetAddress address = null;
try {
address = parseAddress(welcomePacket);
} catch (UnknownHostException e) {
// this will never happen, the address was validated in handshake()
}
int netmask = parseNetmask(welcomePacket);
changeStatus(VPN_STATUS_CONNECTED);
runVPN(socket, createInterface(address.getHostAddress(), netmask));
changeStatus(VPN_STATUS_DISCONNECTED);
} catch (VpnBrokenTunnel e) {
changeStatus(VPN_STATUS_BROKEN);
} catch (VpnHandshakeFailed e) {
changeStatus(VPN_STATUS_ERROR);
break;
} catch (VpnConnectionFailed e) {
changeStatus(VPN_STATUS_ERROR);
break;
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException ignored) {
}
}
}