mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:13:24 +02:00
Reverse port forwarding works, but changes don't apply to new devices yet.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -59,7 +59,7 @@ module.exports = syrup.serial()
|
||||
|
||||
function createForward(data) {
|
||||
log.info(
|
||||
'Reverse forwarding port %d to %s:%d'
|
||||
'Reverse port forwarding port %d to %s:%d'
|
||||
, data.devicePort
|
||||
, data.targetHost
|
||||
, data.targetPort
|
||||
@@ -136,6 +136,7 @@ module.exports = syrup.serial()
|
||||
}
|
||||
|
||||
function removeForward(data) {
|
||||
log.info('Removing reverse port forwarding on port %d', data.devicePort)
|
||||
var forward = service.forwards[data.devicePort]
|
||||
if (forward) {
|
||||
forward.connection.end()
|
||||
@@ -152,7 +153,7 @@ module.exports = syrup.serial()
|
||||
})
|
||||
|
||||
function connectListener() {
|
||||
resolver.resolve()
|
||||
resolver.resolve(conn)
|
||||
}
|
||||
|
||||
function errorListener(err) {
|
||||
@@ -165,7 +166,6 @@ module.exports = syrup.serial()
|
||||
return resolver.promise.finally(function() {
|
||||
conn.removeListener('connect', connectListener)
|
||||
conn.removeListener('error', errorListener)
|
||||
conn.end()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ module.exports = syrup.serial()
|
||||
])
|
||||
})
|
||||
})
|
||||
.on(wire.ForwardMessage, function(channel, message) {
|
||||
.on(wire.ForwardCreateMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
createForward(message)
|
||||
.then(function() {
|
||||
@@ -225,13 +225,6 @@ module.exports = syrup.serial()
|
||||
])
|
||||
})
|
||||
})
|
||||
.on(wire.ForwardListMessage, function(channel) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay('success', listForwards())
|
||||
])
|
||||
})
|
||||
.on(wire.ForwardRemoveMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
removeForward(message)
|
||||
|
||||
Reference in New Issue
Block a user