Skip to content

Commit

Permalink
fantomless: change style preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
aarani committed Nov 7, 2021
1 parent a745a64 commit cc4c4af
Show file tree
Hide file tree
Showing 52 changed files with 945 additions and 961 deletions.
10 changes: 5 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ end_of_line=lf
indent_size=4
max_line_length=80
fsharp_semicolon_at_end_of_line=false
fsharp_space_before_parameter=true
fsharp_space_before_lowercase_invocation=true
fsharp_space_before_uppercase_invocation=true
fsharp_space_before_class_constructor=true
fsharp_space_before_member=true
fsharp_space_before_parameter=false
fsharp_space_before_lowercase_invocation=false
fsharp_space_before_uppercase_invocation=false
fsharp_space_before_class_constructor=false
fsharp_space_before_member=false
fsharp_space_before_colon=false
fsharp_space_after_comma=true
fsharp_space_before_semicolon=false
Expand Down
6 changes: 3 additions & 3 deletions NOnion/Cells/CellAuthChallenge.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ type CellAuthChallenge =
Methods: seq<uint16>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =

let rec readMethod methods n =
if n = 0 then
methods
else
readMethod (methods @ [ ReadBigEndianUInt16 reader ]) (n - 1)
readMethod(methods @ [ ReadBigEndianUInt16 reader ]) (n - 1)

let challenge = reader.ReadBytes Constants.ChallangeLength
let methodsCount = ReadBigEndianUInt16 reader |> int
Expand All @@ -35,7 +35,7 @@ type CellAuthChallenge =

member self.Serialize writer =

let rec writeMethods (methods: seq<uint16>) =
let rec writeMethods(methods: seq<uint16>) =
match Seq.tryHead methods with
| None -> ()
| Some method ->
Expand Down
10 changes: 5 additions & 5 deletions NOnion/Cells/CellCerts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ type CellCerts =
Certs: seq<Cert>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =

let rec readCertificates certificates n =
if n = 0 then
certificates
else
let certificate =
{
Cert.Type = reader.ReadByte ()
Cert.Type = reader.ReadByte()
Cert.Certificate =
ReadBigEndianUInt16 reader
|> int
|> reader.ReadBytes
}

readCertificates (certificates @ [ certificate ]) (n - 1)
readCertificates(certificates @ [ certificate ]) (n - 1)

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

{
Expand All @@ -46,7 +46,7 @@ type CellCerts =

member self.Serialize writer =

let rec writeCertificates (certificates: seq<Cert>) =
let rec writeCertificates(certificates: seq<Cert>) =
match Seq.tryHead certificates with
| None -> ()
| Some certificate ->
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Cells/CellCreate2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CellCreate2 =
HandshakeData: array<byte>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =
{
HandshakeType =
BinaryIO.ReadBigEndianUInt16 reader
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Cells/CellCreateFast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type CellCreateFast =
X: array<byte>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =
let x = reader.ReadBytes Constants.HashLength

{
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Cells/CellCreated2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CellCreated2 =
HandshakeData: array<byte>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =
{
HandshakeData =
BinaryIO.ReadBigEndianUInt16 reader |> int |> reader.ReadBytes
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Cells/CellCreatedFast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CellCreatedFast =
DerivativeKeyData: array<byte>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =
let y = reader.ReadBytes Constants.HashLength
let derivativeKeyData = reader.ReadBytes Constants.HashLength

Expand Down
6 changes: 3 additions & 3 deletions NOnion/Cells/CellDestory.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type CellDestroy =
Reason: DestroyReason
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =
{
Reason =
reader.ReadByte ()
reader.ReadByte()
|> LanguagePrimitives.EnumOfValue<byte, DestroyReason>
}
:> ICell
Expand All @@ -22,4 +22,4 @@ type CellDestroy =
member __.Command = 4uy

member self.Serialize writer =
writer.Write (self.Reason |> byte)
writer.Write(self.Reason |> byte)
20 changes: 10 additions & 10 deletions NOnion/Cells/CellNetInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ type CellNetInfo =
OtherAddress: RouterAddress
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =

let readAddress () : RouterAddress =
let readAddress() : RouterAddress =
{
RouterAddress.Type = reader.ReadByte ()
Value = reader.ReadByte () |> int |> reader.ReadBytes
RouterAddress.Type = reader.ReadByte()
Value = reader.ReadByte() |> int |> reader.ReadBytes
}

let rec readAddresses addresses n =
if n = 0uy then
addresses
else
readAddresses (addresses @ [ readAddress () ]) (n - 1uy)
readAddresses(addresses @ [ readAddress() ]) (n - 1uy)

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

{
Expand All @@ -49,17 +49,17 @@ type CellNetInfo =

member self.Serialize writer =

let writeAddress (addr: RouterAddress) =
let writeAddress(addr: RouterAddress) =
writer.Write addr.Type
addr.Value.Length |> byte |> writer.Write
writer.Write addr.Value

let rec writeAddresses (addresses: seq<RouterAddress>) =
let rec writeAddresses(addresses: seq<RouterAddress>) =
match Seq.tryHead addresses with
| None -> ()
| Some addr ->
writeAddress addr
writeAddresses (Seq.tail addresses)
writeAddresses(Seq.tail addresses)

WriteUInt32BigEndian writer self.Time
writeAddress self.OtherAddress
Expand Down
2 changes: 1 addition & 1 deletion NOnion/Cells/CellPadding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type CellPadding =
Bytes: array<byte>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =
{
Bytes = reader.ReadBytes Constants.FixedPayloadLength
}
Expand Down
8 changes: 4 additions & 4 deletions NOnion/Cells/CellVersions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type CellVersions =
Versions: seq<uint16>
}

static member Deserialize (reader: BinaryReader) =
static member Deserialize(reader: BinaryReader) =

let rec readVersions versions =
if (reader.BaseStream.Length - reader.BaseStream.Position) % 2L
Expand All @@ -20,7 +20,7 @@ type CellVersions =
if reader.BaseStream.Length = reader.BaseStream.Position then
versions
else
readVersions (versions @ [ ReadBigEndianUInt16 reader ])
readVersions(versions @ [ ReadBigEndianUInt16 reader ])

let versions = readVersions List.empty

Expand All @@ -35,11 +35,11 @@ type CellVersions =

member self.Serialize writer =

let rec writeVersions (versions: seq<uint16>) =
let rec writeVersions(versions: seq<uint16>) =
match Seq.tryHead versions with
| None -> ()
| Some version ->
WriteUInt16BigEndian writer version
writeVersions (Seq.tail versions)
writeVersions(Seq.tail versions)

writeVersions self.Versions
8 changes: 4 additions & 4 deletions NOnion/Cells/Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Command =
[<Literal>]
let Created2 = 11uy

let IsVariableLength (command: byte) : bool =
let IsVariableLength(command: byte) : bool =
command = 7uy || command >= 128uy

/// Serialize a cell, assuming its command has already been written.
Expand All @@ -68,10 +68,10 @@ module Command =
| Destroy -> CellDestroy.Deserialize reader
| Create2 -> CellCreate2.Deserialize reader
| Created2 -> CellCreated2.Deserialize reader
| _ -> raise <| NotImplementedException ()
| _ -> raise <| NotImplementedException()

// Is there any non generic way for this?
let GetCommandByCellType<'T when 'T :> ICell> () =
let GetCommandByCellType<'T when 'T :> ICell>() =
match typeof<'T> with
| t when t = typeof<CellCerts> -> Certs
| t when t = typeof<CellAuthChallenge> -> AuthChallenge
Expand All @@ -84,4 +84,4 @@ module Command =
| t when t = typeof<CellDestroy> -> Destroy
| t when t = typeof<CellCreate2> -> Create2
| t when t = typeof<CellCreated2> -> Created2
| _ -> raise <| NotImplementedException ()
| _ -> raise <| NotImplementedException()
48 changes: 24 additions & 24 deletions NOnion/Cells/Relay/CellPlainRelay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ type RelayData =
| RelayRendezvous2 of RelayRendezvous

static member FromBytes (command: byte) (data: array<byte>) =
use memStream = new MemoryStream (data)
use reader = new BinaryReader (memStream)
use memStream = new MemoryStream(data)
use reader = new BinaryReader(memStream)

match command with
| RelayCommands.RelayBegin -> RelayBegin.FromBytes reader |> RelayBegin
| RelayCommands.RelayData -> RelayData data
| RelayCommands.RelayEnd ->
reader.ReadByte ()
reader.ReadByte()
|> LanguagePrimitives.EnumOfValue<byte, EndReason>
|> RelayEnd
| RelayCommands.RelayConnected -> RelayConnected data
| RelayCommands.RelayTruncated ->
reader.ReadByte ()
reader.ReadByte()
|> LanguagePrimitives.EnumOfValue<byte, DestroyReason>
|> RelayTruncated
| RelayCommands.RelayExtended2 ->
Expand All @@ -83,7 +83,7 @@ type RelayData =
RelayIntroduceAck.FromBytes reader |> RelayIntroduceAck
| _ -> failwith "Unsupported command"

member self.GetCommand () : byte =
member self.GetCommand() : byte =
match self with
| RelayBegin _ -> RelayCommands.RelayBegin
| RelayBeginDirectory -> RelayCommands.RelayBeginDirectory
Expand All @@ -101,21 +101,21 @@ type RelayData =
| RelayIntroduceAck _ -> RelayCommands.RelayIntroduceAck
| _ -> failwith "Not implemeted yet"

member self.ToBytes () =
member self.ToBytes() =
match self with
| RelayBegin relayBegin -> relayBegin.ToBytes ()
| RelayBegin relayBegin -> relayBegin.ToBytes()
| RelayConnected data -> data
| RelayData data -> data
| RelaySendMe _ -> Array.zeroCreate 3
| RelayEnd reason -> reason |> byte |> Array.singleton
| RelayExtend2 extend2 -> extend2.ToBytes ()
| RelayExtend2 extend2 -> extend2.ToBytes()
| RelayEstablishIntro establishIntro -> establishIntro.ToBytes true true
| RelayEstablishRendezvous cookie -> cookie
| RelayIntroduceAck introduceAck -> introduceAck.ToBytes ()
| RelayIntroduceAck introduceAck -> introduceAck.ToBytes()
| RelayIntroduce1 introducePayload
| RelayIntroduce2 introducePayload -> introducePayload.ToBytes ()
| RelayIntroduce2 introducePayload -> introducePayload.ToBytes()
| RelayRendezvous1 rendezvousPayload
| RelayRendezvous2 rendezvousPayload -> rendezvousPayload.ToBytes ()
| RelayRendezvous2 rendezvousPayload -> rendezvousPayload.ToBytes()
| _ -> Array.zeroCreate 0

type CellPlainRelay =
Expand All @@ -132,7 +132,7 @@ type CellPlainRelay =
(data: RelayData)
(digest: array<byte>)
=
let payload = data.ToBytes ()
let payload = data.ToBytes()

let paddingLen = Constants.MaximumRelayPayloadLength - payload.Length

Expand All @@ -156,10 +156,10 @@ type CellPlainRelay =
Padding = padding
}

static member FromBytes (bytes: array<byte>) =
use memStream = new MemoryStream (bytes)
use reader = new BinaryReader (memStream)
let relayCommand = reader.ReadByte ()
static member FromBytes(bytes: array<byte>) =
use memStream = new MemoryStream(bytes)
use reader = new BinaryReader(memStream)
let relayCommand = reader.ReadByte()
let recognized = BinaryIO.ReadBigEndianUInt16 reader
let streamId = BinaryIO.ReadBigEndianUInt16 reader
let digest = reader.ReadBytes Constants.RelayDigestLength
Expand All @@ -168,7 +168,7 @@ type CellPlainRelay =
BinaryIO.ReadBigEndianUInt16 reader |> int |> reader.ReadBytes

let padding =
reader.ReadBytes (Constants.MaximumRelayPayloadLength - data.Length)
reader.ReadBytes(Constants.MaximumRelayPayloadLength - data.Length)

{
Recognized = recognized
Expand All @@ -178,10 +178,10 @@ type CellPlainRelay =
Padding = padding
}

member self.ToBytes (emptyDigest: bool) : array<byte> =
use memStream = new MemoryStream (Constants.FixedPayloadLength)
use writer = new BinaryWriter (memStream)
self.Data.GetCommand () |> writer.Write
member self.ToBytes(emptyDigest: bool) : array<byte> =
use memStream = new MemoryStream(Constants.FixedPayloadLength)
use writer = new BinaryWriter(memStream)
self.Data.GetCommand() |> writer.Write

self.Recognized |> BinaryIO.WriteUInt16BigEndian writer

Expand All @@ -195,12 +195,12 @@ type CellPlainRelay =

digest |> writer.Write

self.Data.ToBytes ()
self.Data.ToBytes()
|> Array.length
|> uint16
|> BinaryIO.WriteUInt16BigEndian writer

self.Data.ToBytes () |> writer.Write
self.Data.ToBytes() |> writer.Write
self.Padding |> writer.Write

memStream.ToArray ()
memStream.ToArray()
Loading

0 comments on commit cc4c4af

Please sign in to comment.