protected Result GetResultForErrorCode(int c) {
Result result = Result.ProtocolError;
if( c == (int)ErrorMessage.ErrorCode.InProgress ) {
result = Result.RetryThisTA;
}
else if ( c == (int)ErrorMessage.ErrorCode.AlreadyConnected ) {
/*
* The other side thinks we are already connected. This is
* odd, let's see if we agree
*/
Address target = _linker.Target;
ConnectionTable tab = _node.ConnectionTable;
if( target == null ) {
//This can happen with leaf connections. In this case, we
//should move on to another TA.
result = Result.MoveToNextTA;
}
else if( tab.Contains( Connection.StringToMainType( _contype ), target) ) {
//This shouldn't happen
result = Result.ProtocolError;
if(ProtocolLog.LinkDebug.Enabled)
ProtocolLog.Write(ProtocolLog.LinkDebug, String.Format(
"Already connected: {0}, {1}", _contype));
}
else {
//The other guy thinks we are connected, but we disagree,
//let's retry. This can happen if we get disconnected
//and reconnect, but the other node hasn't realized we
//are disconnected.
result = Result.RetryThisTA;
}
}
else if ( c == (int)ErrorMessage.ErrorCode.TargetMismatch ) {
/*
* This could happen in some NAT cases, or perhaps due to
* some other as of yet undiagnosed bug.
*
* Move to the next TA since this TA definitely connects to
* the wrong guy.
*/
if(ProtocolLog.LinkDebug.Enabled)
ProtocolLog.Write(ProtocolLog.LinkDebug, String.Format(
"LPS: from {0} target mismatch", _e));
result = Result.MoveToNextTA;
}
else if ( c == (int)ErrorMessage.ErrorCode.ConnectToSelf ) {
/*
* Somehow we connected to ourself, this TA is no good.
*/
result = Result.MoveToNextTA;
}
else if ( c == (int)ErrorMessage.ErrorCode.Disconnecting ) {
/* The other node is going offline */
if( _linker.Target == null ) {
result = Result.MoveToNextTA;
} else {
result = Result.ProtocolError; //Give up now
}
}
else {
if(ProtocolLog.LinkDebug.Enabled)
ProtocolLog.Write(ProtocolLog.LinkDebug, String.Format(
"Unrecognized error code: {0}", c));
}
return result;
}