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 support for NAT traversal techniques #1051

Open
wants to merge 7 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 NAt support for HTTP server

  • Loading branch information
yciabaud committed Feb 22, 2017
commit 3bc4205af956ad44fad87de8ca72e85ad7541eb6
@@ -10,13 +10,15 @@ var url = require('url')

function Server (torrent, opts) {
var server = http.createServer(opts)
var natTraversal = require('./nat-traversal')

var sockets = []
var pendingReady = []
var closed = false

server.on('connection', onConnection)
server.on('request', onRequest)
server.on('listening', onListening)

var _close = server.close
server.close = function (cb) {
@@ -36,6 +38,10 @@ function Server (torrent, opts) {
socket.destroy()
})

if (server.address()) {
natTraversal.portUnMapping(server.address().port)
}

// Only call `server.close` if user has not called it already
if (closed) process.nextTick(cb)
else server.close(cb)
@@ -134,5 +140,9 @@ function Server (torrent, opts) {
}
}

function onListening () {
natTraversal.portMapping(server.address().port)
}

return server
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.