1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +02:00

Reverse port forwarding works, but changes don't apply to new devices yet.

This commit is contained in:
Simo Kinnunen 2014-04-15 15:52:00 +09:00
parent a1fa91a356
commit f8a2eeab26
6 changed files with 97 additions and 33 deletions

View file

@ -234,6 +234,10 @@ module.exports = function(options) {
io.on('connection', function(socket) {
var channels = []
, user = socket.handshake.user
, ip = socket.handshake.headers['x-forwarded-for'] ||
socket.handshake.address.address
socket.emit('socket.ip', ip)
function joinChannel(channel) {
channels.push(channel)
@ -483,6 +487,48 @@ module.exports = function(options) {
])
})
})
.on('forward.test', function(channel, responseChannel, data) {
joinChannel(responseChannel)
if (!data.targetHost || data.targetHost === 'localhost') {
data.targetHost = ip
}
push.send([
channel
, wireutil.transaction(
responseChannel
, new wire.ForwardTestMessage(data)
)
])
})
.on('forward.create', function(channel, responseChannel, data) {
if (!data.targetHost || data.targetHost === 'localhost') {
data.targetHost = ip
}
dbapi.addUserForward(user.email, data)
.then(function() {
joinChannel(responseChannel)
push.send([
channel
, wireutil.transaction(
responseChannel
, new wire.ForwardCreateMessage(data)
)
])
})
})
.on('forward.remove', function(channel, responseChannel, data) {
dbapi.removeUserForward(user.email, data.devicePort)
.then(function() {
joinChannel(responseChannel)
push.send([
channel
, wireutil.transaction(
responseChannel
, new wire.ForwardRemoveMessage(data)
)
])
})
})
})
.finally(function() {
// Clean up all listeners and subscriptions