Skip to content

Commit

Permalink
Add usePrev flag to bulletin board
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahMarsh committed Nov 5, 2024
1 parent 7f23f47 commit d422610
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 117 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ out/*


**/prometheus.yml
**/lastRegisteredClientsRelays.yml
**/lastRegisteredClientsRelays.yml
config/lastRegisteredClientsRelays.yml
internal/model/bulletin_board/metrics/prometheus.yml
4 changes: 3 additions & 1 deletion cmd/bulletin-board/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func main() {
// Define command-line flags
logLevel := flag.String("log-level", "info", "Log level")

tellNodesToRegister := flag.Bool("usePrev", false, "False by default. If true, the bulletin board will tell all the clients and relays to register again, using the addresses saved from the previous run (lastRegisteredClientsRelays.yml)")

flag.Usage = func() {
if _, err := fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0]); err != nil {
slog.Error("Usage of %s:\n", err, os.Args[0])
Expand Down Expand Up @@ -56,7 +58,7 @@ func main() {
slog.Info("⚡ init Bulletin board", "url", url)

// Create a new instance of the Bulletin Board with the current configuration.
bulletinBoard = bulletin_board.NewBulletinBoard()
bulletinBoard = bulletin_board.NewBulletinBoard(*tellNodesToRegister)

// Start the Bulletin Board's main operations in a new goroutine
go func() {
Expand Down
38 changes: 0 additions & 38 deletions config/lastRegisteredClientsRelays.yml

This file was deleted.

23 changes: 13 additions & 10 deletions internal/model/bulletin_board/bulletin_board.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@ import (

// BulletinBoard keeps track of active relays and coordinates the start signal
type BulletinBoard struct {
Network map[int]*RelayView // Maps relay IDs to their respective RelayView structs.
Clients map[int]*ClientView // Maps client IDs to their respective ClientView structs.
mu sync.RWMutex // Mutex for read/write locking
lastStartRun time.Time // Timestamp of the last start signal sent.
timeBetweenRuns time.Duration // Minimum duration between consecutive start signals.
Network map[int]*RelayView // Maps relay IDs to their respective RelayView structs.
Clients map[int]*ClientView // Maps client IDs to their respective ClientView structs.
mu sync.RWMutex // Mutex for read/write locking
lastStartRun time.Time // Timestamp of the last start signal sent.
timeBetweenRuns time.Duration // Minimum duration between consecutive start signals.
tellNodesToRegister bool
}

// NewBulletinBoard creates a new bulletin board
func NewBulletinBoard() *BulletinBoard {
func NewBulletinBoard(tellNodesToRegister bool) *BulletinBoard {
lastStartRun, _ := utils.GetTimestamp()
return &BulletinBoard{
Network: make(map[int]*RelayView),
Clients: make(map[int]*ClientView),
lastStartRun: lastStartRun,
timeBetweenRuns: time.Millisecond * 10_000, // 10 seconds
Network: make(map[int]*RelayView),
Clients: make(map[int]*ClientView),
lastStartRun: lastStartRun,
timeBetweenRuns: time.Millisecond * 10_000, // 10 seconds
tellNodesToRegister: tellNodesToRegister,
}
}

Expand Down Expand Up @@ -78,6 +80,7 @@ var useLastMu sync.Mutex

// StartProtocol periodically checks if all nodes are ready and, if so, signals them to start a new run.
func (bb *BulletinBoard) StartProtocol(useLastRegistered bool) error {
useLastRegistered = useLastRegistered || bb.tellNodesToRegister
slog.Info("Starting protocol...", "useLastRegistered", useLastRegistered)
if useLastRegistered {
useLastMu.Lock()
Expand Down
67 changes: 0 additions & 67 deletions internal/model/bulletin_board/metrics/prometheus.yml

This file was deleted.

0 comments on commit d422610

Please sign in to comment.