Skip to content

Commit cbfab7d

Browse files
committed
refactor(config-shared): curryify create* functions
1 parent ab60aa7 commit cbfab7d

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

Aurum.Configuration/ShareLinks.fs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let createV2FlyObjectFromUri (uriObject: System.Uri) =
1313
let protocolSetting =
1414
match uriObject.Scheme with
1515
| "vmess" ->
16-
createVMessObject (uriObject.Host, uriObject.Port, uriObject.UserInfo, VMessSecurity.Auto)
16+
createVMessObject uriObject.Host uriObject.Port uriObject.UserInfo VMessSecurity.Auto
1717
|> Success
1818
| unknown -> Failure([ ShareLinkFormatException $"unknown sharelink protocol {unknown}" ])
1919

@@ -34,11 +34,11 @@ let createV2FlyObjectFromUri (uriObject: System.Uri) =
3434
let securitySetting =
3535
match securityType with
3636
| "tls" ->
37-
createTLSObject (
38-
tryRetrieveFromShareLink "sni",
39-
tryRetrieveFromShareLink "alpn"
40-
|> Option.map (fun alpn -> alpn.Split(",") |> Seq.toList)
41-
)
37+
createTLSObject
38+
(tryRetrieveFromShareLink "sni")
39+
(tryRetrieveFromShareLink "alpn"
40+
|> Option.map (fun alpn -> alpn.Split(",") |> Seq.toList))
41+
4242
|> Success
4343
| "none" -> Success(TransportSecurity.None)
4444
| unsupported -> Failure([ ShareLinkFormatException $"unsupported security type {unsupported}" ])
@@ -53,28 +53,26 @@ let createV2FlyObjectFromUri (uriObject: System.Uri) =
5353
(fun transportType ->
5454
match transportType with
5555
| "ws" ->
56-
createWebSocketObject (
57-
(tryRetrieveFromShareLink "path"),
58-
None,
59-
None,
60-
None,
61-
(tryRetrieveFromShareLink "host"),
62-
None
63-
)
56+
createWebSocketObject (tryRetrieveFromShareLink "path") None None None (tryRetrieveFromShareLink "host") None
57+
6458
|> Success
6559
| "grpc" ->
6660
retrieveFromShareLink "serviceName"
6761
|> Result.mapError (fun e -> [ e ])
6862
|> Validation.ofResult
6963
|> Validation.map createGrpcObject
7064
| "http" ->
71-
createHttpObject (tryRetrieveFromShareLink "path", tryRetrieveFromShareLink "host", Dictionary())
65+
createHttpObjectWithHost
66+
(tryRetrieveFromShareLink "path")
67+
(tryRetrieveFromShareLink "host")
68+
(HTTP2)
69+
(Some(Dictionary()))
7270
|> Success
7371
| "quic" -> createQuicObject () |> Success
7472
| "kcp" ->
75-
createKCPObject (None, None, None, None, None, None, None, (tryRetrieveFromShareLink "seed"))
73+
createKCPObject None None None None None None None (tryRetrieveFromShareLink "seed")
7674
|> Success
77-
| "tcp" -> createTCPObject () |> Success
75+
| "tcp" -> createHttpObjectWithHost None None HTTP1 None |> Success
7876
| unknown -> Failure([ ConfigurationParameterException $"unknown transport protocol {unknown}" ]))
7977
transportType
8078

Aurum.Configuration/Shared/V2fly.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ module V2flyObject =
293293
let inline _StreamSettings f (p: V2flyObject) =
294294
f p.StreamSettings <&> fun x -> { p with StreamSettings = x }
295295

296-
let createWebSocketObject (path, maxEarlyData, browserForwarding, earlyDataHeader, host, headers) =
296+
let createWebSocketObject path maxEarlyData browserForwarding earlyDataHeader host headers =
297297
let constructedHeaders = Option.defaultValue (Dictionary()) headers
298298

299299
match host with
@@ -314,19 +314,20 @@ let createGrpcObject serviceName =
314314

315315
GRPC config
316316

317-
let createHttpObject (path, host: string option, headers) =
317+
let createHttpObjectWithHost path (host: string option) version headers =
318318
let parsedHost =
319319
Option.map (fun (host: string) -> host.Split "," |> Seq.toList) host
320320
|> Option.defaultValue []
321321

322322
let config =
323323
{ HttpObject.Path = Option.defaultValue "/" path
324324
Headers = headers
325+
Version = version
325326
Host = parsedHost }
326327

327328
HTTP config
328329

329-
let createKCPObject (mtu, tti, uplinkCapacity, downlinkCapacity, congestion, readBufferSize, writeBufferSize, seed) =
330+
let createKCPObject mtu tti uplinkCapacity downlinkCapacity congestion readBufferSize writeBufferSize seed =
330331

331332
let config =
332333
{ KcpObject.MTU = Option.defaultValue 1350 mtu
@@ -342,13 +343,13 @@ let createKCPObject (mtu, tti, uplinkCapacity, downlinkCapacity, congestion, rea
342343

343344
let createQuicObject () = QUIC
344345

345-
let createTLSObject (serverName, alpn) =
346+
let createTLSObject serverName alpn =
346347
TransportSecurity.TLS
347348
{ TlsObject.ServerName = serverName
348349
ALPN = alpn
349350
AllowInsecure = Some false }
350351

351-
let createVMessObject (host, port, uuid, security) =
352+
let createVMessObject host port uuid security =
352353
VMess
353354
{ VMessObject.Address = host
354355
Port = port

Aurum.Configuration/V2fly/Outbound.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,24 @@ type OutboundObject =
6161
let options = opt.Split(";") |> Array.toList
6262

6363
if options.Length = 0 then
64-
let transportSettings = createWebSocketObject (None, None, None, None, None, None)
64+
let transportSettings = createWebSocketObject None None None None None None
6565

6666
{ TransportSettings = transportSettings
6767
SecuritySettings = TransportSecurity.None }
6868
elif options |> List.contains "tls" then
6969
let host = (options |> List.find (fun a -> a.IndexOf("host") <> -1)).Split("=")[1]
7070

7171
let transportSettings =
72-
createWebSocketObject (None, None, None, Some host, None, None)
72+
createWebSocketObject None None None (Some host) None None
7373

74-
let securitySettings = createTLSObject (Some host, None)
74+
let securitySettings = createTLSObject (Some host) None
7575

7676
{ TransportSettings = transportSettings
7777
SecuritySettings = securitySettings }
7878
elif options |> List.exists (fun a -> a.IndexOf("mode") <> -1) then
7979
let host = (options |> List.find (fun a -> a.IndexOf("host") <> -1)).Split("=")[1]
8080
let transportSettings = createQuicObject ()
81-
let securitySettings = createTLSObject (Some host, None)
81+
let securitySettings = createTLSObject (Some host) None
8282

8383
{ TransportSettings = transportSettings
8484
SecuritySettings = securitySettings }
@@ -148,7 +148,8 @@ type OutboundJsonObject =
148148
Settings = settings
149149
Tag = this.Tag
150150
StreamSettings = this.StreamSettings
151-
Mux = this.Mux } |> Ok
151+
Mux = this.Mux }
152+
|> Ok
152153
| Error e -> Error e
153154

154155
let createV2flyOutboundObject sendThrough setting streamSetting tag mux =

0 commit comments

Comments
 (0)