mirror of
https://github.com/Ylianst/MeshCentralRouter
synced 2025-12-06 00:13:33 +00:00
improved debug log.
This commit is contained in:
@@ -263,6 +263,7 @@ namespace MeshCentralRouter
|
||||
if (i >= 0) { ux = ux.Substring(0, i); }
|
||||
Uri u = new Uri(ux + "meshrelay.ashx?browser=1&p=5&nodeid=" + node.nodeid + "&id=" + randomIdHex + "&auth=" + server.authCookie);
|
||||
wc = new webSocketClient();
|
||||
wc.xdebug = server.debug;
|
||||
wc.onStateChanged += Wc_onStateChanged;
|
||||
wc.onBinaryData += Wc_onBinaryData;
|
||||
wc.onStringData += Wc_onStringData;
|
||||
|
||||
@@ -105,6 +105,7 @@ namespace MeshCentralRouter
|
||||
if (i >= 0) { ux = ux.Substring(0, i); }
|
||||
Uri u = new Uri(ux + "meshrelay.ashx?browser=1&p=2&nodeid=" + node.nodeid + "&id=" + randomIdHex + "&auth=" + server.authCookie);
|
||||
wc = new webSocketClient();
|
||||
wc.xdebug = server.debug;
|
||||
wc.onStateChanged += Wc_onStateChanged;
|
||||
wc.onBinaryData += Wc_onBinaryData;
|
||||
wc.onStringData += Wc_onStringData;
|
||||
|
||||
@@ -75,6 +75,8 @@ namespace MeshCentralRouter
|
||||
wsurl = new Uri(url);
|
||||
//wshash = serverHashTextBox.Text;
|
||||
|
||||
Debug(string.Format("MeshMapper-Start: Protcol={0}, LocalPort={1}, Url={2}, RemotePort={3}, RemoteIP={4}", protocol, localPort, url, remotePort, remoteIP));
|
||||
|
||||
if (protocol == 1)
|
||||
{
|
||||
// Start the TCP listener
|
||||
@@ -201,6 +203,7 @@ namespace MeshCentralRouter
|
||||
{
|
||||
webSocketClient wc = new webSocketClient();
|
||||
Debug("#" + counter + ": Connecting web socket to: " + wsurl.ToString());
|
||||
wc.xdebug = xdebug;
|
||||
wc.Start(wsurl, certhash);
|
||||
wc.tag = client;
|
||||
wc.id = counter;
|
||||
@@ -213,6 +216,7 @@ namespace MeshCentralRouter
|
||||
{
|
||||
webSocketClient wc = new webSocketClient();
|
||||
Debug("#" + counter + ": Connecting web socket to: " + wsurl.ToString());
|
||||
wc.xdebug = xdebug;
|
||||
wc.Start(wsurl, certhash);
|
||||
wc.tag = client;
|
||||
wc.id = counter;
|
||||
|
||||
16
Program.cs
16
Program.cs
@@ -15,6 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MeshCentralRouter
|
||||
@@ -33,6 +34,10 @@ namespace MeshCentralRouter
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Properties.Settings.Default.Upgrade();
|
||||
|
||||
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(ExceptionSink);
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventSink);
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
|
||||
|
||||
foreach (string arg in args)
|
||||
{
|
||||
if (arg.Length > 3 && string.Compare(arg.Substring(0, 3), "-l:", true) == 0) {
|
||||
@@ -51,5 +56,16 @@ namespace MeshCentralRouter
|
||||
while (currentCulture.Equals(System.Threading.Thread.CurrentThread.CurrentUICulture) == false);
|
||||
}
|
||||
|
||||
public static void Debug(string msg) { try { File.AppendAllText("debug.log", msg + "\r\n"); } catch (Exception) { } }
|
||||
|
||||
public static void ExceptionSink(object sender, System.Threading.ThreadExceptionEventArgs args)
|
||||
{
|
||||
Debug("ExceptionSink: " + args.Exception.ToString());
|
||||
}
|
||||
|
||||
public static void UnhandledExceptionEventSink(object sender, UnhandledExceptionEventArgs args)
|
||||
{
|
||||
Debug("UnhandledExceptionEventSink: " + ((Exception)args.ExceptionObject).ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,8 @@ namespace MeshCentralRouter
|
||||
this.tlsCertFingerprint = tlsCertFingerprint;
|
||||
Uri proxyUri = null;
|
||||
|
||||
Debug("Websocket Start, URL=" + url.ToString());
|
||||
|
||||
// Check if we need to use a HTTP proxy (Auto-proxy way)
|
||||
try
|
||||
{
|
||||
@@ -130,6 +132,7 @@ namespace MeshCentralRouter
|
||||
if (proxyUri != null)
|
||||
{
|
||||
// Proxy in use
|
||||
Debug("Websocket proxyUri: " + proxyUri.ToString());
|
||||
proxyInUse = true;
|
||||
wsclient = new TcpClient();
|
||||
wsclient.BeginConnect(proxyUri.Host, proxyUri.Port, new AsyncCallback(OnConnectSink), this);
|
||||
@@ -137,6 +140,7 @@ namespace MeshCentralRouter
|
||||
else
|
||||
{
|
||||
// No proxy in use
|
||||
Debug("Websocket noProxy");
|
||||
proxyInUse = false;
|
||||
wsclient = new TcpClient();
|
||||
wsclient.BeginConnect(url.Host, url.Port, new AsyncCallback(OnConnectSink), this);
|
||||
@@ -461,17 +465,26 @@ namespace MeshCentralRouter
|
||||
|
||||
private bool VerifyServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
string hash1 = GetMeshKeyHash(certificate);
|
||||
string hash2 = certificate.GetCertHashString();
|
||||
Debug("VerifyServerCertificate: tlsCertFingerprint = " + ((tlsCertFingerprint == null) ? "NULL" : tlsCertFingerprint));
|
||||
Debug("VerifyServerCertificate: Hash1 = " + hash1);
|
||||
Debug("VerifyServerCertificate: Hash2 = " + hash2);
|
||||
return ((tlsCertFingerprint == GetMeshKeyHash(certificate)) || (tlsCertFingerprint == certificate.GetCertHashString()));
|
||||
}
|
||||
|
||||
public int SendString(string data)
|
||||
{
|
||||
if (state != ConnectionStates.Connected) return 0;
|
||||
Debug("WebSocketClient-SEND-String: " + data);
|
||||
byte[] buf = UTF8Encoding.UTF8.GetBytes(data);
|
||||
return SendFragment(buf, 0, buf.Length, 129);
|
||||
}
|
||||
|
||||
public int SendBinary(byte[] data, int offset, int len) { return SendFragment(data, offset, len, 130); }
|
||||
public int SendBinary(byte[] data, int offset, int len) {
|
||||
Debug("WebSocketClient-SEND-Binary-Len:" + len);
|
||||
return SendFragment(data, offset, len, 130);
|
||||
}
|
||||
|
||||
// Fragment op code (129 = text, 130 = binary)
|
||||
public int SendFragment(byte[] data, int offset, int len, byte op)
|
||||
|
||||
Reference in New Issue
Block a user