Log found hosts

This commit is contained in:
Robert Bendun 2023-01-06 09:01:52 +01:00
parent a08389b60f
commit d2f7562f05
2 changed files with 14 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"net" "net"
"sync" "sync"
"time" "time"
"strings"
"github.com/RobertBendun/zeroconf/v2" "github.com/RobertBendun/zeroconf/v2"
) )
@ -25,7 +26,7 @@ func doHandshake(wg *sync.WaitGroup, service *zeroconf.ServiceEntry, remotes cha
var hs proto.HandshakeResponse var hs proto.HandshakeResponse
err := proto.CommandTimeout(target, proto.Handshake(), &hs, timeout) err := proto.CommandTimeout(target, proto.Handshake(), &hs, timeout)
if err == nil { if err == nil {
log.Println("Received handshake response", target, hs) // log.Println("Received handshake response", target, hs)
remotes <- Remote{ remotes <- Remote{
Address: target, Address: target,
Nick: hs.Nick, Nick: hs.Nick,
@ -76,6 +77,17 @@ func registerRemotes(waitTime int) error {
remotes[remote.Address] = &remote remotes[remote.Address] = &remote
} }
msg := &strings.Builder{}
comma := false
for _, remote := range remotes {
if comma {
fmt.Fprint(msg, ", ")
}
fmt.Fprintf(msg, "%s@%s", remote.Nick, remote.Address)
comma = true
}
log.Println("Hosts found:", msg.String())
return <-done return <-done
} }

View File

@ -59,7 +59,7 @@ func (router *Router) handleIncoming(incoming net.Conn) {
request := proto.Request{} request := proto.Request{}
json.NewDecoder(incoming).Decode(&request) json.NewDecoder(incoming).Decode(&request)
log.Printf("%s: %+v\n", incoming.RemoteAddr(), request) // log.Printf("%s: %+v\n", incoming.RemoteAddr(), request)
if handler, ok := router.routes[request.Type]; ok { if handler, ok := router.routes[request.Type]; ok {
if response := handler(incoming, request); response != nil { if response := handler(incoming, request); response != nil {