mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 17:18:25 +08:00
enhance node-vless udp...
This commit is contained in:
@@ -99,8 +99,14 @@ vlessWServer.on('connection', async function connection(ws) {
|
|||||||
async write(chunk: Buffer, controller) {
|
async write(chunk: Buffer, controller) {
|
||||||
if (udpClientStream) {
|
if (udpClientStream) {
|
||||||
const writer = udpClientStream.writable.getWriter();
|
const writer = udpClientStream.writable.getWriter();
|
||||||
// nodejs buffer will fill some byte, need offset is
|
// nodejs buffer to ArrayBuffer issue
|
||||||
writer.write(chunk.buffer.slice(chunk.byteOffset));
|
// https://nodejs.org/dist/latest-v18.x/docs/api/buffer.html#bufbuffer
|
||||||
|
writer.write(
|
||||||
|
chunk.buffer.slice(
|
||||||
|
chunk.byteOffset,
|
||||||
|
chunk.byteOffset + chunk.length
|
||||||
|
)
|
||||||
|
);
|
||||||
writer.releaseLock();
|
writer.releaseLock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -109,7 +115,10 @@ vlessWServer.on('connection', async function connection(ws) {
|
|||||||
// remoteConnection.write(chunk);
|
// remoteConnection.write(chunk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const vlessBuffer = chunk.buffer.slice(chunk.byteOffset);
|
const vlessBuffer = chunk.buffer.slice(
|
||||||
|
chunk.byteOffset,
|
||||||
|
chunk.byteOffset + chunk.length
|
||||||
|
);
|
||||||
const {
|
const {
|
||||||
hasError,
|
hasError,
|
||||||
message,
|
message,
|
||||||
@@ -299,7 +308,6 @@ function makeUDPSocketStream(portRemote, address) {
|
|||||||
chunk.slice(index + 2, index + 2 + udpPakcetLength)
|
chunk.slice(index + 2, index + 2 + udpPakcetLength)
|
||||||
);
|
);
|
||||||
index = index + 2 + udpPakcetLength;
|
index = index + 2 + udpPakcetLength;
|
||||||
|
|
||||||
udpClient.send(udpData, portRemote, address, (err) => {
|
udpClient.send(udpData, portRemote, address, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user