diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
commit | 73471b1a52f242e86364ffb077ea6cadb3b07ae2 (patch) | |
tree | 43dbb7748e281f8d80f15326f489cdea10ec857d /server/controllers/tracker.ts | |
parent | c22419dd265c0c7185bf4197a1cb286eb3d8ebc0 (diff) | |
parent | f5305c04aae14467d6f957b713c5a902275cbb89 (diff) | |
download | PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.gz PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.zst PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.zip |
Merge branch 'release/v1.2.0'
Diffstat (limited to 'server/controllers/tracker.ts')
-rw-r--r-- | server/controllers/tracker.ts | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/server/controllers/tracker.ts b/server/controllers/tracker.ts index 9bc7586d1..1deb8c402 100644 --- a/server/controllers/tracker.ts +++ b/server/controllers/tracker.ts | |||
@@ -6,6 +6,7 @@ import * as proxyAddr from 'proxy-addr' | |||
6 | import { Server as WebSocketServer } from 'ws' | 6 | import { Server as WebSocketServer } from 'ws' |
7 | import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants' | 7 | import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants' |
8 | import { VideoFileModel } from '../models/video/video-file' | 8 | import { VideoFileModel } from '../models/video/video-file' |
9 | import { parse } from 'url' | ||
9 | 10 | ||
10 | const TrackerServer = bitTorrentTracker.Server | 11 | const TrackerServer = bitTorrentTracker.Server |
11 | 12 | ||
@@ -59,16 +60,26 @@ const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer) | |||
59 | trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) | 60 | trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) |
60 | trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { action: 'scrape' })) | 61 | trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { action: 'scrape' })) |
61 | 62 | ||
62 | function createWebsocketServer (app: express.Application) { | 63 | function createWebsocketTrackerServer (app: express.Application) { |
63 | const server = http.createServer(app) | 64 | const server = http.createServer(app) |
64 | const wss = new WebSocketServer({ server: server, path: '/tracker/socket' }) | 65 | const wss = new WebSocketServer({ noServer: true }) |
66 | |||
65 | wss.on('connection', function (ws, req) { | 67 | wss.on('connection', function (ws, req) { |
66 | const ip = proxyAddr(req, CONFIG.TRUST_PROXY) | 68 | ws['ip'] = proxyAddr(req, CONFIG.TRUST_PROXY) |
67 | ws['ip'] = ip | ||
68 | 69 | ||
69 | trackerServer.onWebSocketConnection(ws) | 70 | trackerServer.onWebSocketConnection(ws) |
70 | }) | 71 | }) |
71 | 72 | ||
73 | server.on('upgrade', (request, socket, head) => { | ||
74 | const pathname = parse(request.url).pathname | ||
75 | |||
76 | if (pathname === '/tracker/socket') { | ||
77 | wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request)) | ||
78 | } | ||
79 | |||
80 | // Don't destroy socket, we have Socket.IO too | ||
81 | }) | ||
82 | |||
72 | return server | 83 | return server |
73 | } | 84 | } |
74 | 85 | ||
@@ -76,7 +87,7 @@ function createWebsocketServer (app: express.Application) { | |||
76 | 87 | ||
77 | export { | 88 | export { |
78 | trackerRouter, | 89 | trackerRouter, |
79 | createWebsocketServer | 90 | createWebsocketTrackerServer |
80 | } | 91 | } |
81 | 92 | ||
82 | // --------------------------------------------------------------------------- | 93 | // --------------------------------------------------------------------------- |