diff --git a/.circleci/config.yml b/.circleci/config.yml index 134be09..06ef13f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 parameters: cmds: type: string - default: "ssl-auto-recorder ssl-log-converter ssl-log-cutter ssl-log-indexer ssl-log-player ssl-log-recorder ssl-log-stats ssl-vision-tracker-client" + default: "ssl-auto-recorder ssl-log-converter ssl-log-cutter ssl-log-indexer ssl-log-player ssl-log-recorder ssl-log-stats ssl-vision-tracker-client ssl-multicast-sources" jobs: test_go: diff --git a/Makefile b/Makefile index 6783143..674b1d8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CMDS = ssl-auto-recorder ssl-log-converter ssl-log-cutter ssl-log-indexer ssl-log-player ssl-log-recorder ssl-log-stats ssl-vision-tracker-client +CMDS = ssl-auto-recorder ssl-log-converter ssl-log-cutter ssl-log-indexer ssl-log-player ssl-log-recorder ssl-log-stats ssl-vision-tracker-client ssl-multicast-sources DOCKER_TARGETS = $(addprefix docker-, $(CMDS)) .PHONY: all docker test install proto $(DOCKER_TARGETS) diff --git a/cmd/ssl-multicast-sources/README.md b/cmd/ssl-multicast-sources/README.md new file mode 100644 index 0000000..fb8c4a2 --- /dev/null +++ b/cmd/ssl-multicast-sources/README.md @@ -0,0 +1,13 @@ +# ssl-multicast-sources + +Detect IPs of multicast message producers for debugging purposes. +By default, it looks for all multicast groups and ports that are used by default in the SSL. + +## Usage + +The binary is called `ssl-multicast-sources`. +Pass custom multicast IPs/ports like this: + +```shell +ssl-multicast-sources 224.5.23.1:10003 224.5.23.2:10006 +``` diff --git a/cmd/ssl-multicast-sources/main.go b/cmd/ssl-multicast-sources/main.go new file mode 100644 index 0000000..2d983c3 --- /dev/null +++ b/cmd/ssl-multicast-sources/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "flag" + "log" + "net" + "time" +) + +const maxDatagramSize = 8192 + +var detectedRemotes map[string][]string + +func main() { + flag.Parse() + + detectedRemotes = map[string][]string{} + mcAddresses := flag.Args() + if len(mcAddresses) == 0 { + mcAddresses = []string{"224.5.23.1:10003", "224.5.23.2:10006", "224.5.23.2:10010", "224.5.23.2:10012"} + } + + for _, address := range mcAddresses { + go watchAddress(address) + } + + for { + time.Sleep(1 * time.Second) + } +} + +func watchAddress(address string) { + addr, err := net.ResolveUDPAddr("udp", address) + if err != nil { + log.Fatal(err) + } + conn, err := net.ListenMulticastUDP("udp", nil, addr) + if err != nil { + log.Fatal(err) + } + if err := conn.SetReadBuffer(maxDatagramSize); err != nil { + log.Printf("Could not set read buffer to %v.", maxDatagramSize) + } + log.Println("Receiving from", address) + for { + _, udpAddr, err := conn.ReadFromUDP([]byte{0}) + if err != nil { + log.Print("Could not read: ", err) + time.Sleep(1 * time.Second) + continue + } + addRemote(address, udpAddr.IP.String()) + } +} + +func addRemote(address string, remote string) { + remotes, ok := detectedRemotes[address] + if !ok { + detectedRemotes[address] = []string{} + } + for _, a := range remotes { + if a == remote { + return + } + } + + detectedRemotes[address] = append(detectedRemotes[address], remote) + log.Printf("remote ip on %v: %v\n", address, remote) +}