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: Inability to default to the utp peer type #2805

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SilentBot1
Copy link
Member

@SilentBot1 SilentBot1 commented Jun 7, 2024

What is the purpose of this pull request? (put an "X" next to item)

  • Documentation update
  • Bug fix
  • New feature
  • Other, please explain:

What changes did you make? (Give an overview)
Currently, due to hostonly being defined when client.blocked is truthy and client.blocked only being truthy when opts.blocklist is passed to the construction of the client, we could only successfully default to utp in edge cases.

webtorrent/lib/torrent.js

Lines 843 to 870 in 45b3b1a

let host
if (this.client.blocked) {
if (typeof peer === 'string') {
let parts
try {
parts = addrToIPPort(peer)
} catch (e) {
this._debug('ignoring peer: invalid %s', peer)
this.emit('invalidPeer', peer)
return false
}
host = parts[0]
} else if (typeof peer.remoteAddress === 'string') {
host = peer.remoteAddress
}
if (host && this.client.blocked.contains(host)) {
this._debug('ignoring peer: blocked %s', peer)
if (typeof peer !== 'string') peer.destroy()
this.emit('blockedPeer', peer)
return false
}
}
// if the utp connection fails to connect, then it is replaced with a tcp connection to the same ip:port
const type = (this.client.utp && this._isIPv4(host)) ? 'utp' : 'tcp'

webtorrent/index.js

Lines 170 to 183 in 45b3b1a

if (typeof loadIPSet === 'function' && opts.blocklist != null) {
loadIPSet(opts.blocklist, {
headers: {
'user-agent': `WebTorrent/${VERSION} (https://webtorrent.io)`
}
}, (err, ipSet) => {
if (err) return console.error(`Failed to load blocklist: ${err.message}`)
this.blocked = ipSet
ready()
})
} else {
queueMicrotask(ready)
}
}

In this PR, I make changes to ensures we always populate host, which allows the correct peer type to be defaulted.

Note: Defaulting to uTP in WebTorrent's current implementation, if a peer only supports TCP, it would take >21 seconds to fall back to a TCP connection. Due to this, I would recommend holding off this for the moment.

Which issue (if any) does this pull request address?

Is there anything you'd like reviewers to focus on?

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.

None yet

1 participant