mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 10:53:21 +02:00
* Upgrading STF for security reasons Signed-off-by: Denis barbaron <denis.barbaron@orange.com> * update semaphore files Signed-off-by: Denis barbaron <denis.barbaron@orange.com> * upgrading STF for security reasons v2 Signed-off-by: Denis barbaron <denis.barbaron@orange.com> * update yarn.lock file Signed-off-by: Denis barbaron <denis.barbaron@orange.com> --------- Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
/**
|
|
* Copyright © 2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
|
|
**/
|
|
|
|
var logger = require('../../util/logger')
|
|
var lifecycle = require('../../util/lifecycle')
|
|
var zmqutil = require('../../util/zmqutil')
|
|
|
|
module.exports = function(options) {
|
|
var log = logger.createLogger('triproxy')
|
|
|
|
if (options.name) {
|
|
logger.setGlobalIdentifier(options.name)
|
|
}
|
|
|
|
function proxy(to) {
|
|
return function() {
|
|
to.send([].slice.call(arguments))
|
|
}
|
|
}
|
|
|
|
// App/device output
|
|
var pub = zmqutil.socket('pub')
|
|
pub.bind(options.endpoints.pub)
|
|
log.info('PUB socket bound on', options.endpoints.pub)
|
|
|
|
// Coordinator input/output
|
|
var dealer = zmqutil.socket('dealer')
|
|
dealer.bind(options.endpoints.dealer)
|
|
dealer.on('message', proxy(pub))
|
|
log.info('DEALER socket bound on', options.endpoints.dealer)
|
|
|
|
// App/device input
|
|
var pull = zmqutil.socket('pull')
|
|
pull.bind(options.endpoints.pull)
|
|
pull.on('message', proxy(dealer))
|
|
log.info('PULL socket bound on', options.endpoints.pull)
|
|
|
|
lifecycle.observe(function() {
|
|
[pub, dealer, pull].forEach(function(sock) {
|
|
try {
|
|
sock.close()
|
|
}
|
|
catch (err) {
|
|
// No-op
|
|
}
|
|
})
|
|
})
|
|
}
|