From e89b2c0f3eb8af75a7117f50a0e4384b6f22d407 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Wed, 31 May 2023 12:18:41 +0200 Subject: [PATCH] Network,Directory,Http: naming scheme for async Rename TorStream, TorCircuit, TorGuard, TorDirectory, and TorHttpClient methods according to the following scheme: for method is called Foo Foo() should return 'T FooAsync() should return Task<'T> AsyncFoo() should return Async<'T>. --- NOnion/Directory/TorDirectory.fs | 71 ++++++++++++++++------------- NOnion/Http/TorHttpClient.fs | 6 +-- NOnion/Network/TorCircuit.fs | 30 ++++++------ NOnion/Network/TorGuard.fs | 16 +++---- NOnion/Network/TorStream.fs | 38 ++++++++------- NOnion/Services/TorServiceClient.fs | 48 +++++++++---------- NOnion/Services/TorServiceHost.fs | 55 ++++++++++++---------- 7 files changed, 142 insertions(+), 122 deletions(-) diff --git a/NOnion/Directory/TorDirectory.fs b/NOnion/Directory/TorDirectory.fs index 7e03a77a..021c340e 100644 --- a/NOnion/Directory/TorDirectory.fs +++ b/NOnion/Directory/TorDirectory.fs @@ -101,13 +101,13 @@ type TorDirectory = ) use keyRetrievalStream = new TorStream(circuit) - do! keyRetrievalStream.ConnectToDirectory() |> Async.Ignore + do! keyRetrievalStream.AsyncConnectToDirectory() |> Async.Ignore let httpClient = TorHttpClient(keyRetrievalStream, Constants.DefaultHttpHost) let! downloadedKeys = - httpClient.GetAsString + httpClient.AsyncGetAsString (sprintf "/tor/keys/fp-sk/%s" (String.Join("+", keysToDownload))) @@ -168,11 +168,11 @@ type TorDirectory = return () } - member self.GetMicroDescriptorByIdentity + member self.AsyncGetMicroDescriptorByIdentity (identity: string) : Async = async { - let! networkStatus = self.GetLiveNetworkStatus() + let! networkStatus = self.AsyncGetLiveNetworkStatus() let routerConsensusEntryOpt = networkStatus.Routers @@ -193,7 +193,7 @@ type TorDirectory = let directoryRouter = self.GetRandomDirectorySource() use! guard = - TorGuard.NewClient( + TorGuard.AsyncNewClient( IPEndPoint( IPAddress.Parse(directoryRouter.IP.Value), directoryRouter.OnionRouterPort.Value @@ -210,16 +210,16 @@ type TorDirectory = * until 1 week after key update). *) do! - circuit.Create CircuitNodeDetail.FastCreate + circuit.AsyncCreate CircuitNodeDetail.FastCreate |> Async.Ignore - do! stream.ConnectToDirectory() |> Async.Ignore + do! stream.AsyncConnectToDirectory() |> Async.Ignore let httpClient = TorHttpClient(stream, directoryRouter.IP.Value) let! response = - httpClient.GetAsString + httpClient.AsyncGetAsString (sprintf "/tor/micro/d/%s" routerConsensusEntry.MicroDescriptorDigest.Value) @@ -246,7 +246,7 @@ type TorDirectory = member private self.GetRouterDetailByIdentity(identity: string) = async { - let! networkStatus = self.GetLiveNetworkStatus() + let! networkStatus = self.AsyncGetLiveNetworkStatus() let routerEntryOpt = networkStatus.Routers @@ -258,7 +258,8 @@ type TorDirectory = failwith "TorDirectory::GetRouterDetailByIdentity: router was not in the latest consensus" | Some routerEntry -> - let! descriptor = self.GetMicroDescriptorByIdentity identity + let! descriptor = + self.AsyncGetMicroDescriptorByIdentity identity let fingerprintBytes = Base64Util.FromString(routerEntry.GetIdentity()) @@ -282,7 +283,7 @@ type TorDirectory = } - member self.GetRouter(filter: RouterType) = + member self.AsyncGetRouter(filter: RouterType) = async { do! self.UpdateConsensusIfNotLive() @@ -313,9 +314,9 @@ type TorDirectory = } member self.GetRouterAsync(filter: RouterType) = - self.GetRouter filter |> Async.StartAsTask + self.AsyncGetRouter filter |> Async.StartAsTask - member self.GetCircuitNodeDetailByIdentity(identity: string) = + member self.AsyncGetCircuitNodeDetailByIdentity(identity: string) = async { let! _endpoint, circuitNodeDetail = self.GetRouterDetailByIdentity identity @@ -336,7 +337,7 @@ type TorDirectory = let directoryRouter = self.GetRandomDirectorySource() use! guard = - TorGuard.NewClient( + TorGuard.AsyncNewClient( IPEndPoint( IPAddress.Parse(directoryRouter.IP.Value), directoryRouter.OnionRouterPort.Value @@ -352,14 +353,16 @@ type TorDirectory = * are no more than one week old (according to spec, routers must accept outdated keys * until 1 week after key update). *) - do! circuit.Create CircuitNodeDetail.FastCreate |> Async.Ignore + do! + circuit.AsyncCreate CircuitNodeDetail.FastCreate + |> Async.Ignore - do! stream.ConnectToDirectory() |> Async.Ignore + do! stream.AsyncConnectToDirectory() |> Async.Ignore let httpClient = TorHttpClient(stream, directoryRouter.IP.Value) let! response = - httpClient.GetAsString + httpClient.AsyncGetAsString "/tor/status-vote/current/consensus-microdesc" false @@ -370,7 +373,7 @@ type TorDirectory = self.NetworkStatus <- networkStatus } - static member BootstrapWithGuard + static member AsyncBootstrapWithGuard (guard: TorGuard) (cacheDirectory: DirectoryInfo) = @@ -381,11 +384,14 @@ type TorDirectory = let circuit = TorCircuit guard do! - circuit.Create CircuitNodeDetail.FastCreate + circuit.AsyncCreate CircuitNodeDetail.FastCreate |> Async.Ignore use consensusStream = new TorStream(circuit) - do! consensusStream.ConnectToDirectory() |> Async.Ignore + + do! + consensusStream.AsyncConnectToDirectory() + |> Async.Ignore let consensusHttpClient = TorHttpClient( @@ -394,7 +400,7 @@ type TorDirectory = ) let! consensusStr = - consensusHttpClient.GetAsString + consensusHttpClient.AsyncGetAsString "/tor/status-vote/current/consensus-microdesc" false @@ -470,7 +476,7 @@ type TorDirectory = let circuit = TorCircuit guard do! - circuit.Create CircuitNodeDetail.FastCreate + circuit.AsyncCreate CircuitNodeDetail.FastCreate |> Async.Ignore let downloadDescriptorsForChunk @@ -480,7 +486,7 @@ type TorDirectory = use descriptorsStream = new TorStream(circuit) do! - descriptorsStream.ConnectToDirectory() + descriptorsStream.AsyncConnectToDirectory() |> Async.Ignore let descriptorsHttpClient = @@ -490,7 +496,7 @@ type TorDirectory = ) let! descriptorsStr = - descriptorsHttpClient.GetAsString + descriptorsHttpClient.AsyncGetAsString (sprintf "/tor/micro/d/%s" (String.concat "-" digestsChunk)) @@ -541,16 +547,16 @@ type TorDirectory = } - static member Bootstrap + static member AsyncBootstrap (nodeEndPoint: IPEndPoint) (cacheDirectory: DirectoryInfo) = async { - use! guard = TorGuard.NewClient nodeEndPoint - return! TorDirectory.BootstrapWithGuard guard cacheDirectory + use! guard = TorGuard.AsyncNewClient nodeEndPoint + return! TorDirectory.AsyncBootstrapWithGuard guard cacheDirectory } - member self.GetLiveNetworkStatus() = + member self.AsyncGetLiveNetworkStatus() = async { do! self.UpdateConsensusIfNotLive() return self.NetworkStatus @@ -572,17 +578,18 @@ type TorDirectory = nodeEndPoint: IPEndPoint, cacheDirectory: DirectoryInfo ) = - TorDirectory.Bootstrap nodeEndPoint cacheDirectory |> Async.StartAsTask + TorDirectory.AsyncBootstrap nodeEndPoint cacheDirectory + |> Async.StartAsTask static member BootstrapWithGuardAsync ( guard: TorGuard, cacheDirectory: DirectoryInfo ) = - TorDirectory.BootstrapWithGuard guard cacheDirectory + TorDirectory.AsyncBootstrapWithGuard guard cacheDirectory |> Async.StartAsTask - member self.GetResponsibleHiddenServiceDirectories + member self.AsyncGetResponsibleHiddenServiceDirectories (blindedPublicKey: array) (sharedRandomValue: string) (periodNumber: uint64) @@ -591,7 +598,7 @@ type TorDirectory = = async { - let! networkStatus = self.GetLiveNetworkStatus() + let! networkStatus = self.AsyncGetLiveNetworkStatus() let ByteArrayCompare (x: array) (y: array) = let xlen = x.Length diff --git a/NOnion/Http/TorHttpClient.fs b/NOnion/Http/TorHttpClient.fs index 6b3ea42d..2ca7531a 100644 --- a/NOnion/Http/TorHttpClient.fs +++ b/NOnion/Http/TorHttpClient.fs @@ -15,7 +15,7 @@ type TorHttpClient(stream: Stream, host: string) = let ReceiveAll memStream = stream.CopyToAsync memStream |> Async.AwaitTask - member __.GetAsString (path: string) (forceUncompressed: bool) = + member __.AsyncGetAsString (path: string) (forceUncompressed: bool) = async { let headers = let supportedCompressionAlgorithms = @@ -115,7 +115,7 @@ type TorHttpClient(stream: Stream, host: string) = compressionMethod } - member __.PostString (path: string) (payload: string) = + member __.AsyncPostString (path: string) (payload: string) = async { let headers = [ @@ -204,4 +204,4 @@ type TorHttpClient(stream: Stream, host: string) = } member self.GetAsStringAsync path forceUncompressed = - self.GetAsString path forceUncompressed |> Async.StartAsTask + self.AsyncGetAsString path forceUncompressed |> Async.StartAsTask diff --git a/NOnion/Network/TorCircuit.fs b/NOnion/Network/TorCircuit.fs index 39edec50..7071cf73 100644 --- a/NOnion/Network/TorCircuit.fs +++ b/NOnion/Network/TorCircuit.fs @@ -223,7 +223,7 @@ and TorCircuit |> encryptMessage onionList Early = early } - |> guard.Send circuitId + |> guard.AsyncSend circuitId match relayData with | RelayData _ @@ -656,7 +656,7 @@ and TorCircuit connectionCompletionSource ) - do! guard.Send circuitId handshakeCell + do! guard.AsyncSend circuitId handshakeCell TorLogger.Log( sprintf @@ -1072,7 +1072,7 @@ and TorCircuit failwith "Should not happen: can't get circuitId for non-initialized circuit." - member __.GetLastNode() = + member __.AsyncGetLastNode() = async { let! lastNodeResult = circuitOperationsMailBox.PostAndAsyncReply @@ -1081,7 +1081,7 @@ and TorCircuit return UnwrapResult lastNodeResult } - member __.SendRelayCell + member __.AsyncSendRelayCell (streamId: uint16) (relayData: RelayData) (customDestinationOpt: Option) @@ -1100,7 +1100,7 @@ and TorCircuit return UnwrapResult sendResult } - member self.Create(guardDetailOpt: CircuitNodeDetail) = + member self.AsyncCreate(guardDetailOpt: CircuitNodeDetail) = async { let! completionTaskRes = circuitOperationsMailBox.PostAndAsyncReply( @@ -1121,7 +1121,7 @@ and TorCircuit |> FSharpUtil.WithTimeout Constants.CircuitOperationTimeout } - member __.Extend(nodeDetail: CircuitNodeDetail) = + member __.AsyncExtend(nodeDetail: CircuitNodeDetail) = async { let! completionTaskRes = circuitOperationsMailBox.PostAndAsyncReply( @@ -1138,7 +1138,7 @@ and TorCircuit |> FSharpUtil.WithTimeout Constants.CircuitOperationTimeout } - member __.RegisterAsIntroductionPoint + member __.AsyncRegisterAsIntroductionPoint (authKeyPairOpt: Option) callback disconnectionCallback @@ -1164,7 +1164,7 @@ and TorCircuit |> FSharpUtil.WithTimeout Constants.CircuitOperationTimeout } - member __.RegisterAsRendezvousPoint(cookie: array) = + member __.AsyncRegisterAsRendezvousPoint(cookie: array) = async { let! completionTaskRes = circuitOperationsMailBox.PostAndAsyncReply( @@ -1186,12 +1186,12 @@ and TorCircuit } member self.ExtendAsync nodeDetail = - self.Extend nodeDetail |> Async.StartAsTask + self.AsyncExtend nodeDetail |> Async.StartAsTask member self.CreateAsync guardDetailOpt = - self.Create guardDetailOpt |> Async.StartAsTask + self.AsyncCreate guardDetailOpt |> Async.StartAsTask - member __.Introduce(introduceMsg: RelayIntroduce) = + member __.AsyncIntroduce(introduceMsg: RelayIntroduce) = async { let! completionTaskRes = circuitOperationsMailBox.PostAndAsyncReply( @@ -1211,7 +1211,7 @@ and TorCircuit |> FSharpUtil.WithTimeout Constants.CircuitOperationTimeout } - member __.WaitingForRendezvousJoin + member __.AsyncWaitingForRendezvousJoin (clientRandomPrivateKey: X25519PrivateKeyParameters) (clientRandomPublicKey: X25519PublicKeyParameters) (introAuthPublicKey: Ed25519PublicKeyParameters) @@ -1240,7 +1240,7 @@ and TorCircuit } - member __.Rendezvous + member __.AsyncRendezvous (cookie: array) (clientRandomKey: X25519PublicKeyParameters) (introAuthPublicKey: Ed25519PublicKeyParameters) @@ -1280,14 +1280,14 @@ and TorCircuit let disconnectCallback = fun () -> disconnectCallback.Invoke() - self.RegisterAsIntroductionPoint + self.AsyncRegisterAsIntroductionPoint authKeyPairOpt introduceCallback disconnectCallback |> Async.StartAsTask member self.RegisterAsRendezvousPointAsync(cookie: array) = - self.RegisterAsRendezvousPoint cookie |> Async.StartAsTask + self.AsyncRegisterAsRendezvousPoint cookie |> Async.StartAsTask member internal __.RegisterStream (stream: ITorStream) diff --git a/NOnion/Network/TorGuard.fs b/NOnion/Network/TorGuard.fs index 8450be42..9b26ea34 100644 --- a/NOnion/Network/TorGuard.fs +++ b/NOnion/Network/TorGuard.fs @@ -181,20 +181,20 @@ type TorGuard return guard } - static member NewClientWithIdentity ipEndpoint fingerprintOpt = + static member AsyncNewClientWithIdentity ipEndpoint fingerprintOpt = TorGuard.InnerNewClient ipEndpoint fingerprintOpt static member NewClientWithIdentityAsync ipEndpoint fingerprintOpt = - TorGuard.NewClientWithIdentity ipEndpoint fingerprintOpt + TorGuard.AsyncNewClientWithIdentity ipEndpoint fingerprintOpt |> Async.StartAsTask - static member NewClient ipEndpoint = + static member AsyncNewClient ipEndpoint = TorGuard.InnerNewClient ipEndpoint None static member NewClientAsync ipEndpoint = - TorGuard.NewClient ipEndpoint |> Async.StartAsTask + TorGuard.AsyncNewClient ipEndpoint |> Async.StartAsTask - member self.Send (circuitId: uint16) (cellToSend: ICell) = + member self.AsyncSend (circuitId: uint16) (cellToSend: ICell) = async { let! sendResult = sendMailBox.PostAndAsyncReply(fun replyChannel -> @@ -213,7 +213,7 @@ type TorGuard } member self.SendAsync (circuidId: uint16) (cellToSend: ICell) = - self.Send circuidId cellToSend |> Async.StartAsTask + self.AsyncSend circuidId cellToSend |> Async.StartAsTask member private __.ReceiveInternal() = async { @@ -487,7 +487,7 @@ type TorGuard TorLogger.Log "TorGuard: started handshake process" do! - self.Send + self.AsyncSend Constants.DefaultCircuitId { CellVersions.Versions = @@ -521,7 +521,7 @@ type TorGuard "Expected router address is not listed in NETINFO" do! - self.Send + self.AsyncSend Constants.DefaultCircuitId { //Clients SHOULD send "0" as their timestamp, to avoid fingerprinting. diff --git a/NOnion/Network/TorStream.fs b/NOnion/Network/TorStream.fs index 4fc2ec27..2e40701d 100644 --- a/NOnion/Network/TorStream.fs +++ b/NOnion/Network/TorStream.fs @@ -71,7 +71,7 @@ type TorStream(circuit: TorCircuit) = match streamState with | Connected streamId -> do! - circuit.SendRelayCell + circuit.AsyncSendRelayCell streamId (RelayEnd EndReason.Done) None @@ -99,11 +99,11 @@ type TorStream(circuit: TorCircuit) = match Seq.tryHeadTail dataChunks with | None -> () | Some(head, nextDataChunks) -> - let! lastNode = circuit.GetLastNode() + let! lastNode = circuit.AsyncGetLastNode() lastNode.Window.PackageDecrease() do! - circuit.SendRelayCell + circuit.AsyncSendRelayCell streamId (head |> Seq.toArray @@ -138,7 +138,7 @@ type TorStream(circuit: TorCircuit) = |> TorLogger.Log do! - circuit.SendRelayCell + circuit.AsyncSendRelayCell streamId (RelayBegin { @@ -165,7 +165,7 @@ type TorStream(circuit: TorCircuit) = |> TorLogger.Log do! - circuit.SendRelayCell + circuit.AsyncSendRelayCell streamId RelayData.RelayBeginDirectory None @@ -218,7 +218,7 @@ type TorStream(circuit: TorCircuit) = match streamState with | Connected streamId -> return! - circuit.SendRelayCell + circuit.AsyncSendRelayCell streamId RelayData.RelaySendMe None @@ -432,14 +432,18 @@ type TorStream(circuit: TorCircuit) = override _.Flush() = () - static member Accept (streamId: uint16) (circuit: TorCircuit) = + static member AsyncAccept (streamId: uint16) (circuit: TorCircuit) = async { // We can't use the "use" keyword since this stream needs // to outlive this function. let stream = new TorStream(circuit) - do! stream.RegisterIncomingStream streamId + do! stream.AsyncRegisterIncomingStream streamId - do! circuit.SendRelayCell streamId (RelayConnected Array.empty) None + do! + circuit.AsyncSendRelayCell + streamId + (RelayConnected Array.empty) + None sprintf "TorStream[%i,%i]: incoming stream accepted" @@ -450,7 +454,7 @@ type TorStream(circuit: TorCircuit) = return stream } - member __.End() = + member __.AsyncEnd() = async { let! sendResult = streamControlMailBox.PostAndAsyncReply StreamControlMessage.End @@ -459,9 +463,9 @@ type TorStream(circuit: TorCircuit) = } member self.EndAsync() = - self.End() |> Async.StartAsTask + self.AsyncEnd() |> Async.StartAsTask - member self.ConnectToService(port: int) = + member self.AsyncConnectToService(port: int) = async { let! completionTaskRes = streamControlMailBox.PostAndAsyncReply( @@ -482,7 +486,7 @@ type TorStream(circuit: TorCircuit) = |> FSharpUtil.WithTimeout Constants.StreamCreationTimeout } - member self.ConnectToDirectory() = + member self.AsyncConnectToDirectory() = async { let! completionTaskResult = streamControlMailBox.PostAndAsyncReply( @@ -503,9 +507,9 @@ type TorStream(circuit: TorCircuit) = } member self.ConnectToDirectoryAsync() = - self.ConnectToDirectory() |> Async.StartAsTask + self.AsyncConnectToDirectory() |> Async.StartAsTask - member self.ConnectToOutside (address: string) (port: int) = + member self.AsyncConnectToOutside (address: string) (port: int) = async { let! completionTaskRes = streamControlMailBox.PostAndAsyncReply( @@ -527,9 +531,9 @@ type TorStream(circuit: TorCircuit) = } member self.ConnectToOutsideAsync(address, port) = - self.ConnectToOutside address port |> Async.StartAsTask + self.AsyncConnectToOutside address port |> Async.StartAsTask - member private self.RegisterIncomingStream(streamId: uint16) = + member private self.AsyncRegisterIncomingStream(streamId: uint16) = async { let! registerationResult = streamControlMailBox.PostAndAsyncReply(fun replyChannel -> diff --git a/NOnion/Services/TorServiceClient.fs b/NOnion/Services/TorServiceClient.fs index 9264dfbc..f17a4956 100644 --- a/NOnion/Services/TorServiceClient.fs +++ b/NOnion/Services/TorServiceClient.fs @@ -38,7 +38,7 @@ type TorServiceClient = let getIntroductionPointInfo() = async { - let! networkStatus = directory.GetLiveNetworkStatus() + let! networkStatus = directory.AsyncGetLiveNetworkStatus() let periodNum, periodLength = networkStatus.GetTimePeriod() let srv = networkStatus.GetCurrentSRVForClient() @@ -49,7 +49,7 @@ type TorServiceClient = publicKey let! responsibleDirs = - directory.GetResponsibleHiddenServiceDirectories + directory.AsyncGetResponsibleHiddenServiceDirectories blindedPublicKey srv periodNum @@ -65,17 +65,19 @@ type TorServiceClient = | hsDirectory :: tail -> try let! guardEndPoint, randomGuardNode = - directory.GetRouter RouterType.Guard + directory.AsyncGetRouter + RouterType.Guard let! _, randomMiddleNode = - directory.GetRouter RouterType.Normal + directory.AsyncGetRouter + RouterType.Normal let! hsDirectoryNode = - directory.GetCircuitNodeDetailByIdentity + directory.AsyncGetCircuitNodeDetailByIdentity hsDirectory use! guardNode = - TorGuard.NewClientWithIdentity + TorGuard.AsyncNewClientWithIdentity guardEndPoint (randomGuardNode.GetIdentityKey() |> Some) @@ -83,22 +85,22 @@ type TorServiceClient = let circuit = TorCircuit guardNode do! - circuit.Create randomGuardNode + circuit.AsyncCreate randomGuardNode |> Async.Ignore do! - circuit.Extend randomMiddleNode + circuit.AsyncExtend randomMiddleNode |> Async.Ignore try do! - circuit.Extend hsDirectoryNode + circuit.AsyncExtend hsDirectoryNode |> Async.Ignore use dirStream = new TorStream(circuit) do! - dirStream.ConnectToDirectory() + dirStream.AsyncConnectToDirectory() |> Async.Ignore let! documentInString = @@ -106,7 +108,7 @@ type TorServiceClient = dirStream, Constants.DefaultHttpHost ) - .GetAsString + .AsyncGetAsString (sprintf "/tor/hs/%i/%s" Constants.HiddenServices.Version @@ -394,21 +396,21 @@ type TorServiceClient = .Create() .GetNonZeroBytes randomGeneratedCookie - let! endpoint, guardnode = directory.GetRouter RouterType.Guard - let! _, rendezvousNode = directory.GetRouter RouterType.Normal + let! endpoint, guardnode = directory.AsyncGetRouter RouterType.Guard + let! _, rendezvousNode = directory.AsyncGetRouter RouterType.Normal let! rendezvousGuard = - TorGuard.NewClientWithIdentity + TorGuard.AsyncNewClientWithIdentity endpoint (guardnode.GetIdentityKey() |> Some) let rendezvousCircuit = TorCircuit rendezvousGuard - do! rendezvousCircuit.Create guardnode |> Async.Ignore - do! rendezvousCircuit.Extend rendezvousNode |> Async.Ignore + do! rendezvousCircuit.AsyncCreate guardnode |> Async.Ignore + do! rendezvousCircuit.AsyncExtend rendezvousNode |> Async.Ignore do! - rendezvousCircuit.RegisterAsRendezvousPoint + rendezvousCircuit.AsyncRegisterAsRendezvousPoint randomGeneratedCookie let randomPrivateKey, randomPublicKey = @@ -438,7 +440,7 @@ type TorServiceClient = ] } - let! networkStatus = directory.GetLiveNetworkStatus() + let! networkStatus = directory.AsyncGetLiveNetworkStatus() let periodInfo = networkStatus.GetTimePeriod() let data, macKey = @@ -473,14 +475,14 @@ type TorServiceClient = let introCircuit = TorCircuit rendezvousGuard - do! introCircuit.Create guardnode |> Async.Ignore + do! introCircuit.AsyncCreate guardnode |> Async.Ignore do! - introCircuit.Extend introductionPointNodeDetail + introCircuit.AsyncExtend introductionPointNodeDetail |> Async.Ignore let rendezvousJoin = - rendezvousCircuit.WaitingForRendezvousJoin + rendezvousCircuit.AsyncWaitingForRendezvousJoin randomPrivateKey randomPublicKey introductionPointAuthKey @@ -488,7 +490,7 @@ type TorServiceClient = let introduceJob = async { - let! ack = introCircuit.Introduce introduce1Packet + let! ack = introCircuit.AsyncIntroduce introduce1Packet if ack.Status <> RelayIntroduceStatus.Success then return @@ -503,7 +505,7 @@ type TorServiceClient = // We can't use the "use" keyword since this stream needs // to outlive this function. let serviceStream = new TorStream(rendezvousCircuit) - do! serviceStream.ConnectToService port |> Async.Ignore + do! serviceStream.AsyncConnectToService port |> Async.Ignore return { diff --git a/NOnion/Services/TorServiceHost.fs b/NOnion/Services/TorServiceHost.fs index 7d6c10e0..bc0e96bb 100644 --- a/NOnion/Services/TorServiceHost.fs +++ b/NOnion/Services/TorServiceHost.fs @@ -126,20 +126,22 @@ type TorServiceHost = async { let! endPoint, randomNodeDetails = - directory.GetRouter RouterType.Guard + directory.AsyncGetRouter RouterType.Guard let! guard = - TorGuard.NewClientWithIdentity + TorGuard.AsyncNewClientWithIdentity endPoint (randomNodeDetails.GetIdentityKey() |> Some) let rendezvousCircuit = TorCircuit(guard, self.IncomingServiceStreamCallback) - do! rendezvousCircuit.Create randomNodeDetails |> Async.Ignore + do! + rendezvousCircuit.AsyncCreate randomNodeDetails + |> Async.Ignore do! - rendezvousCircuit.Extend( + rendezvousCircuit.AsyncExtend( CircuitNodeDetail.Create( rendezvousEndpoint, onionKey, @@ -149,7 +151,7 @@ type TorServiceHost |> Async.Ignore do! - rendezvousCircuit.Rendezvous + rendezvousCircuit.AsyncRendezvous cookie (X25519PublicKeyParameters(clientPubKey, 0)) introAuthPubKey @@ -181,7 +183,7 @@ type TorServiceHost introductionPointDetails.EncryptionKey.Private :?> X25519PrivateKeyParameters - let! networkStatus = directory.GetLiveNetworkStatus() + let! networkStatus = directory.AsyncGetLiveNetworkStatus() let periodInfo = networkStatus.GetTimePeriod() let decryptedData, macKey = @@ -265,10 +267,10 @@ type TorServiceHost async { try let! guardEndPoint, guardNodeDetail = - directory.GetRouter RouterType.Guard + directory.AsyncGetRouter RouterType.Guard let! _, introNodeDetail = - directory.GetRouter RouterType.Normal + directory.AsyncGetRouter RouterType.Normal match introNodeDetail with | FastCreate -> @@ -277,7 +279,7 @@ type TorServiceHost "Unreachable, directory always returns non-fast connection info" | Create(address, onionKey, fingerprint) -> let! guard = - TorGuard.NewClientWithIdentity + TorGuard.AsyncNewClientWithIdentity guardEndPoint (guardNodeDetail.GetIdentityKey() |> Some) @@ -311,11 +313,16 @@ type TorServiceHost masterPublicKey.GetEncoded() } - do! circuit.Create guardNodeDetail |> Async.Ignore - do! circuit.Extend introNodeDetail |> Async.Ignore + do! + circuit.AsyncCreate guardNodeDetail + |> Async.Ignore + + do! + circuit.AsyncExtend introNodeDetail + |> Async.Ignore do! - circuit.RegisterAsIntroductionPoint + circuit.AsyncRegisterAsIntroductionPoint (Some authKeyPair) self.RelayIntroduceCallback self.IntroductionPointDeathCallback @@ -376,34 +383,34 @@ type TorServiceHost else try let! hsDirectoryNode = - directory.GetCircuitNodeDetailByIdentity + directory.AsyncGetCircuitNodeDetailByIdentity directoryToUploadTo let! guardEndPoint, randomGuardNode = - directory.GetRouter RouterType.Guard + directory.AsyncGetRouter RouterType.Guard let! _, randomMiddleNode = - directory.GetRouter RouterType.Normal + directory.AsyncGetRouter RouterType.Normal use! guardNode = - TorGuard.NewClientWithIdentity + TorGuard.AsyncNewClientWithIdentity guardEndPoint (randomGuardNode.GetIdentityKey() |> Some) let circuit = TorCircuit guardNode - do! circuit.Create randomGuardNode |> Async.Ignore - do! circuit.Extend randomMiddleNode |> Async.Ignore - do! circuit.Extend hsDirectoryNode |> Async.Ignore + do! circuit.AsyncCreate randomGuardNode |> Async.Ignore + do! circuit.AsyncExtend randomMiddleNode |> Async.Ignore + do! circuit.AsyncExtend hsDirectoryNode |> Async.Ignore use dirStream = new TorStream(circuit) - do! dirStream.ConnectToDirectory() |> Async.Ignore + do! dirStream.AsyncConnectToDirectory() |> Async.Ignore let! _response = TorHttpClient( dirStream, Constants.DefaultHttpHost ) - .PostString + .AsyncPostString (sprintf "/tor/hs/%i/publish" Constants.HiddenServices.Version) @@ -450,7 +457,7 @@ type TorServiceHost (masterPublicKey.GetEncoded()) let! responsibleDirs = - directory.GetResponsibleHiddenServiceDirectories + directory.AsyncGetResponsibleHiddenServiceDirectories blindedPublicKey srv periodNum @@ -756,7 +763,7 @@ type TorServiceHost //TODO: this should refresh every 60-120min member self.KeepDescriptorsUpToDate() = async { - let! networkStatus = directory.GetLiveNetworkStatus() + let! networkStatus = directory.AsyncGetLiveNetworkStatus() let firstDescriptorBuildJob = self.UpdateFirstDescriptor networkStatus @@ -825,7 +832,7 @@ type TorServiceHost // We can't use the "use" keyword since this stream needs // to outlive this function. Hopefully the caller will dispose // this after they're done using it. - let! stream = TorStream.Accept streamId senderCircuit + let! stream = TorStream.AsyncAccept streamId senderCircuit return stream }