Fixed a bug where setting compression would crash the server on local routes, fixed some useless never-will-happen eventualities
Signed-off-by: arzumify <jliwin98@danwin1210.de>
This commit is contained in:
parent
eebe3763f5
commit
d40bc7dc8e
56
main.go
56
main.go
|
@ -644,22 +644,6 @@ func tryAuthAccess(message library.InterServiceMessage) {
|
||||||
service, ok := activeServices[uuid.MustParse("00000000-0000-0000-0000-000000000004")]
|
service, ok := activeServices[uuid.MustParse("00000000-0000-0000-0000-000000000004")]
|
||||||
if ok {
|
if ok {
|
||||||
service.Inbox <- message
|
service.Inbox <- message
|
||||||
} else if !ok {
|
|
||||||
// Send error message
|
|
||||||
service, ok := activeServices[message.ServiceID]
|
|
||||||
if ok {
|
|
||||||
service.Inbox <- library.InterServiceMessage{
|
|
||||||
ServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
||||||
ForServiceID: message.ServiceID,
|
|
||||||
MessageType: 1,
|
|
||||||
SentAt: time.Now(),
|
|
||||||
Message: errors.New("authentication service not found"),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// This should never happen
|
|
||||||
slog.Error("Bit flip error: Impossible service ID. Move away from radiation or use ECC memory.")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Send error message
|
// Send error message
|
||||||
service, ok := activeServices[message.ServiceID]
|
service, ok := activeServices[message.ServiceID]
|
||||||
|
@ -669,7 +653,7 @@ func tryAuthAccess(message library.InterServiceMessage) {
|
||||||
ForServiceID: message.ServiceID,
|
ForServiceID: message.ServiceID,
|
||||||
MessageType: 1,
|
MessageType: 1,
|
||||||
SentAt: time.Now(),
|
SentAt: time.Now(),
|
||||||
Message: errors.New("authentication service not yet available"),
|
Message: errors.New("authentication service not found"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This should never happen
|
// This should never happen
|
||||||
|
@ -704,22 +688,6 @@ func tryStorageAccess(message library.InterServiceMessage) {
|
||||||
service, ok := activeServices[uuid.MustParse("00000000-0000-0000-0000-000000000003")]
|
service, ok := activeServices[uuid.MustParse("00000000-0000-0000-0000-000000000003")]
|
||||||
if ok {
|
if ok {
|
||||||
service.Inbox <- message
|
service.Inbox <- message
|
||||||
} else if !ok {
|
|
||||||
// Send error message
|
|
||||||
service, ok := activeServices[message.ServiceID]
|
|
||||||
if ok {
|
|
||||||
service.Inbox <- library.InterServiceMessage{
|
|
||||||
ServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
||||||
ForServiceID: message.ServiceID,
|
|
||||||
MessageType: 1,
|
|
||||||
SentAt: time.Now(),
|
|
||||||
Message: errors.New("blob storage service not found"),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// This should never happen
|
|
||||||
slog.Error("Bit flip error: Impossible service ID. Move away from radiation or use ECC memory.")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Send error message
|
// Send error message
|
||||||
service, ok := activeServices[message.ServiceID]
|
service, ok := activeServices[message.ServiceID]
|
||||||
|
@ -729,7 +697,7 @@ func tryStorageAccess(message library.InterServiceMessage) {
|
||||||
ForServiceID: message.ServiceID,
|
ForServiceID: message.ServiceID,
|
||||||
MessageType: 1,
|
MessageType: 1,
|
||||||
SentAt: time.Now(),
|
SentAt: time.Now(),
|
||||||
Message: errors.New("blob storage is not yet available"),
|
Message: errors.New("blob storage service not found"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This should never happen
|
// This should never happen
|
||||||
|
@ -915,20 +883,19 @@ func parseConfig(path string) Config {
|
||||||
|
|
||||||
func iterateThroughSubdomains(globalOutbox chan library.InterServiceMessage) {
|
func iterateThroughSubdomains(globalOutbox chan library.InterServiceMessage) {
|
||||||
for _, route := range config.Routes {
|
for _, route := range config.Routes {
|
||||||
var subdomainRouter *chi.Mux
|
|
||||||
// Create the subdomain router
|
|
||||||
if route.Compression.Level != 0 {
|
if route.Compression.Level != 0 {
|
||||||
compression[route.Subdomain] = CompressionSettings{
|
compression[route.Subdomain] = CompressionSettings{
|
||||||
Level: int(route.Compression.Level),
|
Level: int(route.Compression.Level),
|
||||||
Algorithm: route.Compression.Algorithm,
|
Algorithm: route.Compression.Algorithm,
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
subdomainRouter = chi.NewRouter()
|
|
||||||
subdomainRouter.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
serverError(w, 404)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the subdomain router
|
||||||
|
subdomainRouter := chi.NewRouter()
|
||||||
|
subdomainRouter.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
serverError(w, 404)
|
||||||
|
})
|
||||||
|
|
||||||
subdomains[route.Subdomain] = subdomainRouter
|
subdomains[route.Subdomain] = subdomainRouter
|
||||||
subdomains[route.Subdomain].Use(logger)
|
subdomains[route.Subdomain].Use(logger)
|
||||||
subdomains[route.Subdomain].Use(serverChanger)
|
subdomains[route.Subdomain].Use(serverChanger)
|
||||||
|
@ -1158,6 +1125,11 @@ func main() {
|
||||||
|
|
||||||
// Start the HTTP server
|
// Start the HTTP server
|
||||||
err = http.ListenAndServe(config.Global.IP+":"+config.Global.HTTPPort, http.HandlerFunc(hostRouter))
|
err = http.ListenAndServe(config.Global.IP+":"+config.Global.HTTPPort, http.HandlerFunc(hostRouter))
|
||||||
slog.Error("Error starting server: " + err.Error())
|
if err != nil {
|
||||||
|
slog.Error("Error starting server: " + err.Error())
|
||||||
|
} else {
|
||||||
|
// This should never happen
|
||||||
|
slog.Error("Bit flip error: Impossible service ID. Move away from radiation or use ECC memory.")
|
||||||
|
}
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,11 +189,6 @@ func Main(information library.ServiceInitializationInformation) {
|
||||||
identifier := information.Configuration["identifier"].(string)
|
identifier := information.Configuration["identifier"].(string)
|
||||||
adminKey := information.Configuration["adminKey"].(string)
|
adminKey := information.Configuration["adminKey"].(string)
|
||||||
|
|
||||||
var err error
|
|
||||||
if err != nil {
|
|
||||||
logFunc(err.Error(), 3, information)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initiate a connection to the database
|
// Initiate a connection to the database
|
||||||
// Call service ID 1 to get the database connection information
|
// Call service ID 1 to get the database connection information
|
||||||
information.Outbox <- library.InterServiceMessage{
|
information.Outbox <- library.InterServiceMessage{
|
||||||
|
@ -246,7 +241,7 @@ func Main(information library.ServiceInitializationInformation) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set up the in-memory cache
|
// Set up the in-memory cache
|
||||||
mem, err = sql.Open("sqlite3", "file:"+ServiceInformation.ServiceID.String()+"?mode=memory&cache=shared")
|
mem, err := sql.Open("sqlite3", "file:"+ServiceInformation.ServiceID.String()+"?mode=memory&cache=shared")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logFunc(err.Error(), 3, information)
|
logFunc(err.Error(), 3, information)
|
||||||
}
|
}
|
||||||
|
@ -295,7 +290,7 @@ func Main(information library.ServiceInitializationInformation) {
|
||||||
|
|
||||||
// Set up the signing keys
|
// Set up the signing keys
|
||||||
// Check if the global table has the keys
|
// Check if the global table has the keys
|
||||||
err = conn.DB.QueryRow("SELECT key FROM global LIMIT 1").Scan(&privateKey)
|
err := conn.DB.QueryRow("SELECT key FROM global LIMIT 1").Scan(&privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
// Generate a new key
|
// Generate a new key
|
||||||
|
|
Loading…
Reference in New Issue