-
Notifications
You must be signed in to change notification settings - Fork 446
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
Conversation
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this test?
There was a problem hiding this comment.
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()) | ||
|
||
;[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-colon? 🤢
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