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

Feature/163 global download upload limit #1040

Open
wants to merge 5 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

Set throttle streams for tcpIncoming peers

  • Loading branch information
chtrinh committed Feb 11, 2017
commit 462a1916fc1736fa9ede2ce0240e1500efad51de
@@ -143,18 +143,27 @@ Peer.prototype.onConnect = function () {
})
self.startHandshakeTimeout()

if (self.type.indexOf('tcp') !== -1) {
conn.pipe(self.swarm.client.throttleGroups.down.throttle())
.pipe(wire)
.pipe(self.swarm.client.throttleGroups.up.throttle())
.pipe(conn)
if (self.type === 'tcpOutgoing') {
self.setThrottlePipes()
} else {
conn.pipe(wire).pipe(conn)
}

if (self.swarm && !self.sentHandshake) self.handshake()
}

Peer.prototype.clearPipes = function () {
this.wire.unpipe()
this.conn.unpipe()
}

Peer.prototype.setThrottlePipes = function () {
this.conn.pipe(this.swarm.client.throttleGroups.down.throttle())
.pipe(this.wire)
.pipe(this.swarm.client.throttleGroups.up.throttle())
.pipe(this.conn)
}

/**
* Called when handshake is received from remote peer.
* @param {string} infoHash
@@ -106,6 +106,8 @@ TCPPool.prototype._onConnection = function (conn) {
var torrent = self._client.get(infoHash)
if (torrent) {
peer.swarm = torrent
peer.clearPipes()
peer.setThrottlePipes()
torrent._addIncomingPeer(peer)
peer.onHandshake(infoHash, peerId)
} else {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.