Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function connect (buffer) {
let binaryStream = binary.stream(buffer);
binaryStream
.word8('ver')
.word8('cmd')
.word8('rsv')
.word8('atyp')
.tap((args) => {
// capture the raw buffer
args.requestBuffer = buffer;
// verify version is appropriate
if (args.ver !== RFC_1928_VERSION) {
return end(RFC_1928_REPLIES.GENERAL_FAILURE, args);
}
// append socket to active sessions
function handshake (buffer) {
binary
.stream(buffer)
.word8('ver')
.word8('nmethods')
.buffer('methods', 'nmethods')
.tap(function (args) {
// verify version is appropriate
if (args.ver !== RFC_1928_VERSION) {
return end(RFC_1928_REPLIES.GENERAL_FAILURE, args);
}
// convert methods buffer to an array
var
acceptedMethods = [].slice.call(args.methods).reduce(function (methods, method) {
methods[method] = true;
return methods;
}, {}),
function handshake (buffer) {
binary
.stream(buffer)
.word8('ver')
.word8('nmethods')
.buffer('methods', 'nmethods')
.tap((args) => {
// verify version is appropriate
if (args.ver !== RFC_1928_VERSION) {
return end(RFC_1928_REPLIES.GENERAL_FAILURE, args);
}
// convert methods buffer to an array
let
acceptedMethods = [].slice.call(args.methods).reduce((methods, method) => {
methods[method] = true;
return methods;
}, {}),
constructor({ host, port = 5333 } = {}) {
super();
let self = this;
debug(`Connecting to ${host}:${port}`);
this.connection = net.createConnection({ host, port }, () => {
debug('Connection established');
});
binary.stream(this.connection)
.loop(function () {
this.peek(function() {
this.word8u('size');
})
.buffer('data', 'size')
.tap(function(vars) {
debug('fromRemoteClient', vars.data);
self.emit('data', vars.data);
});
});
}
Resolve: function (buff) {
//var decipher = crypto.createDecipher(algorithm, password);
buff = decipherGCM(buff, password);//试试看用GCM算法解码 //decipher.update(buff);
if (buff === null)
return null;//解码失败返回空
var msg = {};
binary
.stream(buff)
.word8('flag')//标识位1个字节
.word16be('len')//长度2个字节,代表后面的域名字符串的长度
.tap(function (args) {
args.dst = {};
this
.buffer('addr', args.len)
.tap(function (args) {
args.dst.addr = args.addr.toString();
});
})
.word16be('port')
.word64be('timestamp')
.tap(function (args) {
args.dst.port = args.port;
msg = args;