Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-01-30 12:31:22 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-01-30 12:31:22 +0400
commitbf8abcb409c5d9b7f3586f64612f9a38b78e42ed (patch)
tree98af1268ceb3be0597a058607dadf375945ceee2
parent27b8c67131ab0ace621d76426f1d245ed15a65c4 (diff)
set wire options
-rw-r--r--index.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/index.js b/index.js
index 5646529..5e91800 100644
--- a/index.js
+++ b/index.js
@@ -21,6 +21,7 @@ var magnet = require('magnet-uri')
var Swarm = require('bittorrent-swarm')
var MAX_PEERS = 60
+var TIMEOUT = 10000
var METADATA_BLOCK_SIZE = 16 * 1024
var isChromeApp = !!(typeof window !== 'undefined' && window.chrome &&
@@ -74,4 +75,26 @@ var swarm = new Swarm(infoHash, peerId)
swarm.on('wire', function (wire) {
$('.connectedPeers span').text(swarm.wires.length)
+
+ // Send KEEP-ALIVE (every 60s) so peers will not disconnect the wire
+ wire.setKeepAlive(true)
+
+ // If peer supports DHT, send PORT message to report what port our DHT node
+ // is listening on
+ if (wire.peerExtensions.dht) {
+ // TODO: DHT doesn't support listening yet
+ // wire.port(dht.port)
+ }
+
+ // When peer sends PORT, add them to the routing table
+ wire.on('port', function (port) {
+ console.log('PORT', port)
+ // TODO: DHT doesn't have a routing table
+ // dht.add(wire.remoteAddress, port)
+ })
+
+ // Time to wait before considering requests timed out
+ wire.setTimeout(TIMEOUT)
+
+
})