Add verbose logging to log every connection
Note: - Added a configuration entry, user should add this by hand or reset from scratch. Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
@@ -505,19 +505,24 @@ namespace Shadowsocks.Controller
|
||||
case 1: // IPv4 address, 4 bytes
|
||||
dst_addr = new IPAddress(_connetionRecvBuffer.Skip(1).Take(4).ToArray()).ToString();
|
||||
dst_port = (_connetionRecvBuffer[5] << 8) + _connetionRecvBuffer[6];
|
||||
// Note by wongsyrone: this will be stripped out in Release version
|
||||
Logging.Debug($"connect to {dst_addr}:{dst_port}");
|
||||
if ( controller.GetCurrentConfiguration().isVerboseLogging ) {
|
||||
Logging.Info( $"connect to {dst_addr}:{dst_port}" );
|
||||
}
|
||||
break;
|
||||
case 3: // domain name, length + str
|
||||
int len = _connetionRecvBuffer[1];
|
||||
dst_addr = System.Text.Encoding.UTF8.GetString(_connetionRecvBuffer, 2, len);
|
||||
dst_port = (_connetionRecvBuffer[len + 2] << 8) + _connetionRecvBuffer[len + 3];
|
||||
Logging.Debug($"connect to {dst_addr}:{dst_port}");
|
||||
if ( controller.GetCurrentConfiguration().isVerboseLogging ) {
|
||||
Logging.Info( $"connect to {dst_addr}:{dst_port}" );
|
||||
}
|
||||
break;
|
||||
case 4: // IPv6 address, 16 bytes
|
||||
dst_addr = new IPAddress(_connetionRecvBuffer.Skip(1).Take(16).ToArray()).ToString();
|
||||
dst_port = (_connetionRecvBuffer[17] << 8) + _connetionRecvBuffer[18];
|
||||
Logging.Debug($"connect to [{dst_addr}]:{dst_port}");
|
||||
if ( controller.GetCurrentConfiguration().isVerboseLogging ) {
|
||||
Logging.Info( $"connect to [{dst_addr}]:{dst_port}" );
|
||||
}
|
||||
break;
|
||||
}
|
||||
int bytesToSend;
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace Shadowsocks.Controller
|
||||
public event EventHandler EnableStatusChanged;
|
||||
public event EventHandler EnableGlobalChanged;
|
||||
public event EventHandler ShareOverLANStatusChanged;
|
||||
public event EventHandler VerboseLoggingStatusChanged;
|
||||
public event EventHandler TrafficChanged;
|
||||
|
||||
// when user clicked Edit PAC, and PAC file has already created
|
||||
@@ -212,6 +213,15 @@ namespace Shadowsocks.Controller
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleVerboseLogging(bool enabled)
|
||||
{
|
||||
_config.isVerboseLogging = enabled;
|
||||
SaveConfig(_config);
|
||||
if ( VerboseLoggingStatusChanged != null ) {
|
||||
VerboseLoggingStatusChanged(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectServerIndex(int index)
|
||||
{
|
||||
_config.index = index;
|
||||
|
||||
@@ -22,6 +22,7 @@ Show QRCode...=显示二维码...
|
||||
Scan QRCode from Screen...=扫描屏幕上的二维码...
|
||||
Availability Statistics=统计可用性
|
||||
Show Logs...=显示日志...
|
||||
Verbose Logging=详细记录日志
|
||||
Updates...=更新...
|
||||
Check for Updates...=检查更新
|
||||
Check for Updates at Startup=启动时检查更新
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Shadowsocks.Model
|
||||
public bool useOnlinePac;
|
||||
public bool availabilityStatistics;
|
||||
public bool autoCheckUpdate;
|
||||
public bool isVerboseLogging;
|
||||
public LogViewerConfig logViewer;
|
||||
|
||||
private static string CONFIG_FILE = "gui-config.json";
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Shadowsocks.View
|
||||
private MenuItem editGFWUserRuleItem;
|
||||
private MenuItem editOnlinePACItem;
|
||||
private MenuItem autoCheckUpdatesToggleItem;
|
||||
private MenuItem VerboseLoggingToggleItem;
|
||||
private ConfigForm configForm;
|
||||
private List<LogForm> logForms = new List<LogForm>();
|
||||
private bool logFormsVisible = false;
|
||||
@@ -64,6 +65,7 @@ namespace Shadowsocks.View
|
||||
controller.PACFileReadyToOpen += controller_FileReadyToOpen;
|
||||
controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
|
||||
controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
|
||||
controller.VerboseLoggingStatusChanged += controller_VerboseLoggingStatusChanged;
|
||||
controller.EnableGlobalChanged += controller_EnableGlobalChanged;
|
||||
controller.Errored += controller_Errored;
|
||||
controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
|
||||
@@ -265,6 +267,7 @@ namespace Shadowsocks.View
|
||||
this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)),
|
||||
new MenuItem("-"),
|
||||
CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
|
||||
this.VerboseLoggingToggleItem = CreateMenuItem( "Verbose Logging", new EventHandler(this.VerboseLoggingToggleItem_Click) ),
|
||||
CreateMenuGroup("Updates...", new MenuItem[] {
|
||||
CreateMenuItem("Check for Updates...", new EventHandler(this.checkUpdatesItem_Click)),
|
||||
new MenuItem("-"),
|
||||
@@ -293,6 +296,10 @@ namespace Shadowsocks.View
|
||||
ShareOverLANItem.Checked = controller.GetConfigurationCopy().shareOverLan;
|
||||
}
|
||||
|
||||
void controller_VerboseLoggingStatusChanged(object sender, EventArgs e) {
|
||||
VerboseLoggingToggleItem.Checked = controller.GetConfigurationCopy().isVerboseLogging;
|
||||
}
|
||||
|
||||
void controller_EnableGlobalChanged(object sender, EventArgs e)
|
||||
{
|
||||
globalModeItem.Checked = controller.GetConfigurationCopy().global;
|
||||
@@ -369,6 +376,7 @@ namespace Shadowsocks.View
|
||||
globalModeItem.Checked = config.global;
|
||||
PACModeItem.Checked = !config.global;
|
||||
ShareOverLANItem.Checked = config.shareOverLan;
|
||||
VerboseLoggingToggleItem.Checked = config.isVerboseLogging;
|
||||
AutoStartupItem.Checked = AutoStartup.Check();
|
||||
onlinePACItem.Checked = onlinePACItem.Enabled && config.useOnlinePac;
|
||||
localPACItem.Checked = !onlinePACItem.Checked;
|
||||
@@ -576,6 +584,11 @@ namespace Shadowsocks.View
|
||||
logForms.Add(f);
|
||||
}
|
||||
|
||||
private void VerboseLoggingToggleItem_Click( object sender, EventArgs e ) {
|
||||
VerboseLoggingToggleItem.Checked = ! VerboseLoggingToggleItem.Checked;
|
||||
controller.ToggleVerboseLogging( VerboseLoggingToggleItem.Checked );
|
||||
}
|
||||
|
||||
private void StatisticsConfigItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
StatisticsStrategyConfigurationForm form = new StatisticsStrategyConfigurationForm(controller);
|
||||
|
||||
Reference in New Issue
Block a user