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

Add proxy options to allow proxying tracker and peer connections #874

Open
wants to merge 16 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Add WebRTC proxy with electron-webrtc

  • Loading branch information
yciabaud committed Aug 9, 2016
commit 40fb20c11ed13ad71bcd01789d9765236e1819dc
104 index.js
@@ -124,54 +124,82 @@ function WebTorrent (opts) {
if (!self.proxyOpts.httpsAgent) {
self.proxyOpts.httpsAgent = new Socks.Agent(self.proxyOpts.socksProxy, true)
}
}
}

if (typeof TCPPool === 'function') {
self._tcpPool = new TCPPool(self)
// Convert proxy opts to electron API in webtorrent-hybrid
if (self.tracker.wrtc && self.tracker.wrtc.electronDaemon &&
self.proxyOpts && self.proxyOpts.socksProxy && self.proxyOpts.proxyPeerConnections) {
if (!self.proxyOpts.socksProxy.proxy.authentication && !self.proxyOpts.socksProxy.proxy.userid) {
var electronConfig = {
proxyRules: 'socks' + self.proxyOpts.socksProxy.proxy.type + '://' + self.proxyOpts.socksProxy.proxy.ipAddress + ':' + self.proxyOpts.socksProxy.proxy.port
}
self.tracker.wrtc.electronDaemon.eval('window.webContents.session.setProxy(' +
JSON.stringify(electronConfig) + ', function(){})', networkSettingsReady)
} else {
self.emit('error', 'SOCKS Proxy authentication is not available in electron-wrtc')
}
} else {
networkSettingsReady(null)
}
} else {
networkSettingsReady(null)
}
} else {
process.nextTick(function () {
self._onListening()
})
networkSettingsReady(null)
}

// stats
self._downloadSpeed = speedometer()
self._uploadSpeed = speedometer()
function networkSettingsReady (err) {
if (err) {
self._destroy(err)
}

if (opts.dht !== false && typeof DHT === 'function' /* browser exclude */) {
// use a single DHT instance for all torrents, so the routing table can be reused
self.dht = new DHT(extend({ nodeId: self.nodeId }, opts.dht))
if (typeof TCPPool === 'function') {
self._tcpPool = new TCPPool(self)
} else {
process.nextTick(function () {
self._onListening()
})
}

self.dht.once('error', function (err) {
self._destroy(err)
})
// stats
self._downloadSpeed = speedometer()
self._uploadSpeed = speedometer()

self.dht.once('listening', function () {
var address = self.dht.address()
if (address) self.dhtPort = address.port
})
if (opts.dht !== false && typeof DHT === 'function' /* browser exclude */) {
// use a single DHT instance for all torrents, so the routing table can be reused
self.dht = new DHT(extend({nodeId: self.nodeId}, opts.dht))

// Ignore warning when there are > 10 torrents in the client
self.dht.setMaxListeners(0)
self.dht.once('error', function (err) {
self._destroy(err)
})

self.dht.listen(self.dhtPort)
} else {
self.dht = false
}
self.dht.once('listening', function () {
var address = self.dht.address()
if (address) self.dhtPort = address.port
})

if (typeof loadIPSet === 'function' && opts.blocklist != null) {
loadIPSet(opts.blocklist, {
headers: {
'user-agent': 'WebTorrent/' + VERSION + ' (https://webtorrent.io)'
}
}, function (err, ipSet) {
if (err) return self.error('Failed to load blocklist: ' + err.message)
self.blocked = ipSet
ready()
})
} else {
process.nextTick(ready)
// Ignore warning when there are > 10 torrents in the client
self.dht.setMaxListeners(0)

self.dht.listen(self.dhtPort)
} else {
self.dht = false
}

debug('new webtorrent (peerId %s, nodeId %s)', self.peerId, self.nodeId)

if (typeof loadIPSet === 'function' && opts.blocklist != null) {
loadIPSet(opts.blocklist, {
headers: {
'user-agent': 'WebTorrent/' + VERSION + ' (https://webtorrent.io)'
}
}, function (err, ipSet) {
if (err) return self.error('Failed to load blocklist: ' + err.message)
self.blocked = ipSet
ready()
})
} else {
process.nextTick(ready)
}
}

function ready () {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.