Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Performance optimizations via list prepend #36

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NOnion/Cells/CellAuthChallenge.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type CellAuthChallenge =
methods
else
readMethod
(methods @ [ ReadBigEndianUInt16 reader ])
(ReadBigEndianUInt16 reader :: methods)
(remainingCount - 1)

let challenge = reader.ReadBytes Constants.ChallangeLength
let methodsCount = ReadBigEndianUInt16 reader |> int
let methods = readMethod [] methodsCount
let methods = readMethod [] methodsCount |> Seq.rev

{
Challenge = challenge
Expand Down
4 changes: 2 additions & 2 deletions NOnion/Cells/CellCerts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type CellCerts =
}

readCertificates
(certificates @ [ certificate ])
(certificate :: certificates)
(remainingCount - 1)

let certificatesCount = reader.ReadByte() |> int
let certs = readCertificates List.empty certificatesCount
let certs = readCertificates List.empty certificatesCount |> Seq.rev

{
Certs = certs
Expand Down
4 changes: 2 additions & 2 deletions NOnion/Cells/CellNetInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type CellNetInfo =
addresses
else
readAddresses
(addresses @ [ readAddress() ])
(readAddress() :: addresses)
(remainingCount - 1uy)

let time = ReadBigEndianUInt32 reader
let otherAddress = readAddress()
let myAddressesCount = reader.ReadByte()
let myAddresses = readAddresses List.Empty myAddressesCount
let myAddresses = readAddresses List.Empty myAddressesCount |> Seq.rev

{
Time = time
Expand Down
4 changes: 2 additions & 2 deletions NOnion/Cells/CellVersions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type CellVersions =
if reader.BaseStream.Length = reader.BaseStream.Position then
versions
else
readVersions(versions @ [ ReadBigEndianUInt16 reader ])
readVersions((ReadBigEndianUInt16 reader) :: versions)

let versions = readVersions List.empty
let versions = readVersions List.empty |> Seq.rev

{
Versions = versions
Expand Down
5 changes: 2 additions & 3 deletions NOnion/Cells/Relay/RelayEstablishIntro.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ type RelayEstablishIntro =
state
else
readExtensionsList
(state
@ List.singleton(RelayIntroExtension.FromBytes reader))
((RelayIntroExtension.FromBytes reader) :: state)
(remainingCount - 1uy)

readExtensionsList List.empty extensionCount
readExtensionsList List.empty extensionCount |> Seq.rev

let handshakeAuth = reader.ReadBytes authKey.MacLength

Expand Down
6 changes: 2 additions & 4 deletions NOnion/Cells/Relay/RelayIntroduce.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ type RelayIntroduceInnerData =
state
else
readExtensionsList
(state
@ List.singleton(RelayIntroExtension.FromBytes reader))
((RelayIntroExtension.FromBytes reader) :: state)
(remainingCount - 1uy)

readExtensionsList List.empty extensionCount
Expand Down Expand Up @@ -105,8 +104,7 @@ type RelayIntroduce =
state
else
readExtensionsList
(state
@ List.singleton(RelayIntroExtension.FromBytes reader))
((RelayIntroExtension.FromBytes reader)::state)
(remainingCount - 1uy)

readExtensionsList List.empty extensionCount
Expand Down
3 changes: 1 addition & 2 deletions NOnion/Cells/Relay/RelayIntroduceAck.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ type RelayIntroduceAck =
state
else
readExtensionsList
(state
@ List.singleton(RelayIntroExtension.FromBytes reader))
(((RelayIntroExtension.FromBytes reader)) :: state)
(remainingCount - 1uy)

readExtensionsList List.empty extensionCount
Expand Down
3 changes: 1 addition & 2 deletions NOnion/Directory/HiddenServiceDescriptorDocument.fs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ type HiddenServiceDescriptorDocument =
| "introduction-point" ->
{ state with
IntroductionPoints =
state.IntroductionPoints
@ List.singleton(IntroductionPointEntry.Parse lines)
(IntroductionPointEntry.Parse lines) :: state.IntroductionPoints
}
| _ ->
lines.Dequeue() |> ignore<string>
Expand Down
44 changes: 19 additions & 25 deletions NOnion/Network/TorCircuit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -673,17 +673,15 @@ type TorCircuit
circuitState <-
Ready(
circuitId,
nodes
@ List.singleton
{
TorCircuitNode.CryptoState =
TorCryptoState.FromKdfResult
(Kdf.ComputeHSKdf ntorKeySeed)
true
Window =
TorWindow
Constants.DefaultCircuitLevelWindowParams
}
{
TorCircuitNode.CryptoState =
TorCryptoState.FromKdfResult
(Kdf.ComputeHSKdf ntorKeySeed)
true
Window =
TorWindow
Constants.DefaultCircuitLevelWindowParams
} :: nodes
)

do!
Expand Down Expand Up @@ -785,17 +783,15 @@ type TorCircuit
circuitState <-
Ready(
circuitId,
nodes
@ List.singleton
{
TorCircuitNode.CryptoState =
TorCryptoState.FromKdfResult
kdfResult
false
Window =
TorWindow
Constants.DefaultCircuitLevelWindowParams
}
{
TorCircuitNode.CryptoState =
TorCryptoState.FromKdfResult
kdfResult
false
Window =
TorWindow
Constants.DefaultCircuitLevelWindowParams
} :: nodes
)

tcs.SetResult circuitId
Expand Down Expand Up @@ -960,8 +956,6 @@ type TorCircuit
circuitState <-
Ready(
circuitId,
nodes
@ List.singleton
{
TorCircuitNode.CryptoState =
TorCryptoState.FromKdfResult
Expand All @@ -971,7 +965,7 @@ type TorCircuit
Window =
TorWindow
Constants.DefaultCircuitLevelWindowParams
}
} :: nodes
)

tcs.SetResult()
Expand Down