From 3746c05d79e7b93f25130094c2083ca990b0e000 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 29 Jul 2015 00:26:44 -0700 Subject: [PATCH] restructure folders --- client.js | 6 +++--- lib/{ => client}/http-tracker.js | 4 ++-- lib/{ => client}/udp-tracker.js | 2 +- lib/{ => client}/websocket-tracker.js | 3 ++- lib/common.js | 1 + lib/{ => server}/parse-http.js | 2 +- lib/{ => server}/parse-udp.js | 2 +- lib/{ => server}/parse-websocket.js | 2 +- lib/{ => server}/swarm.js | 0 package.json | 4 ++-- server.js | 8 ++++---- 11 files changed, 18 insertions(+), 16 deletions(-) rename lib/{ => client}/http-tracker.js (99%) rename lib/{ => client}/udp-tracker.js (99%) rename lib/{ => client}/websocket-tracker.js (99%) rename lib/{ => server}/parse-http.js (98%) rename lib/{ => server}/parse-udp.js (98%) rename lib/{ => server}/parse-websocket.js (97%) rename lib/{ => server}/swarm.js (100%) diff --git a/client.js b/client.js index 67e5e71..7ea27ad 100644 --- a/client.js +++ b/client.js @@ -8,9 +8,9 @@ var parallel = require('run-parallel') var url = require('url') var common = require('./lib/common') -var HTTPTracker = require('./lib/http-tracker') // empty object in browser -var UDPTracker = require('./lib/udp-tracker') // empty object in browser -var WebSocketTracker = require('./lib/websocket-tracker') +var HTTPTracker = require('./lib/client/http-tracker') // empty object in browser +var UDPTracker = require('./lib/client/udp-tracker') // empty object in browser +var WebSocketTracker = require('./lib/client/websocket-tracker') inherits(Client, EventEmitter) diff --git a/lib/http-tracker.js b/lib/client/http-tracker.js similarity index 99% rename from lib/http-tracker.js rename to lib/client/http-tracker.js index 042ebdb..adaa525 100644 --- a/lib/http-tracker.js +++ b/lib/client/http-tracker.js @@ -7,7 +7,7 @@ var EventEmitter = require('events').EventEmitter var get = require('simple-get') var inherits = require('inherits') -var common = require('./common') +var common = require('../common') var HTTP_SCRAPE_SUPPORT = /\/(announce)[^\/]*$/ @@ -84,9 +84,9 @@ HTTPTracker.prototype.scrape = function (opts) { // TODO: Improve this interface HTTPTracker.prototype.setInterval = function (intervalMs) { var self = this + self._intervalMs = intervalMs clearInterval(self._interval) - self._intervalMs = intervalMs if (intervalMs) { // HACK var update = self.announce.bind(self, self.client._defaultAnnounceOpts()) diff --git a/lib/udp-tracker.js b/lib/client/udp-tracker.js similarity index 99% rename from lib/udp-tracker.js rename to lib/client/udp-tracker.js index bbd5eb3..983339b 100644 --- a/lib/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -9,7 +9,7 @@ var hat = require('hat') var inherits = require('inherits') var url = require('url') -var common = require('./common') +var common = require('../common') var TIMEOUT = 15000 diff --git a/lib/websocket-tracker.js b/lib/client/websocket-tracker.js similarity index 99% rename from lib/websocket-tracker.js rename to lib/client/websocket-tracker.js index b79d166..83ed105 100644 --- a/lib/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -9,7 +9,7 @@ var inherits = require('inherits') var Peer = require('simple-peer') var Socket = require('simple-websocket') -var common = require('./common') +var common = require('../common') // Use a socket pool, so tracker clients share WebSocket objects for the same server. // In practice, WebSockets are pretty slow to establish, so this gives a nice performance @@ -38,6 +38,7 @@ function WebSocketTracker (client, announceUrl, opts) { self._peers = {} // peers (offer id -> peer) self._socket = null + self._intervalMs = self.client._intervalMs // use client interval initially self._interval = null diff --git a/lib/common.js b/lib/common.js index a6f191a..ad9962d 100644 --- a/lib/common.js +++ b/lib/common.js @@ -5,6 +5,7 @@ var extend = require('xtend/mutable') exports.DEFAULT_ANNOUNCE_INTERVAL = 30 * 60 * 1000 // 30 minutes +exports.DEFAULT_ANNOUNCE_INTERVAL_WEBRTC = 60 * 1000 // 1 minute exports.DEFAULT_ANNOUNCE_PEERS = 50 exports.MAX_ANNOUNCE_PEERS = 82 diff --git a/lib/parse-http.js b/lib/server/parse-http.js similarity index 98% rename from lib/parse-http.js rename to lib/server/parse-http.js index fa044b4..c5cd9d8 100644 --- a/lib/parse-http.js +++ b/lib/server/parse-http.js @@ -1,6 +1,6 @@ module.exports = parseHttpRequest -var common = require('./common') +var common = require('../common') var REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/ diff --git a/lib/parse-udp.js b/lib/server/parse-udp.js similarity index 98% rename from lib/parse-udp.js rename to lib/server/parse-udp.js index 0499149..0eda11d 100644 --- a/lib/parse-udp.js +++ b/lib/server/parse-udp.js @@ -2,7 +2,7 @@ module.exports = parseUdpRequest var bufferEqual = require('buffer-equal') var ipLib = require('ip') -var common = require('./common') +var common = require('../common') function parseUdpRequest (msg, rinfo) { if (msg.length < 16) throw new Error('received packet is too short') diff --git a/lib/parse-websocket.js b/lib/server/parse-websocket.js similarity index 97% rename from lib/parse-websocket.js rename to lib/server/parse-websocket.js index 6b16bbc..944843a 100644 --- a/lib/parse-websocket.js +++ b/lib/server/parse-websocket.js @@ -1,6 +1,6 @@ module.exports = parseWebSocketRequest -var common = require('./common') +var common = require('../common') function parseWebSocketRequest (socket, params) { params = JSON.parse(params) // may throw diff --git a/lib/swarm.js b/lib/server/swarm.js similarity index 100% rename from lib/swarm.js rename to lib/server/swarm.js diff --git a/package.json b/package.json index 7617211..e1f37b4 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ }, "browser": { "./lib/common-node": false, - "./lib/http-tracker": false, - "./lib/udp-tracker": false, + "./lib/client/http-tracker": false, + "./lib/client/udp-tracker": false, "./server": false }, "bugs": { diff --git a/server.js b/server.js index 35b4d36..9360cdc 100644 --- a/server.js +++ b/server.js @@ -11,10 +11,10 @@ var string2compact = require('string2compact') var WebSocketServer = require('ws').Server var common = require('./lib/common') -var Swarm = require('./lib/swarm') -var parseHttpRequest = require('./lib/parse_http') -var parseUdpRequest = require('./lib/parse_udp') -var parseWebSocketRequest = require('./lib/parse_websocket') +var Swarm = require('./lib/server/swarm') +var parseHttpRequest = require('./lib/server/parse-http') +var parseUdpRequest = require('./lib/server/parse-udp') +var parseWebSocketRequest = require('./lib/server/parse-websocket') inherits(Server, EventEmitter)