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

fix(@libp2p/mdns): do not send TXT records that are too long #2014

Merged
merged 3 commits into from
Sep 1, 2023

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Sep 1, 2023

The data field of mDNS TXT records has a hard limit of 255 characters - some multiaddrs can be longer than this so filter them out before sending, otherwise remote peers can fail to parse our mDNS response.

We should also only be sending link-local addresses in mDNS responses so filter any non-link-local addresses out too, though go-libp2p includes loopback addresses even though it probably shouldn't (according to the mDNS spec which conflicts with our mDNS Peer Discovery spec) so we continue to do so as well.

Fixes #2012

The data field of mDNS TXT records has a hard limit of 255 characters
- some multiaddrs can be longer than this so filter them out before
sending.

We should also only be sending link-local, non-loopback addresses in
mDNS responses so filter those out too.
@achingbrain achingbrain requested a review from a team as a code owner September 1, 2023 06:54
Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are hard to follow but the src code changes make sense.

return
}
_onMdnsWarning (err: Error): void {
log.error('mdns warning', err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be .error or .info?

// TXT record fields have a max data length of 255 bytes
// see 6.1 - https://www.ietf.org/rfc/rfc6763.txt
if (data.length > 255) {
log('multiaddr %a is too long to use in mDNS query response', addr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely lead to a lot of circuit relay webtransport multiaddrs failing, won't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not failing, just being omitted from the mDNS response. go-libp2p just excludes all circuit addresses so I'm not sure if it's a big deal or not. My feeling is that mDNS is really for tcp/quic sort of addresses.

@@ -141,15 +142,6 @@ describe('MulticastDNS', () => {
await stop(mdnsC)
})

it('should start and stop with go-libp2p-mdns compat', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Historically go-libp2p-mdns didn't speak spec-compliant mDNS so we had a compatibility layer.

go-libp2p-mdns has since been updated to behave better so the compatibility layer was removed, this test should have gone too.


expect(pB.toString()).to.eql(id.toString())

;[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-colon? 🤢

@achingbrain achingbrain merged commit 4f19234 into master Sep 1, 2023
21 checks passed
@achingbrain achingbrain deleted the fix/do-not-send-invalid-mdns-answers branch September 1, 2023 17:00
This was referenced Jan 18, 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 this pull request may close these issues.

mDNS peer discovery stops working once a certain threshold is reached
2 participants