diff --git a/cmd/client/main.go b/cmd/client/main.go index 52e9b05..fe94be5 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -121,6 +121,7 @@ func main() { // Set up HTTP handlers http.HandleFunc("/receive", newClient.HandleReceive) http.HandleFunc("/start", newClient.HandleStartRun) + http.HandleFunc("/register", newClient.HandleRegisterWithBulletinBoard) http.HandleFunc("/shutdown", func(w http.ResponseWriter, r *http.Request) { slog.Info("Shutdown signal received") quit <- os.Signal(syscall.SIGTERM) // signal shutdown diff --git a/internal/model/client/clientHandler.go b/internal/model/client/clientHandler.go index 052303a..f870ddc 100644 --- a/internal/model/client/clientHandler.go +++ b/internal/model/client/clientHandler.go @@ -9,6 +9,7 @@ import ( "io" "log/slog" "net/http" + "time" ) // HandleReceive handles incoming onions sent to the client by other nodes. @@ -36,6 +37,23 @@ func (c *Client) HandleStartRun(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } +func (c *Client) HandleRegisterWithBulletinBoard(w http.ResponseWriter, r *http.Request) { + slog.Info("Registering with bulletin board") + + go func(c *Client) { + for { + if err := c.RegisterWithBulletinBoard(); err != nil { + slog.Error("failed to register with bulletin board: " + err.Error()) + } else { + slog.Info("Registered with bulletin board") + break + } + time.Sleep(5 * time.Second) + } + }(c) + w.WriteHeader(http.StatusOK) +} + // GetActiveNodes retrieves the list of active nodes from the bulletin board. func (c *Client) GetActiveNodes() ([]structs.PublicNodeApi, error) { url := fmt.Sprintf("%s/Clients", c.BulletinBoardUrl)