-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect Enhancements #833
Connect Enhancements #833
Changes from all commits
180c53e
d8cfdcb
90b8440
af72e19
9100944
5970183
4e9a7e7
ddc472d
d6e81ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1134,7 +1134,15 @@ private void processConnectInit(Srv s) | |
try | ||
{ | ||
conn.ReceiveTimeout = opts.Timeout; | ||
processExpectedInfo(s); | ||
if (!opts.TlsFirst) | ||
{ | ||
processExpectedInfo(); | ||
} | ||
checkForSecure(s); | ||
if (opts.TlsFirst) | ||
{ | ||
processExpectedInfo(); | ||
} | ||
sendConnect(); | ||
} | ||
catch (IOException ex) | ||
|
@@ -1188,8 +1196,10 @@ internal bool connect(Srv s, out Exception exToThrow) | |
} | ||
catch (NATSConnectionException ex) | ||
{ | ||
if (!ex.IsAuthorizationViolationError() && !ex.IsAuthenticationExpiredError()) | ||
if (!ex.IsAuthenticationOrAuthorizationError()) | ||
{ | ||
throw; | ||
} | ||
scottf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ScheduleErrorEvent(s, ex); | ||
|
||
|
@@ -1222,7 +1232,7 @@ internal void ScheduleErrorEvent(object sender, NATSException ex, Subscription s | |
opts.AsyncErrorEventHandlerOrDefault(sender, new ErrEventArgs(this, subscription, ex.Message))); | ||
} | ||
|
||
internal void connect() | ||
internal void connect(bool reconnectOnConnect) | ||
{ | ||
Exception exToThrow = null; | ||
|
||
|
@@ -1234,11 +1244,22 @@ internal void connect() | |
{ | ||
if (status != ConnState.CONNECTED) | ||
{ | ||
if (exToThrow is NATSException) | ||
throw exToThrow; | ||
if (exToThrow != null) | ||
throw new NATSConnectionException("Failed to connect", exToThrow); | ||
throw new NATSNoServersException("Unable to connect to a server."); | ||
if (reconnectOnConnect) | ||
{ | ||
doReconnect(); | ||
} | ||
scottf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
{ | ||
if (exToThrow is NATSException) | ||
{ | ||
throw exToThrow; | ||
} | ||
if (exToThrow != null) | ||
{ | ||
throw new NATSConnectionException("Failed to connect", exToThrow); | ||
} | ||
throw new NATSNoServersException("Unable to connect to a server."); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -1248,17 +1269,20 @@ internal void connect() | |
// only be called after the INIT protocol has been received. | ||
private void checkForSecure(Srv s) | ||
{ | ||
// Check to see if we need to engage TLS | ||
// Check for mismatch in setups | ||
if (Opts.Secure && !info.TlsRequired) | ||
{ | ||
throw new NATSSecureConnWantedException(); | ||
} | ||
else if (info.TlsRequired && !Opts.Secure) | ||
if (!Opts.TlsFirst) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if tlsFirst, it will always be secure |
||
{ | ||
// If the server asks us to be secure, give it | ||
// a shot. | ||
Opts.Secure = true; | ||
// Check to see if we need to engage TLS | ||
// Check for mismatch in setups | ||
if (Opts.Secure && !info.TlsRequired) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
throw new NATSSecureConnWantedException(); | ||
} | ||
else if (info.TlsRequired && !Opts.Secure) | ||
{ | ||
// If the server asks us to be secure, give it | ||
// a shot. | ||
Opts.Secure = true; | ||
} | ||
} | ||
|
||
// Need to rewrap with bufio if options tell us we need | ||
|
@@ -1272,10 +1296,9 @@ private void checkForSecure(Srv s) | |
// processExpectedInfo will look for the expected first INFO message | ||
// sent when a connection is established. The lock should be held entering. | ||
// Caller must lock. | ||
private void processExpectedInfo(Srv s) | ||
private void processExpectedInfo() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need the Srv parameter since that work is now done outside this function |
||
{ | ||
Control c; | ||
|
||
try | ||
{ | ||
conn.SendTimeout = 2; | ||
|
@@ -1298,7 +1321,6 @@ private void processExpectedInfo(Srv s) | |
|
||
// do not notify listeners of server changes when we process the first INFO message | ||
processInfo(c.args, false); | ||
checkForSecure(s); | ||
scottf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
internal void SendUnsub(long sid, int max) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tls first, don't check/process the server info.
checkForSecure
used to be the last thing inprocessExpectedInfo
. I moved it out so I could do it on either side. I supposed I could have done the change insideprocessExpectedInfo
but this matches the java code