Skip to content

Export mdnsService struct or rename the Service interface for mDNS #3232

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

Open
melroy89 opened this issue Mar 9, 2025 · 2 comments
Open

Export mdnsService struct or rename the Service interface for mDNS #3232

melroy89 opened this issue Mar 9, 2025 · 2 comments

Comments

@melroy89
Copy link

melroy89 commented Mar 9, 2025

I would like to have my own struct, where I can assign mDNS service to mdns.NewMdnsService():

type MyStruct struct {
	mdnsService *mdns.mdnsService // Error: name mdnsService not exported by package  typesinternal#UnexportedName
}

// Meaning, this is currently NOT possible
MyStruct.mdnsService = mdns.NewMdnsService(p2pHost, "something", &mDNSNotifee{host: p2pHost})
if err := MyStruct.mdnsService.Start(); err != nil {
	panic(err)
} else {
	log.Println("mDNS service started")
}

If you would expose the mdns.mdnsService struct (just like you already do expose dht.IpfsDHT), I could assign it to my own struct.

Meaning it be much easier to later call a MyStruct.mdnsService.Close() on it for example. Maybe its just me, but I think it makes sense to export a struct that is getting returned by a public function.

@melroy89
Copy link
Author

melroy89 commented Mar 10, 2025

The solution should be as simple of starting with a capital letter m so MdnsService should make it an exported MdnsService type.

EDIT: I did notice this interface now type Service interface {:

https://github.com/distractedm1nd/go-libp2p/blob/160218ead08bfc5eb74bde427b5034eb49cba61f/p2p/discovery/mdns/mdns.go#L29

But that interface name is not really uniquely named, and can easily conflict. Should I use this interface instead? If so, maybe consider renaming the interface so something like MdnsService as well. Similar to: IDService: https://github.com/distractedm1nd/go-libp2p/blob/160218ead08bfc5eb74bde427b5034eb49cba61f/p2p/protocol/identify/id.go#L91

@melroy89 melroy89 changed the title Export mdnsService struct Export mdnsService struct or rename the Service interface for mDNS Mar 10, 2025
@sukunrt
Copy link
Member

sukunrt commented Mar 17, 2025

The interface name is mdns.Service which reads okay to me. I'd argue IDService is named inappropriately.

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

No branches or pull requests

2 participants