presets: use onInitTargetAddress() instead of onNotified() to get target address
This commit is contained in:
parent
805bf7fb9f
commit
d1dedef8e6
@ -99,6 +99,11 @@ export default class BaseAuthPreset extends IPresetAddressing {
|
||||
}
|
||||
}
|
||||
|
||||
onInitTargetAddress({ host, port }) {
|
||||
this._host = Buffer.from(host);
|
||||
this._port = numberToBuffer(port);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this._cipher = null;
|
||||
this._decipher = null;
|
||||
@ -107,14 +112,6 @@ export default class BaseAuthPreset extends IPresetAddressing {
|
||||
this._port = null;
|
||||
}
|
||||
|
||||
onNotified(action) {
|
||||
if (this._config.is_client && action.type === CONNECT_TO_REMOTE) {
|
||||
const { host, port } = action.payload;
|
||||
this._host = Buffer.from(host);
|
||||
this._port = numberToBuffer(port);
|
||||
}
|
||||
}
|
||||
|
||||
encodeHeader() {
|
||||
const header = Buffer.concat([numberToBuffer(this._host.length, 1), this._host, this._port]);
|
||||
const encHeader = this._cipher.update(header);
|
||||
|
@ -58,16 +58,6 @@ export class IPreset {
|
||||
|
||||
}
|
||||
|
||||
// callbacks
|
||||
|
||||
/**
|
||||
* how to handle the action, return false/undefined to continue delivery
|
||||
* @returns {boolean}
|
||||
*/
|
||||
onNotified(action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* you can do something when preset destroyed
|
||||
*/
|
||||
@ -164,4 +154,13 @@ export class IPreset {
|
||||
*/
|
||||
export class IPresetAddressing extends IPreset {
|
||||
|
||||
/**
|
||||
* triggered once target address resolved on client side
|
||||
* @param host
|
||||
* @param port
|
||||
*/
|
||||
onInitTargetAddress({ host, port }) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ function checkPresetClass(clazz) {
|
||||
}
|
||||
// check require hooks
|
||||
const requiredMethods = [
|
||||
'onNotified', 'onDestroy', 'onInit',
|
||||
'onDestroy', 'onInit',
|
||||
'beforeOut', 'beforeIn', 'clientOut', 'serverIn', 'serverOut', 'clientIn',
|
||||
'beforeOutUdp', 'beforeInUdp', 'clientOutUdp', 'serverInUdp', 'serverOutUdp', 'clientInUdp'
|
||||
];
|
||||
|
@ -78,22 +78,19 @@ export default class SsBasePreset extends IPresetAddressing {
|
||||
return this._headSize;
|
||||
}
|
||||
|
||||
onInitTargetAddress({ host, port }) {
|
||||
const type = getHostType(host);
|
||||
this._atyp = type;
|
||||
this._port = numberToBuffer(port);
|
||||
this._host = type === ATYP_DOMAIN ? Buffer.from(host) : ip.toBuffer(host);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this._pending = null;
|
||||
this._host = null;
|
||||
this._port = null;
|
||||
}
|
||||
|
||||
onNotified(action) {
|
||||
if (this._config.is_client && action.type === CONNECT_TO_REMOTE) {
|
||||
const { host, port } = action.payload;
|
||||
const type = getHostType(host);
|
||||
this._atyp = type;
|
||||
this._port = numberToBuffer(port);
|
||||
this._host = type === ATYP_DOMAIN ? Buffer.from(host) : ip.toBuffer(host);
|
||||
}
|
||||
}
|
||||
|
||||
encodeHeader() {
|
||||
const head = Buffer.from([
|
||||
this._atyp,
|
||||
|
@ -235,6 +235,13 @@ export default class V2rayVmessPreset extends IPresetAddressing {
|
||||
this._adBuf.on('data', this.onChunkReceived.bind(this));
|
||||
}
|
||||
|
||||
onInitTargetAddress({ host, port }) {
|
||||
const type = getAddrType(host);
|
||||
this._atyp = type;
|
||||
this._port = ntb(port);
|
||||
this._host = (type === ATYP_DOMAIN) ? Buffer.from(host) : ip.toBuffer(host);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this._adBuf.clear();
|
||||
this._adBuf = null;
|
||||
@ -251,19 +258,6 @@ export default class V2rayVmessPreset extends IPresetAddressing {
|
||||
this._chunkLenDecMaskGenerator = null;
|
||||
}
|
||||
|
||||
onNotified(action) {
|
||||
if (this._config.is_client && action.type === CONNECT_TO_REMOTE) {
|
||||
const { host, port } = action.payload;
|
||||
const type = getAddrType(host);
|
||||
this._atyp = type;
|
||||
this._port = ntb(port);
|
||||
this._host = (type === ATYP_DOMAIN) ? Buffer.from(host) : ip.toBuffer(host);
|
||||
}
|
||||
// if (action.type === CONNECTION_WILL_CLOSE) {
|
||||
// this.next(PIPE_ENCODE, Buffer.alloc(2));
|
||||
// }
|
||||
}
|
||||
|
||||
beforeOut({ buffer }) {
|
||||
if (!this._isHeaderSent) {
|
||||
this._isHeaderSent = true;
|
||||
@ -293,7 +287,7 @@ export default class V2rayVmessPreset extends IPresetAddressing {
|
||||
this._adBuf.put(buffer, { next, fail });
|
||||
}
|
||||
|
||||
serverIn({ buffer, next, fail }) {
|
||||
serverIn({ buffer, next, broadcast, fail }) {
|
||||
if (!this._isHeaderRecv) {
|
||||
|
||||
if (this._isBroadCasting) {
|
||||
@ -411,7 +405,7 @@ export default class V2rayVmessPreset extends IPresetAddressing {
|
||||
this._security = securityType;
|
||||
|
||||
this._isBroadCasting = true;
|
||||
this.broadcast({
|
||||
broadcast({
|
||||
type: CONNECT_TO_REMOTE,
|
||||
payload: {
|
||||
host: addrType === ATYP_DOMAIN ? addr.toString() : ip.toString(addr),
|
||||
|
Loading…
Reference in New Issue
Block a user