Skip to content

Commit

Permalink
add register with bulletinboard endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahMarsh committed Nov 5, 2024
1 parent 56ee57e commit d312154
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions internal/model/client/clientHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"log/slog"
"net/http"
"time"
)

// HandleReceive handles incoming onions sent to the client by other nodes.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d312154

Please sign in to comment.