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"
"sync"
"time"
"strings"
"github.com/RobertBendun/zeroconf/v2"
)
@ -25,7 +26,7 @@ func doHandshake(wg *sync.WaitGroup, service *zeroconf.ServiceEntry, remotes cha
var hs proto.HandshakeResponse
err := proto.CommandTimeout(target, proto.Handshake(), &hs, timeout)
if err == nil {
log.Println("Received handshake response", target, hs)
// log.Println("Received handshake response", target, hs)
remotes <- Remote{
Address: target,
Nick: hs.Nick,
@ -76,6 +77,17 @@ func registerRemotes(waitTime int) error {
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
}

View File

@ -59,7 +59,7 @@ func (router *Router) handleIncoming(incoming net.Conn) {
request := proto.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 response := handler(incoming, request); response != nil {