diff --git a/NOnion/Exceptions.fs b/NOnion/Exceptions.fs index 4cd21ff8..20c61b25 100644 --- a/NOnion/Exceptions.fs +++ b/NOnion/Exceptions.fs @@ -26,6 +26,9 @@ type CircuitTruncatedException internal (reason: DestroyReason) = type CircuitDestroyedException internal (reason: DestroyReason) = inherit NOnionException(sprintf "Circuit got destroyed, reason %A" reason) +type CircuitDecryptionFailedException internal () = + inherit NOnionException(sprintf "Circuit Decryption Failed") + type TimeoutErrorException internal () = inherit NOnionException("Time limit exceeded for operation") diff --git a/NOnion/Network/TorCircuit.fs b/NOnion/Network/TorCircuit.fs index 57c9f691..77748073 100644 --- a/NOnion/Network/TorCircuit.fs +++ b/NOnion/Network/TorCircuit.fs @@ -336,7 +336,8 @@ and TorCircuit node) | None -> announceDeath() - failwith "Decryption failed!" + + raise <| CircuitDecryptionFailedException() decryptMessage encryptedRelayCell.EncryptedData nodes | _ -> failwith "Unexpected state when receiving relay cell" diff --git a/NOnion/Network/TorGuard.fs b/NOnion/Network/TorGuard.fs index d32e9584..4bdcdb13 100644 --- a/NOnion/Network/TorGuard.fs +++ b/NOnion/Network/TorGuard.fs @@ -332,7 +332,7 @@ type TorGuard private (client: TcpClient, sslStream: SslStream) = try do! circuit.HandleIncomingCell cell with - | ex -> + | :? CircuitDecryptionFailedException as ex -> sprintf "TorGuard: exception when trying to handle incoming cell type=%i, ex=%s" cell.Command @@ -340,6 +340,7 @@ type TorGuard private (client: TcpClient, sslStream: SslStream) = |> TorLogger.Log self.KillChildCircuits() + | ex -> return raise <| FSharpUtil.ReRaise ex | None -> self.KillChildCircuits() failwithf "Unknown circuit, Id = %i" cid