public void DataLoop() { while (true) { byte[] read = Tun.Read(); var route = GetRoute(read); if (route != null) { Log.Trace("Routing {0} long packet to {1}", read.Length, route.Address); route.WritePacket(read); } else { Log.Warn("Couldn't find route for packet with destination address {0}", NetworkTools.GetDestination(read)); continue; } } }
public bool Init() { try { Link = new ServerLink(Tunnel); Link.LoadCertificatesFromFiles( CertificateAuthorityPath, CertificatePath, SignaturePath); if (Link.PerformHandshake().Type != HandshakeResultType.Successful) { Log.Error("Handshake failed, can't init"); return(false); } LinkToTun = (sender, data) => { Tun.Write(data); Log.Trace("Wrote {0} bytes", data.Length); Log.Trace("Packet from link: {0} -> {1}", NetworkTools.GetSource(data), NetworkTools.GetDestination(data)); if (Address == null) { if (NetworkTools.GetSource(data).ToString().StartsWith("10.0.0")) { Address = NetworkTools.GetSource(data); } } }; Link.OnDataReceived += LinkToTun; return(true); } catch (Exception ex) { Log.Error("Failed to initialize client instance"); Log.Error("\tRemote endpoint: {0}", Tunnel.ToString()); Log.Error(ex); try { End(); Log.Info("Successfully terminated client instance"); } catch { Log.Info("Failed to terminate client instance"); } return(false); } }