fix bug on port forwarding feature (#629)

* fix bug on port forwarding feature

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* fix lint error

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
Denis Barbaron
2023-01-16 12:38:17 +01:00
committed by GitHub
parent 8b67366b05
commit f04738f9be
5 changed files with 46 additions and 22 deletions

View File

@@ -1,3 +1,7 @@
/**
* Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
var util = require('util')
var events = require('events')
var net = require('net')
@@ -76,7 +80,6 @@ function ForwardHandler(conn, options) {
function packetListener(id, packet) {
var dest = destHandlersById[id]
if (packet) {
if (!dest) {
// Let's create a new connection
@@ -132,6 +135,13 @@ function ForwardManager() {
this.remove(id)
}
for(const handlerId in handlersById) {
if (handlersById[handlerId].options.devicePort === options.devicePort) {
this.remove(handlerId)
break
}
}
var handler = new ForwardHandler(conn, options)
handler.on('end', endListener.bind(this))
@@ -145,11 +155,15 @@ function ForwardManager() {
if (handler) {
handler.end()
}
delete handlersById[id]
this.emit('remove', id)
}
this.removeAll = function() {
this.removeAll = function(manager) {
Object.keys(handlersById).forEach(function(id) {
handlersById[id].end()
delete handlersById[id]
manager.emit('remove', id)
})
}