Ssh Connect() now spins up new clients. Seems to be helping deal with connection failures

This commit is contained in:
Heath Volmer
2016-12-06 16:02:49 -07:00
parent d7613d2f52
commit 15cd23a857
7 changed files with 32 additions and 31 deletions

View File

@@ -126,10 +126,10 @@ namespace PepperDash.Core
CTimer ReconnectTimer; CTimer ReconnectTimer;
string PreviousHostname; //string PreviousHostname;
int PreviousPort; //int PreviousPort;
string PreviousUsername; //string PreviousUsername;
string PreviousPassword; //string PreviousPassword;
/// <summary> /// <summary>
/// Typical constructor. /// Typical constructor.
@@ -213,37 +213,37 @@ namespace PepperDash.Core
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(Username, Password); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(Username, Password);
// Make a new client if we need it or things have changed // Make a new client if we need it or things have changed
if (Client == null || PropertiesHaveChanged()) //if (Client == null || PropertiesHaveChanged())
{ //{
if (Client != null) if (Client != null)
{ {
Debug.Console(2, this, "Cleaning up disconnected client"); Debug.Console(2, this, "Cleaning up disconnected client");
Client.ErrorOccurred -= Client_ErrorOccurred; Client.ErrorOccurred -= Client_ErrorOccurred;
if (TheStream != null) KillStream();
{
TheStream.DataReceived -= Stream_DataReceived; //if (TheStream != null)
TheStream.ErrorOccurred -= TheStream_ErrorOccurred; //{
} // TheStream.DataReceived -= Stream_DataReceived;
TheStream = null; // TheStream.ErrorOccurred -= TheStream_ErrorOccurred;
//}
//TheStream = null;
} }
Debug.Console(2, this, "Creating new SshClient"); Debug.Console(2, this, "Creating new SshClient");
ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth); ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth);
Client = new SshClient(connectionInfo); Client = new SshClient(connectionInfo);
Client.ErrorOccurred += Client_ErrorOccurred; Client.ErrorOccurred += Client_ErrorOccurred;
} //}
PreviousHostname = Hostname; //PreviousHostname = Hostname;
PreviousPassword = Password; //PreviousPassword = Password;
PreviousPort = Port; //PreviousPort = Port;
PreviousUsername = Username; //PreviousUsername = Username;
//You can do it! //You can do it!
ClientStatus = SocketStatus.SOCKET_STATUS_WAITING; ClientStatus = SocketStatus.SOCKET_STATUS_WAITING;
try try
{ {
Client.Connect(); Client.Connect();
#warning We are getting past here with a false IsConnected when it appears to be connected
// Have to assume client is connected cause Client.IsConnected is busted in some cases // Have to assume client is connected cause Client.IsConnected is busted in some cases
// All other conditions *should* error out... // All other conditions *should* error out...
@@ -256,10 +256,10 @@ namespace PepperDash.Core
TheStream.ErrorOccurred += TheStream_ErrorOccurred; TheStream.ErrorOccurred += TheStream_ErrorOccurred;
Debug.Console(1, this, "Connected"); Debug.Console(1, this, "Connected");
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED; ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
PreviousHostname = Hostname; //PreviousHostname = Hostname;
PreviousPassword = Password; //PreviousPassword = Password;
PreviousPort = Port; //PreviousPort = Port;
PreviousUsername = Username; //PreviousUsername = Username;
//} //}
return; // Success will not pass here return; // Success will not pass here
} }
@@ -305,6 +305,7 @@ namespace PepperDash.Core
} }
KillStream(); KillStream();
Client.Disconnect(); Client.Disconnect();
Client = null;
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY; ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY;
Debug.Console(1, this, "Disconnected"); Debug.Console(1, this, "Disconnected");
} }
@@ -352,11 +353,11 @@ namespace PepperDash.Core
} }
} }
bool PropertiesHaveChanged() //bool PropertiesHaveChanged()
{ //{
return Hostname != PreviousHostname || Port != PreviousPort // return Hostname != PreviousHostname || Port != PreviousPort
|| Username != PreviousUsername || Password != PreviousPassword; // || Username != PreviousUsername || Password != PreviousPassword;
} //}
/// <summary> /// <summary>
/// Handles the keyboard interactive authentication, should it be required. /// Handles the keyboard interactive authentication, should it be required.

View File

@@ -10,8 +10,8 @@
<ArchiveName /> <ArchiveName />
</RequiredInfo> </RequiredInfo>
<OptionalInfo> <OptionalInfo>
<CompiledOn>12/6/2016 2:53:00 PM</CompiledOn> <CompiledOn>12/6/2016 3:50:54 PM</CompiledOn>
<CompilerRev>1.0.0.26789</CompilerRev> <CompilerRev>1.0.0.28526</CompilerRev>
</OptionalInfo> </OptionalInfo>
<Plugin> <Plugin>
<Version>Crestron.SIMPLSharp, Version=2.0.48.0, Culture=neutral, PublicKeyToken=812d080f93e2de10</Version> <Version>Crestron.SIMPLSharp, Version=2.0.48.0, Culture=neutral, PublicKeyToken=812d080f93e2de10</Version>

View File

@@ -1,4 +1,4 @@
MainAssembly=PepperDash_Core.dll:3a5fe881bafa819e1046cf092f48b180 MainAssembly=PepperDash_Core.dll:2fe05eb2518594f4d27bd9ae43dc7a02
MainAssemblyMinFirmwareVersion=1.007.0017 MainAssemblyMinFirmwareVersion=1.007.0017
MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e
ü ü