New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@holesail/hyper-cmd-lib-net

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@holesail/hyper-cmd-lib-net - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

110

index.js

@@ -0,3 +1,4 @@

const dgram = require('bare-dgram')
const EventEmitter = require('events')
function connPiper (connection, _dst, opts = {}, stats = {}) {

@@ -30,9 +31,9 @@ const loc = _dst()

loc.on('data', d => {
connection.write(d)
})
loc.on('data', d => {
connection.write(d)
})
connection.on('data', d => {
loc.write(d)
})
connection.on('data', d => {
loc.write(d)
})

@@ -78,52 +79,93 @@ loc.on('error', destroy).on('close', destroy)

function connRemoteCtrl (connection, opts = {}, stats = {}) {
if (!stats.remCnt) {
stats.remCnt = 0
class udpSocket {
constructor (opts) {
this.opts = opts
this.server = dgram.createSocket('udp4')
this.client = dgram.createSocket('udp4')
this.event = new EventEmitter()
this.rinfo = null
this.connect()
}
stats.remCnt++
connect () {
if (this.opts.bind) {
this.server.bind(this.opts.port, this.opts.host)
}
let destroyed = false
this.server.on('message', (msg, rinfo) => {
this.event.emit('message', msg, rinfo)
this.rinfo = rinfo
})
connection.on('error', destroy)
connection.on('close', destroy)
this.client.on('message', (response, rinfo) => {
this.event.emit('message', response)
})
connection.on('error', err => {
if (opts.debug) {
console.error(err)
}
})
this.client.on('error', (err) => {
console.error(`UDP error: \n${err.stack}`)
this.client.close()
})
}
function destroy (err) {
if (destroyed) {
return
write (msg) {
if (this.rinfo) {
this.server.send(msg, 0, msg.length, this.rinfo.port, this.rinfo.address)
} else {
this.client.send(msg, 0, msg.length, this.opts.port, this.opts.host)
}
}
}
stats.remCnt--
class udpConnPiper {
constructor (connection, _dst, opts = {}, stats = {}) {
this.loc = _dst()
this.connection = connection
destroyed = true
this.stats = {
rejectCnt: 0,
locCnt: 0,
remCnt: 0
}
connection.destroy(err)
this.destroyed = false
if (opts.onDestroy) {
opts.onDestroy(err)
}
// Connect
this.connect()
}
function send (data) {
if (destroyed) {
connect () {
if (this.loc === null) {
this.connection.destroy()
return
}
connection.write(data)
this.loc.event.on('message', (msg, rinfo) => {
this.connection.trySend(msg)
})
this.connection.on('message', (msg) => {
this.loc.write(msg)
})
this.loc.server.on('error', this.destroy).on('close', this.destroy)
this.connection.on('error', this.destroy).on('close', this.destroy)
}
return {
send
destroy (err) {
// TODO: Add destroy functionality
}
}
function udpConnect (opts) {
return new udpSocket(opts)
}
function udpPiper (connection, _dst, opts = {}, stats = {}) {
return new udpConnPiper(connection, _dst, opts = {}, stats = {})
}
module.exports = {
connPiper,
connRemoteCtrl
udpPiper,
udpConnect
}
{
"name": "@holesail/hyper-cmd-lib-net",
"version": "0.1.1",
"version": "0.2.0",
"description": "HyperCmd Net lib",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"repository": {

@@ -17,3 +15,9 @@ "type": "git",

},
"homepage": "https://github.com/holesail/hyper-cmd-lib-net/s"
"homepage": "https://github.com/holesail/hyper-cmd-lib-net/s",
"devDependencies": {
"standard": "^17.1.2"
},
"dependencies": {
"bare-dgram": "^1.0.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc