Skip to content

Commit

Permalink
get multicast_ip from config
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Oct 30, 2024
1 parent a1d5371 commit 755a77b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var embedFS embed.FS
type Config struct {
NameOfDevice string `toml:"name"`
NameLanguage string `toml:"name_language"`
MulticastIP string `toml:"multicast_ip"`
Receive struct {
Directory string `toml:"directory"`
MaxFileSize int `toml:"max_file_size"`
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = ""
name_language = "en"
multicast_ip = "224.0.0.167" # https://en.wikipedia.org/wiki/Multicast_address

[receive]
directory = "uploads"
Expand Down
5 changes: 0 additions & 5 deletions pkg/discovery/discovery.go

This file was deleted.

10 changes: 6 additions & 4 deletions pkg/discovery/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (

// StartBroadcast sends a broadcast message
func StartBroadcast(conf *config.Config) {
slog.Info("Starting broadcast", "multicast_ip", conf.MulticastIP)

// Set the multicast address and port
multicastAddr := &net.UDPAddr{
IP: net.ParseIP(mulicastIP),
IP: net.ParseIP(conf.MulticastIP),
Port: 53317,
}

Expand Down Expand Up @@ -49,12 +51,12 @@ func StartBroadcast(conf *config.Config) {
}

// ListenForBroadcasts listens for UDP broadcast messages
func ListenForBroadcasts() {
slog.Info("Listening for broadcasts...")
func ListenForBroadcasts(conf *config.Config) {
slog.Info("Listening for broadcasts", "multicast_ip", conf.MulticastIP)

// Set the multicast address and port
multicastAddr := &net.UDPAddr{
IP: net.ParseIP(mulicastIP),
IP: net.ParseIP(conf.MulticastIP),
Port: 53317,
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/startup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Enable broadcast and monitoring functions
func StartDiscovery(conf *config.Config) {
go discovery.ListenForBroadcasts()
go discovery.ListenForBroadcasts(conf)
go discovery.StartBroadcast(conf)
go discovery.StartHTTPBroadcast(conf)
}
Expand Down

0 comments on commit 755a77b

Please sign in to comment.