From 5fc1c8fb95b41783fa66cddd8f8d279787ef4211 Mon Sep 17 00:00:00 2001 From: Arzumify Date: Thu, 3 Oct 2024 17:17:24 +0100 Subject: [PATCH] Fixed the request and added a timeout --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index aebaded..f155319 100644 --- a/main.go +++ b/main.go @@ -157,8 +157,17 @@ func Main(information library.ServiceInitializationInformation) { Message: nil, } + var publicKey ed25519.PublicKey = nil + + // 10 second timeout + go func() { + time.Sleep(10 * time.Second) + if publicKey == nil { + logFunc("Timeout while waiting for the public key from the authentication service", 3, information) + } + }() + // Wait for the response - var publicKey ed25519.PublicKey response = <-information.Inbox if response.MessageType == 2 { // This is the public key @@ -169,15 +178,6 @@ func Main(information library.ServiceInitializationInformation) { logFunc(response.Message.(error).Error(), 3, information) } - // Ask the authentication service for its host name - information.Outbox <- library.InterServiceMessage{ - ServiceID: ServiceInformation.ServiceID, - ForServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000004"), // Authentication service - MessageType: 0, // Request host name - SentAt: time.Now(), - Message: nil, - } - // Set up the router router := information.Router