From ff391a8af3626787e437d4c5265bdcef187ea8c7 Mon Sep 17 00:00:00 2001 From: parham saremi <45370204+parhamsaremi@users.noreply.github.com> Date: Fri, 11 Nov 2022 18:40:16 +0330 Subject: [PATCH] Network: return exception when addresses is empty (#50) This fix is necessary for fixing [1]. [1] https://github.com/nblockchain/geewallet/issues/186 --- NOnion/Network/TorGuard.fs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/NOnion/Network/TorGuard.fs b/NOnion/Network/TorGuard.fs index 33bf4a45..4ffb5834 100644 --- a/NOnion/Network/TorGuard.fs +++ b/NOnion/Network/TorGuard.fs @@ -356,16 +356,25 @@ type TorGuard private (client: TcpClient, sslStream: SslStream) = //TODO: Client authentication isn't implemented yet! do! self.ReceiveExpected() |> Async.Ignore let! netInfo = self.ReceiveExpected() + let maybeOtherAddress = netInfo.MyAddresses |> Seq.tryHead - do! - self.Send - Constants.DefaultCircuitId - { - CellNetInfo.Time = - DateTimeUtils.ToUnixTimestamp DateTime.UtcNow - OtherAddress = netInfo.MyAddresses |> Seq.head - MyAddresses = List.singleton netInfo.OtherAddress - } + match maybeOtherAddress with + | None -> + return + raise + <| GuardConnectionFailedException( + "TorGuard.Handshake: problem in initializing the handshake process" + ) + | Some otherAddress -> + do! + self.Send + Constants.DefaultCircuitId + { + CellNetInfo.Time = + DateTimeUtils.ToUnixTimestamp DateTime.UtcNow + OtherAddress = otherAddress + MyAddresses = List.singleton netInfo.OtherAddress + } TorLogger.Log "TorGuard: finished handshake process" //TODO: do security checks on handshake data