本文整理匯總了TypeScript中smart-buffer.SmartBuffer.toBuffer方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript SmartBuffer.toBuffer方法的具體用法?TypeScript SmartBuffer.toBuffer怎麽用?TypeScript SmartBuffer.toBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類smart-buffer.SmartBuffer
的用法示例。
在下文中一共展示了SmartBuffer.toBuffer方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: sendSocks5CommandRequest
/**
* Sends Socks v5 final handshake request.
*/
private sendSocks5CommandRequest() {
const buff = new SmartBuffer();
buff.writeUInt8(0x05);
buff.writeUInt8(SocksCommand[this._options.command]);
buff.writeUInt8(0x00);
// ipv4, ipv6, domain?
if (net.isIPv4(this._options.destination.host)) {
buff.writeUInt8(Socks5HostType.IPv4);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
} else if (net.isIPv6(this._options.destination.host)) {
buff.writeUInt8(Socks5HostType.IPv6);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
} else {
buff.writeUInt8(Socks5HostType.Hostname);
buff.writeUInt8(this._options.destination.host.length);
buff.writeString(this._options.destination.host);
}
buff.writeUInt16BE(this._options.destination.port);
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader;
this._socket.write(buff.toBuffer());
this.state = SocksClientState.SentFinalHandshake;
}
示例2: sendSocks4InitialHandshake
/**
* Sends initial Socks v4 handshake request.
*/
private sendSocks4InitialHandshake() {
const userId = this._options.proxy.userId || '';
const buff = new SmartBuffer();
buff.writeUInt8(0x04);
buff.writeUInt8(SocksCommand[this._options.command]);
buff.writeUInt16BE(this._options.destination.port);
// Socks 4 (IPv4)
if (net.isIPv4(this._options.destination.host)) {
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
buff.writeStringNT(userId);
// Socks 4a (hostname)
} else {
buff.writeUInt8(0x00);
buff.writeUInt8(0x00);
buff.writeUInt8(0x00);
buff.writeUInt8(0x01);
buff.writeStringNT(userId);
buff.writeStringNT(this._options.destination.host);
}
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks4Response;
this._socket.write(buff.toBuffer());
}
示例3: createUDPFrame
/**
* Creates a SOCKS UDP Frame.
* @param options
*/
static createUDPFrame(options: SocksUDPFrameDetails): Buffer {
const buff = new SmartBuffer();
buff.writeUInt16BE(0);
buff.writeUInt8(options.frameNumber || 0);
// IPv4/IPv6/Hostname
if (net.isIPv4(options.remoteHost.host)) {
buff.writeUInt8(Socks5HostType.IPv4);
buff.writeUInt32BE(ip.toLong(options.remoteHost.host));
} else if (net.isIPv6(options.remoteHost.host)) {
buff.writeUInt8(Socks5HostType.IPv6);
buff.writeBuffer(ip.toBuffer(options.remoteHost.host));
} else {
buff.writeUInt8(Socks5HostType.Hostname);
buff.writeUInt8(Buffer.byteLength(options.remoteHost.host));
buff.writeString(options.remoteHost.host);
}
// Port
buff.writeUInt16BE(options.remoteHost.port);
// Data
buff.writeBuffer(options.data);
return buff.toBuffer();
}
示例4: sendSocks5UserPassAuthentication
/**
* Sends Socks v5 user & password auth handshake.
*
* Note: No auth and user/pass are currently supported.
*/
private sendSocks5UserPassAuthentication() {
const userId = this._options.proxy.userId || '';
const password = this._options.proxy.password || '';
const buff = new SmartBuffer();
buff.writeUInt8(0x01);
buff.writeUInt8(Buffer.byteLength(userId));
buff.writeString(userId);
buff.writeUInt8(Buffer.byteLength(password));
buff.writeString(password);
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks5UserPassAuthenticationResponse;
this._socket.write(buff.toBuffer());
this.state = SocksClientState.SentAuthentication;
}
示例5: sendSocks5InitialHandshake
/**
* Sends initial Socks v5 handshake request.
*/
private sendSocks5InitialHandshake() {
const buff = new SmartBuffer();
buff.writeUInt8(0x05);
// We should only tell the proxy we support user/pass auth if auth info is actually provided.
// Note: As of Tor v0.3.5.7+, if user/pass auth is an option from the client, by default it will always take priority.
if (this._options.proxy.userId || this._options.proxy.password) {
buff.writeUInt8(2);
buff.writeUInt8(Socks5Auth.NoAuth);
buff.writeUInt8(Socks5Auth.UserPass);
} else {
buff.writeUInt8(1);
buff.writeUInt8(Socks5Auth.NoAuth);
}
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks5InitialHandshakeResponse;
this._socket.write(buff.toBuffer());
this.state = SocksClientState.SentInitialHandshake;
}