feat: completed gateway in quic mode

This commit is contained in:
=
2025-03-04 23:01:26 +05:30
parent 9bfc2a5dd2
commit 016cb4a7ba
3 changed files with 215 additions and 10 deletions

View File

@@ -30,6 +30,7 @@
"@fastify/swagger": "^8.14.0",
"@fastify/swagger-ui": "^2.1.0",
"@google-cloud/kms": "^4.5.0",
"@infisical/quic": "^1.0.8",
"@node-saml/passport-saml": "^4.0.4",
"@octokit/auth-app": "^7.1.1",
"@octokit/plugin-retry": "^5.0.5",
@@ -6190,6 +6191,112 @@
"integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==",
"dev": true
},
"node_modules/@infisical/quic": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@infisical/quic/-/quic-1.0.8.tgz",
"integrity": "sha512-ozgGkVdLP+ST41rPYmtaUBnBzisEzoI1l9yIds2l3hbd6OX6I836G0djTWLZbisn2ZO8CEbr8buLUclxqiY/IA==",
"license": "Apache-2.0",
"dependencies": {
"@matrixai/async-cancellable": "^1.1.1",
"@matrixai/async-init": "^1.10.0",
"@matrixai/async-locks": "^4.0.0",
"@matrixai/contexts": "^1.2.0",
"@matrixai/errors": "^1.2.0",
"@matrixai/events": "^3.2.3",
"@matrixai/logger": "^3.1.2",
"@matrixai/resources": "^1.1.5",
"@matrixai/timer": "^1.1.3",
"ip-num": "^1.5.0"
},
"optionalDependencies": {
"@infisical/quic-darwin-arm64": "1.0.8",
"@infisical/quic-darwin-universal": "1.0.8",
"@infisical/quic-darwin-x64": "1.0.8",
"@infisical/quic-linux-arm": "1.0.8",
"@infisical/quic-linux-arm64": "1.0.8",
"@infisical/quic-linux-x64": "1.0.8",
"@infisical/quic-win32-x64": "1.0.8"
}
},
"node_modules/@infisical/quic-darwin-arm64": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@infisical/quic-darwin-arm64/-/quic-darwin-arm64-1.0.8.tgz",
"integrity": "sha512-gJ1g2magCRQ+v02q6Jx50t85xIWnXgihYz/vak0YDYUIIOZFrcc7BaxNdfAo6lcxxDuGnK9RDTcLOpfMWt9EtQ==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@infisical/quic-darwin-universal": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@infisical/quic-darwin-universal/-/quic-darwin-universal-1.0.8.tgz",
"integrity": "sha512-BsOVIKexP+FysAyddnHHNKADUKz12ZzX7Eyl3fx4ZBGYdjzk3QTkG989HhSvYYQ+p3GyxB7p+Qn1cX3W5q3SHw==",
"cpu": [
"x64",
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@infisical/quic-darwin-x64": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@infisical/quic-darwin-x64/-/quic-darwin-x64-1.0.8.tgz",
"integrity": "sha512-xvWuAB8plgGFxK9trO1MYq5xhRFgKRySpWxOuPDkNrGQZJNBZTiQfCM91dWfpMip1GhmhO7K0fcp5GYTphMXCA==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@infisical/quic-linux-arm64": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@infisical/quic-linux-arm64/-/quic-linux-arm64-1.0.8.tgz",
"integrity": "sha512-vOEr/gIskr+eXN0rofpX1+hCJeKjUnHpt97LVsob9Jh7cXVGa9ywM0NbbYurz7FOdWH8+fBtppxkto4UdLSrZg==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@infisical/quic-linux-x64": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@infisical/quic-linux-x64/-/quic-linux-x64-1.0.8.tgz",
"integrity": "sha512-YE4xk5xv2oAiqZwVqNhC9AUnuFj1Q0cUiZmxih0RqfO51sr1BCgqmSBRWRykrdL8oyPmQduSNWKN7FcckPhYVQ==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@infisical/quic-win32-x64": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@infisical/quic-win32-x64/-/quic-win32-x64-1.0.8.tgz",
"integrity": "sha512-Ihh+NxKI6ujJTvOoRwQ8PUmoxU05iiAzkq0r0tP2xtTdXfg57R7sOGUyJCjg1AwpS40T+xgGTIjIGGQS50qYvg==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@ioredis/commands": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@ioredis/commands/-/commands-1.2.0.tgz",
@@ -6462,6 +6569,85 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/@matrixai/async-cancellable": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@matrixai/async-cancellable/-/async-cancellable-1.1.1.tgz",
"integrity": "sha512-f0yxu7dHwvffZ++7aCm2WIcCJn18uLcOTdCCwEA3R3KVHYE3TG/JNoTWD9/mqBkAV1AI5vBfJzg27WnF9rOUXQ==",
"license": "Apache-2.0"
},
"node_modules/@matrixai/async-init": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@matrixai/async-init/-/async-init-1.10.0.tgz",
"integrity": "sha512-JjUFu6rqd+dtTHFJ6z8bjbceuFGBj/APWfJByVsfbEH1DJsOgWERFcW3DBUrS0mgTph4Vl518tsNcsSwKT5Y+g==",
"license": "Apache-2.0",
"dependencies": {
"@matrixai/async-locks": "^4.0.0",
"@matrixai/errors": "^1.2.0",
"@matrixai/events": "^3.2.0"
}
},
"node_modules/@matrixai/async-locks": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@matrixai/async-locks/-/async-locks-4.0.0.tgz",
"integrity": "sha512-u/3fOdtjOKcDYF8dDoPR1/+7nmOkhxo42eBpXTEgfI0hLPGI37PoW7tjLvwy+O51Quy1HGOwhsR/Dgr4x+euug==",
"license": "Apache-2.0",
"dependencies": {
"@matrixai/async-cancellable": "^1.1.1",
"@matrixai/errors": "^1.1.7",
"@matrixai/resources": "^1.1.5",
"@matrixai/timer": "^1.1.1"
}
},
"node_modules/@matrixai/contexts": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@matrixai/contexts/-/contexts-1.2.0.tgz",
"integrity": "sha512-MR/B02Kf4UoliP9b/gMMKsvWV6QM4JSPKTIqrhQP2tbOl3FwLI+AIhL3vgYEj1Xw+PP8bY5cr8ontJ8x6AJyMg==",
"license": "Apache-2.0",
"dependencies": {
"@matrixai/async-cancellable": "^1.1.1",
"@matrixai/async-locks": "^4.0.0",
"@matrixai/errors": "^1.1.7",
"@matrixai/resources": "^1.1.5",
"@matrixai/timer": "^1.1.1"
}
},
"node_modules/@matrixai/errors": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@matrixai/errors/-/errors-1.2.0.tgz",
"integrity": "sha512-eZHPHFla5GFmi0O0yGgbtkca+ZjwpDbMz+60NC3y+DzQq6BMoe4gHmPjDalAHTxyxv0+Q+AWJTuV8Ows+IqBfQ==",
"license": "Apache-2.0",
"dependencies": {
"ts-custom-error": "3.2.2"
}
},
"node_modules/@matrixai/events": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/@matrixai/events/-/events-3.2.3.tgz",
"integrity": "sha512-bZrNCwzYeFalGQpn8qa/jgD10mUAwLRbv6xGMI7gGz1f+vE65d3GPoJ6JoFOJSg9iCmRSayQJ+IipH3LMATvDA==",
"license": "Apache-2.0"
},
"node_modules/@matrixai/logger": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/@matrixai/logger/-/logger-3.1.3.tgz",
"integrity": "sha512-wIHyiAzkrlZ/qlss4HLtXFzdlk1hxmAb0FNCQMd7ZwiHJABiKbvQtFSpBUvUakZYwYomiFmHwTYkHloiIVjrsg==",
"license": "Apache-2.0"
},
"node_modules/@matrixai/resources": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/@matrixai/resources/-/resources-1.1.5.tgz",
"integrity": "sha512-m/DEZEe3wHqWEPTyoBtzFF6U9vWYhEnQtGgwvqiAlTxTM0rk96UBpWjDZCTF/vYG11ZlmlQFtg5H+zGgbjaB3Q==",
"license": "Apache-2.0"
},
"node_modules/@matrixai/timer": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@matrixai/timer/-/timer-1.1.3.tgz",
"integrity": "sha512-BG5bAZMIt7qxc9iqAOCk2zm7V0+yNQLwp+WhsWVkP25Nvd1klqKpScE1lGwoLA27ygxEi+8IRU3wa8PLrhs0DQ==",
"license": "Apache-2.0",
"dependencies": {
"@matrixai/async-cancellable": "^1.1.1",
"@matrixai/errors": "^1.1.7"
}
},
"node_modules/@mongodb-js/saslprep": {
"version": "1.1.9",
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.9.tgz",
@@ -15304,6 +15490,12 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/ip-num": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/ip-num/-/ip-num-1.5.1.tgz",
"integrity": "sha512-QziFxgxq3mjIf5CuwlzXFYscHxgLqdEdJKRo2UJ5GurL5zrSRMzT/O+nK0ABimoFH8MWF8YwIiwECYsHc1LpUQ==",
"license": "MIT"
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
@@ -21289,6 +21481,15 @@
"typescript": ">=4.2.0"
}
},
"node_modules/ts-custom-error": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/ts-custom-error/-/ts-custom-error-3.2.2.tgz",
"integrity": "sha512-u0YCNf2lf6T/vHm+POKZK1yFKWpSpJitcUN3HxqyEcFuNnHIDbyuIQC7QDy/PsBX3giFyk9rt6BFqBAh2lsDZQ==",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/ts-interface-checker": {
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz",

View File

@@ -0,0 +1,3 @@
public_ip: 127.0.0.1
auth_secret: changeThisOnProduction
realm: infisical.org

View File

@@ -28,14 +28,14 @@ type GatewayRelay struct {
}
type GatewayRelayConfig struct {
PublicIP string `json:"public_ip"`
Port int `json:"port"`
Realm string `json:"realm"`
AuthSecret string `json:"auth_secret"`
RelayMinPort uint16 `json:"relay_min_port"`
RelayMaxPort uint16 `json:"relay_max_port"`
TlsCertPath string `json:"tls_cert_path"`
TlsPrivateKeyPath string `json:"tls_private_key_path"`
PublicIP string `yaml:"public_ip"`
Port int `yaml:"port"`
Realm string `yaml:"realm"`
AuthSecret string `yaml:"auth_secret"`
RelayMinPort uint16 `yaml:"relay_min_port"`
RelayMaxPort uint16 `yaml:"relay_max_port"`
TlsCertPath string `yaml:"tls_cert_path"`
TlsPrivateKeyPath string `yaml:"tls_private_key_path"`
tls tls.Certificate
isTlsEnabled bool
@@ -138,6 +138,7 @@ func (g *GatewayRelay) Run() error {
threadNum := runtime.NumCPU()
listenerConfigs := make([]turn.ListenerConfig, threadNum)
var connAddress string
for i := 0; i < threadNum; i++ {
conn, listErr := listenerConfig.Listen(context.Background(), addr.Network(), addr.String())
if listErr != nil {
@@ -155,8 +156,7 @@ func (g *GatewayRelay) Run() error {
} else {
listenerConfigs[i].Listener = conn
}
log.Printf("Server %d listening on %s\n", i, conn.Addr().String())
connAddress = conn.Addr().String()
}
loggerF := logging.NewDefaultLoggerFactory()
@@ -174,6 +174,7 @@ func (g *GatewayRelay) Run() error {
return fmt.Errorf("Failed to start server: %w", err)
}
log.Info().Msgf("Relay listening on %s\n", connAddress)
// Block until user sends SIGINT or SIGTERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)