mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Reverse port forwarding UI actually works now.
This commit is contained in:
parent
99864fb223
commit
cecf08a244
10 changed files with 158 additions and 134 deletions
|
@ -2,6 +2,7 @@ var net = require('net')
|
|||
|
||||
var Promise = require('bluebird')
|
||||
var syrup = require('syrup')
|
||||
var _ = require('lodash')
|
||||
|
||||
var wire = require('../../../../wire')
|
||||
var logger = require('../../../../util/logger')
|
||||
|
@ -61,33 +62,37 @@ module.exports = syrup.serial()
|
|||
})
|
||||
}
|
||||
|
||||
plugin.createForward = function(port, to) {
|
||||
plugin.createForward = function(id, forward) {
|
||||
log.info(
|
||||
'Creating reverse port forward from ":%d" to "%s:%d"'
|
||||
, port
|
||||
, to.host
|
||||
, to.port
|
||||
'Creating reverse port forward "%s" from ":%d" to "%s:%d"'
|
||||
, id
|
||||
, forward.devicePort
|
||||
, forward.targetHost
|
||||
, forward.targetPort
|
||||
)
|
||||
return connectService(1)
|
||||
.then(function(out) {
|
||||
var header = new Buffer(4)
|
||||
header.writeUInt16LE(0, 0)
|
||||
header.writeUInt16LE(port, 2)
|
||||
header.writeUInt16LE(forward.devicePort, 2)
|
||||
out.write(header)
|
||||
return manager.add(port, out, to)
|
||||
return manager.add(id, out, forward)
|
||||
})
|
||||
}
|
||||
|
||||
plugin.removeForward = function(port) {
|
||||
log.info('Removing reverse port forward ":%d"', port)
|
||||
manager.remove(port)
|
||||
plugin.removeForward = function(id) {
|
||||
log.info('Removing reverse port forward "%s"', id)
|
||||
manager.remove(id)
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
plugin.connect = function(options) {
|
||||
var resolver = Promise.defer()
|
||||
|
||||
var conn = net.connect(options)
|
||||
var conn = net.connect({
|
||||
host: options.targetHost
|
||||
, port: options.targetPort
|
||||
})
|
||||
|
||||
function connectListener() {
|
||||
resolver.resolve(conn)
|
||||
|
@ -112,44 +117,29 @@ module.exports = syrup.serial()
|
|||
|
||||
group.on('leave', plugin.reset)
|
||||
|
||||
manager.on('add', function(port, to) {
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.DeviceForwardAddEvent(
|
||||
options.serial
|
||||
, port
|
||||
, to.host
|
||||
, to.port
|
||||
))
|
||||
])
|
||||
})
|
||||
var pushForwards = _.debounce(
|
||||
function() {
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.ReverseForwardsEvent(
|
||||
options.serial
|
||||
, manager.listAll()
|
||||
))
|
||||
])
|
||||
}
|
||||
, 200
|
||||
)
|
||||
|
||||
manager.on('remove', function(port) {
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.DeviceForwardRemoveEvent(
|
||||
options.serial
|
||||
, port
|
||||
))
|
||||
])
|
||||
})
|
||||
manager.on('add', pushForwards)
|
||||
manager.on('remove', pushForwards)
|
||||
|
||||
return startService()
|
||||
.then(awaitServer)
|
||||
.then(function() {
|
||||
|
||||
plugin.createForward(3000, {
|
||||
host: '127.0.0.1'
|
||||
, port: 3000
|
||||
})
|
||||
|
||||
router
|
||||
.on(wire.ForwardTestMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
plugin.connect({
|
||||
host: message.targetHost
|
||||
, port: message.targetPort
|
||||
})
|
||||
plugin.connect(message)
|
||||
.then(function(conn) {
|
||||
conn.end()
|
||||
push.send([
|
||||
|
@ -166,10 +156,7 @@ module.exports = syrup.serial()
|
|||
})
|
||||
.on(wire.ForwardCreateMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
plugin.createForward(message.devicePort, {
|
||||
host: message.targetHost
|
||||
, port: message.targetPort
|
||||
})
|
||||
plugin.createForward(message.id, message)
|
||||
.then(function() {
|
||||
push.send([
|
||||
channel
|
||||
|
@ -186,7 +173,7 @@ module.exports = syrup.serial()
|
|||
})
|
||||
.on(wire.ForwardRemoveMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
plugin.removeForward(message.devicePort)
|
||||
plugin.removeForward(message.id)
|
||||
.then(function() {
|
||||
push.send([
|
||||
channel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue