fix: break packet bridge cycle (fix for https://github.com/microsoft/jacdac/issues/935)
This commit is contained in:
Родитель
819eacf49e
Коммит
e65d2c74d9
|
@ -14,6 +14,7 @@
|
|||
"build": "microbundle --no-compress",
|
||||
"watch": "microbundle watch",
|
||||
"devtools": "yarn build && node ./dist/cli.js devtools",
|
||||
"devtools:serial": "yarn build && node ./dist/cli.js devtools --serial",
|
||||
"devtools:usb": "yarn build && node ./dist/cli.js devtools --usb",
|
||||
"test:usb": "yarn build && node ./dist/cli.js stream --usb --packets --sensors",
|
||||
"publish:pi": "yarn build && scp -r ../jacdac-ts/dist/* pi@192.168.0.131:/home/pi/gh/jacdac-cli/node_modules/jacdac-ts/dist && scp -r ./dist/* pi@192.168.0.131:/home/pi/gh/jacdac-cli/dist"
|
||||
|
@ -38,7 +39,7 @@
|
|||
"dependencies": {
|
||||
"commander": "^9.0.0",
|
||||
"faye-websocket": "^0.11.4",
|
||||
"jacdac-ts": "^1.24.16"
|
||||
"jacdac-ts": "^1.24.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@semantic-release/exec": "^6.0.3",
|
||||
|
|
|
@ -7,9 +7,11 @@ import {
|
|||
printPacket,
|
||||
serializeToTrace,
|
||||
createProxyBridge,
|
||||
randomDeviceId,
|
||||
} from "jacdac-ts"
|
||||
import { createTransports, TransportsOptions } from "./transports"
|
||||
|
||||
const SENDER_FIELD = "__jacdac_sender"
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const WebSocket = require("faye-websocket")
|
||||
const http = require("http")
|
||||
|
@ -77,9 +79,12 @@ export async function devToolsCommand(
|
|||
})
|
||||
|
||||
// passive bus to sniff packets
|
||||
const bridge = createProxyBridge(data =>
|
||||
clients.forEach(c => c.send(Buffer.from(data)))
|
||||
)
|
||||
const bridge = createProxyBridge((data, sender) => {
|
||||
//console.log(sender)
|
||||
clients
|
||||
.filter(c => c[SENDER_FIELD] !== sender)
|
||||
.forEach(c => c.send(Buffer.from(data)))
|
||||
})
|
||||
const transports = createTransports(options)
|
||||
const bus = new JDBus(transports, {
|
||||
client: false,
|
||||
|
@ -103,9 +108,11 @@ export async function devToolsCommand(
|
|||
// is this a socket?
|
||||
if (WebSocket.isWebSocket(request)) {
|
||||
const client = new WebSocket(request, socket, body)
|
||||
const sender = Math.random() + ""
|
||||
const sender = "ws" + randomDeviceId()
|
||||
// store sender id to deduped packet
|
||||
client[SENDER_FIELD] = sender
|
||||
clients.push(client)
|
||||
log(`client: connected (${clients.length} clients)`)
|
||||
log(`client: connected (${sender}, ${clients.length} clients)`)
|
||||
client.on("message", event => {
|
||||
const { data } = event
|
||||
clients.filter(c => c !== client).forEach(c => c.send(data))
|
||||
|
@ -117,7 +124,8 @@ export async function devToolsCommand(
|
|||
})
|
||||
|
||||
const tcpServer = net.createServer(client => {
|
||||
const sender = Math.random() + ""
|
||||
const sender = "tcp" + randomDeviceId()
|
||||
client[SENDER_FIELD] = sender
|
||||
client.send = (pkt0: Buffer) => {
|
||||
const pkt = new Uint8Array(pkt0)
|
||||
const b = new Uint8Array(1 + pkt.length)
|
||||
|
@ -132,7 +140,7 @@ export async function devToolsCommand(
|
|||
}
|
||||
}
|
||||
clients.push(client)
|
||||
log(`client: connected (${clients.length} clients)`)
|
||||
log(`client: connected (${sender} ${clients.length} clients)`)
|
||||
let acc: Uint8Array
|
||||
client.on("data", (buf: Uint8Array) => {
|
||||
if (acc) {
|
||||
|
|
|
@ -4024,10 +4024,10 @@ issue-parser@^6.0.0:
|
|||
lodash.isstring "^4.0.1"
|
||||
lodash.uniqby "^4.7.0"
|
||||
|
||||
jacdac-ts@^1.24.16:
|
||||
version "1.24.16"
|
||||
resolved "https://registry.yarnpkg.com/jacdac-ts/-/jacdac-ts-1.24.16.tgz#e0fe156b7f84ca1dc9e384b6e457ee8c5d0454a7"
|
||||
integrity sha512-h6flgQf5hCV+uzwARv9CxMBZ4xosvOqfSkR6Q0cPcjcO209idk23YIRBrgDU4SlZG9EX6FgCHzEZ/KvlCHZzRA==
|
||||
jacdac-ts@^1.24.19:
|
||||
version "1.24.19"
|
||||
resolved "https://registry.yarnpkg.com/jacdac-ts/-/jacdac-ts-1.24.19.tgz#c55883aa4af0d73db2a7ef3a4035bc4fa4a1fc15"
|
||||
integrity sha512-wr9jzuPILKTIP2tV0CuNxCehHd4s89mohC4cmp4FXyesp4HpJ4XY8zCRZvwz8pG2Cd4GlvfDTj4PECUlKAWBrA==
|
||||
dependencies:
|
||||
"@types/node" "^17.0.17"
|
||||
"@types/w3c-web-serial" "^1.0.2"
|
||||
|
|
Загрузка…
Ссылка в новой задаче