Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying does not work for cases when advertising is delegated to another host. #93

Closed
akamensky opened this issue Sep 8, 2021 · 5 comments · Fixed by #176
Closed

Comments

@akamensky
Copy link

Your environment.

  • Version: v0.0.5
  • Browser: N/A
  • Other Information - N/A

What did you do?

I have a code that advertises A records on behalf of other hosts. Simple code to do that is (this code runs on a host with a different IP address):

package main

import (
	"github.com/davecheney/mdns"
	"fmt"
	"time"
)

func main() {
	err := mdns.Publish("test.local 60 IN A 10.0.1.0")
	if err != nil {
		panic(err)
	}
	fmt.Println("ok")
	time.Sleep(60 * time.Minute)
}

Then query it using code as in examples:

package main

import (
	"context"
	"fmt"
	"net"

	"github.com/pion/mdns"
	"golang.org/x/net/ipv4"
)

func main() {
	addr, err := net.ResolveUDPAddr("udp", mdns.DefaultAddress)
	if err != nil {
		panic(err)
	}

	l, err := net.ListenUDP("udp4", addr)
	if err != nil {
		panic(err)
	}

	server, err := mdns.Server(ipv4.NewPacketConn(l), &mdns.Config{})
	if err != nil {
		panic(err)
	}
	answer, src, err := server.Query(context.TODO(), "test.local")
	if err != nil {
		panic(err)
	}
	fmt.Println(answer)
	fmt.Println(src)
	fmt.Println(err)
}

What did you expect?

Querying using this library should work. It works using avahi client and it works using macos dns-sd. I expect that while the above code is running, querying using this library for "test.local" returns correct result.

What happened?

It hangs indefinitely.

@Sean-Der
Copy link
Member

Sean-Der commented Sep 8, 2021

If you apply #70 does it work?

Most of my attention is on https://github.com/pion/webrtc, but will try my best to get this working!

@akamensky
Copy link
Author

akamensky commented Sep 9, 2021

No, #70 does not fix it. I checked and the code returns here conn.go#L297 For some reason it sees it as empty response. Which it is not.

Debugging the code: err == "parsing/packing of this section has completed" in that if statement. But no error is returned back and no response is captured.

Running tcpdump I do see:

21:29:07.409061 enp2s0f0 M   IP 10.0.0.185.5353 > 224.0.0.251.5353: 0 A (QM)? test.local. (31)
21:29:07.409408 enp2s0f0 Out IP 10.0.0.3.5353 > 10.0.0.185.5353: 0- [0q] 1/0/0 A 10.0.1.0 (41)

So the question is sent and answer is sent back.

@edaniels
Copy link
Member

edaniels commented May 2, 2023

@akamensky if you're still interested, can you check if this is still an issue?

@edaniels
Copy link
Member

edaniels commented Feb 6, 2024

Looked into this. This does not work because when we listen to DefaultAddress = "224.0.0.0:5353", we will only ever get multicast responses back. In order to address this, we need to have Query begin using a unicast socket for queries. This will be more efficient and correct. When we do this, the client side is okay to listen on "0.0.0.0:0", since there does not need to be a dedicated way to listen for questions, just answers. This way, we are allowed to receive answers both from our joined multicast groups and unicast.

So, this will be fixed with #155 which comes behind #69

edaniels added a commit to edaniels/mdns that referenced this issue Feb 8, 2024
@edaniels
Copy link
Member

edaniels commented Feb 8, 2024

Verified #176 fixes this but need a review

edaniels added a commit to edaniels/mdns that referenced this issue Feb 8, 2024
edaniels added a commit to edaniels/mdns that referenced this issue Feb 8, 2024
edaniels added a commit that referenced this issue Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants