Main/Common: Use config entry for frontend/backend address

This commit is contained in:
mkwcat 2024-05-08 22:39:14 -04:00
parent a949b5c727
commit 2c137ed7f3
No known key found for this signature in database
GPG Key ID: 7A505679CE9E7AA9
4 changed files with 74 additions and 29 deletions

View File

@ -6,31 +6,43 @@ import (
) )
type Config struct { type Config struct {
Username string `xml:"username"` Username string `xml:"username"`
Password string `xml:"password"` Password string `xml:"password"`
DatabaseAddress string `xml:"databaseAddress"` DatabaseAddress string `xml:"databaseAddress"`
DatabaseName string `xml:"databaseName"` DatabaseName string `xml:"databaseName"`
DefaultAddress string `xml:"address"`
GameSpyAddress *string `xml:"gsAddress,omitempty"` DefaultAddress string `xml:"address"`
NASAddress *string `xml:"nasAddress,omitempty"` GameSpyAddress *string `xml:"gsAddress,omitempty"`
NASPort string `xml:"nasPort"` NASAddress *string `xml:"nasAddress,omitempty"`
NASAddressHTTPS *string `xml:"nasAddressHttps,omitempty"` NASPort string `xml:"nasPort"`
NASPortHTTPS string `xml:"nasPortHttps"` NASAddressHTTPS *string `xml:"nasAddressHttps,omitempty"`
EnableHTTPS bool `xml:"enableHttps"` NASPortHTTPS string `xml:"nasPortHttps"`
EnableHTTPSExploitWii *bool `xml:"enableHttpsExploitWii,omitempty"`
EnableHTTPSExploitDS *bool `xml:"enableHttpsExploitDS,omitempty"` FrontendAddress string `xml:"frontendAddress"`
LogLevel *int `xml:"logLevel"` FrontendBackendAddress string `xml:"frontendBackendAddress"`
LogOutput string `xml:"logOutput"` BackendAddress string `xml:"backendAddress"`
CertPath string `xml:"certPath"` BackendFrontendAddress string `xml:"backendFrontendAddress"`
KeyPath string `xml:"keyPath"`
CertPathWii string `xml:"certDerPathWii"` EnableHTTPS bool `xml:"enableHttps"`
KeyPathWii string `xml:"keyPathWii"` EnableHTTPSExploitWii *bool `xml:"enableHttpsExploitWii,omitempty"`
CertPathDS string `xml:"certDerPathDS"` EnableHTTPSExploitDS *bool `xml:"enableHttpsExploitDS,omitempty"`
WiiCertPathDS string `xml:"wiiCertDerPathDS"`
KeyPathDS string `xml:"keyPathDS"` LogLevel *int `xml:"logLevel"`
APISecret string `xml:"apiSecret"` LogOutput string `xml:"logOutput"`
AllowDefaultDolphinKeys bool `xml:"allowDefaultDolphinKeys"`
ServerName string `xml:"serverName,omitempty"` CertPath string `xml:"certPath"`
KeyPath string `xml:"keyPath"`
CertPathWii string `xml:"certDerPathWii"`
KeyPathWii string `xml:"keyPathWii"`
CertPathDS string `xml:"certDerPathDS"`
WiiCertPathDS string `xml:"wiiCertDerPathDS"`
KeyPathDS string `xml:"keyPathDS"`
APISecret string `xml:"apiSecret"`
AllowDefaultDolphinKeys bool `xml:"allowDefaultDolphinKeys"`
ServerName string `xml:"serverName,omitempty"`
} }
func GetConfig() Config { func GetConfig() Config {
@ -83,5 +95,21 @@ func GetConfig() Config {
config.LogOutput = "StdOutAndFile" config.LogOutput = "StdOutAndFile"
} }
if config.FrontendAddress == "" {
config.FrontendAddress = "127.0.0.1:29998"
}
if config.BackendAddress == "" {
config.BackendAddress = "127.0.0.1:29999"
}
if config.FrontendBackendAddress == "" {
config.FrontendBackendAddress = config.BackendAddress
}
if config.BackendFrontendAddress == "" {
config.BackendFrontendAddress = config.FrontendAddress
}
return config return config
} }

View File

@ -16,9 +16,11 @@ type RPCFrontendPacket struct {
// ConnectFrontend connects to the frontend RPC server // ConnectFrontend connects to the frontend RPC server
func ConnectFrontend() { func ConnectFrontend() {
config := GetConfig()
var err error var err error
for i := 0; rpcFrontend == nil; i++ { for i := 0; rpcFrontend == nil; i++ {
rpcFrontend, err = rpc.Dial("tcp", "localhost:29998") rpcFrontend, err = rpc.Dial("tcp", config.BackendFrontendAddress)
if err != nil { if err != nil {
if i > 20 { if i > 20 {
panic(err) panic(err)

View File

@ -2,6 +2,18 @@
<!-- The address the GameSpy services will bind to --> <!-- The address the GameSpy services will bind to -->
<gsAddress>127.0.0.1</gsAddress> <gsAddress>127.0.0.1</gsAddress>
<!-- The address the frontend RPC server will bind to -->
<frontendAddress>127.0.0.1:29998</frontendAddress>
<!-- The address the frontend can reach the backend from -->
<frontendBackendAddress>127.0.0.1:29999</frontendBackendAddress>
<!-- The address the backend RPC server will bind to -->
<backendAddress>127.0.0.1:29999</backendAddress>
<!-- The address the backend can reach the frontend from -->
<backendFrontendAddress>127.0.0.1:29998</backendFrontendAddress>
<!-- The address the NAS HTTP server will bind to --> <!-- The address the NAS HTTP server will bind to -->
<nasAddress>127.0.0.1</nasAddress> <nasAddress>127.0.0.1</nasAddress>
<nasPort>80</nasPort> <nasPort>80</nasPort>

View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
"time"
"wwfc/api" "wwfc/api"
"wwfc/common" "wwfc/common"
"wwfc/gamestats" "wwfc/gamestats"
@ -77,7 +78,7 @@ func backendMain(noSignal, noReload bool) {
} }
rpc.Register(&RPCPacket{}) rpc.Register(&RPCPacket{})
address := "localhost:29999" address := config.BackendAddress
l, err := net.Listen("tcp", address) l, err := net.Listen("tcp", address)
if err != nil { if err != nil {
@ -328,7 +329,7 @@ func frontendMain(noSignal, noBackend bool) {
// startFrontendServer starts the frontend RPC server. // startFrontendServer starts the frontend RPC server.
func startFrontendServer() { func startFrontendServer() {
rpc.Register(&RPCFrontendPacket{}) rpc.Register(&RPCFrontendPacket{})
address := "localhost:29998" address := config.FrontendAddress
l, err := net.Listen("tcp", address) l, err := net.Listen("tcp", address)
if err != nil { if err != nil {
@ -389,7 +390,7 @@ func waitForBackend() {
backendReady = make(chan struct{}) backendReady = make(chan struct{})
for { for {
client, err := rpc.Dial("tcp", "localhost:29999") client, err := rpc.Dial("tcp", config.FrontendBackendAddress)
if err == nil { if err == nil {
rpcClient = client rpcClient = client
rpcMutex.Unlock() rpcMutex.Unlock()
@ -398,6 +399,8 @@ func waitForBackend() {
return return
} }
<-time.After(50 * time.Millisecond)
} }
} }