Skip to content

Commit

Permalink
Client,Services,Tests: TorClient exit circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
aarani committed Apr 23, 2023
1 parent 8915556 commit 3b8212c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion NOnion.Tests/TorClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TorClientTests
private async Task CreateCircuit()
{
var client = await TorClient.BootstrapWithEmbeddedListAsync();
await client.CreateCircuitAsync(3, FSharpOption<Network.CircuitNodeDetail>.None);
await client.CreateCircuitAsync(3, CircuitPurpose.Unknown, FSharpOption<Network.CircuitNodeDetail>.None);
}

[Test]
Expand Down
21 changes: 18 additions & 3 deletions NOnion/Client/TorClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ open NOnion.Utility
open NOnion
open NOnion.Network

type CircuitPurpose =
| Unknown
| Exit

type TorClient internal (directory: TorDirectory) =
static let maximumBootstrapTries = 5

Expand Down Expand Up @@ -99,6 +103,7 @@ type TorClient internal (directory: TorDirectory) =

member __.CreateCircuit
(hopsCount: int)
(purpose: CircuitPurpose)
(extendByNodeOpt: Option<CircuitNodeDetail>)
=
async {
Expand Down Expand Up @@ -145,8 +150,17 @@ type TorClient internal (directory: TorDirectory) =
let rec findUnusedNode() =
async {
let! _ipEndPoint, nodeDetail =
directory.GetRouter
RouterType.Normal
if numHopsToExtend = 1 then
match purpose with
| Unknown ->
directory.GetRouter
RouterType.Normal
| Exit ->
directory.GetRouter
RouterType.Exit
else
directory.GetRouter
RouterType.Normal

if (List.contains
nodeDetail
Expand Down Expand Up @@ -208,9 +222,10 @@ type TorClient internal (directory: TorDirectory) =
member self.CreateCircuitAsync
(
hopsCount: int,
purpse: CircuitPurpose,
extendByNode: Option<CircuitNodeDetail>
) =
self.CreateCircuit hopsCount extendByNode |> Async.StartAsTask
self.CreateCircuit hopsCount purpse extendByNode |> Async.StartAsTask


interface IDisposable with
Expand Down
1 change: 1 addition & 0 deletions NOnion/Services/TorServiceClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type TorServiceClient =
let! circuit =
torClient.CreateCircuit
2
CircuitPurpose.Unknown
(Some hsDirectoryNode)

use dirStream = new TorStream(circuit)
Expand Down
5 changes: 4 additions & 1 deletion NOnion/Services/TorServiceHost.fs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ type TorServiceHost
use torClient = new TorClient(directory)

let! circuit =
torClient.CreateCircuit 2 (Some hsDirectoryNode)
torClient.CreateCircuit
2
CircuitPurpose.Unknown
(Some hsDirectoryNode)

use dirStream = new TorStream(circuit)
do! dirStream.ConnectToDirectory() |> Async.Ignore
Expand Down

0 comments on commit 3b8212c

Please sign in to comment.