core,presets: switch to use SOCKET_CONNECT_TO_REMOTE
This commit is contained in:
parent
d5d8dca99a
commit
5d4bd8c3a9
@ -13,9 +13,8 @@ import {
|
|||||||
} from './middleware';
|
} from './middleware';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SOCKET_CONNECT_TO_DST,
|
SOCKET_CONNECT_TO_REMOTE,
|
||||||
PROCESSING_FAILED,
|
PROCESSING_FAILED
|
||||||
PROXY_HANDSHAKE_DONE
|
|
||||||
} from '../presets/defs';
|
} from '../presets/defs';
|
||||||
|
|
||||||
const TRACK_CHAR_UPLOAD = '↑';
|
const TRACK_CHAR_UPLOAD = '↑';
|
||||||
@ -382,8 +381,7 @@ export class Socket extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
onPipeNotified(action) {
|
onPipeNotified(action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case PROXY_HANDSHAKE_DONE:
|
case SOCKET_CONNECT_TO_REMOTE: {
|
||||||
case SOCKET_CONNECT_TO_DST: {
|
|
||||||
const {targetAddress, onConnected} = action.payload;
|
const {targetAddress, onConnected} = action.payload;
|
||||||
if (__IS_SERVER__) {
|
if (__IS_SERVER__) {
|
||||||
// connect to destination
|
// connect to destination
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {PROXY_HANDSHAKE_DONE} from '../defs';
|
import {SOCKET_CONNECT_TO_REMOTE} from '../defs';
|
||||||
import SsBasePreset from '../ss-base';
|
import SsBasePreset from '../ss-base';
|
||||||
|
|
||||||
describe('SsBasePreset#clientOut', function () {
|
describe('SsBasePreset#clientOut', function () {
|
||||||
@ -6,7 +6,7 @@ describe('SsBasePreset#clientOut', function () {
|
|||||||
const preset = new SsBasePreset();
|
const preset = new SsBasePreset();
|
||||||
|
|
||||||
preset.onNotified({
|
preset.onNotified({
|
||||||
type: PROXY_HANDSHAKE_DONE,
|
type: SOCKET_CONNECT_TO_REMOTE,
|
||||||
payload: {
|
payload: {
|
||||||
targetAddress: {
|
targetAddress: {
|
||||||
type: 3,
|
type: 3,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
export const SOCKET_CONNECT_TO_DST = 'socket/connect/to/dst';
|
export const SOCKET_CONNECT_TO_REMOTE = 'socket/connect/to/remote';
|
||||||
export const PROXY_HANDSHAKE_DONE = 'socket/handshake/done';
|
|
||||||
export const PROCESSING_FAILED = 'processing/failed';
|
export const PROCESSING_FAILED = 'processing/failed';
|
||||||
|
|
||||||
export class IPreset {
|
export class IPreset {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import {EVP_BytesToKey, numberToBuffer, hmac, Xor} from '../utils';
|
import {EVP_BytesToKey, numberToBuffer, hmac, Xor} from '../utils';
|
||||||
import {IPreset, SOCKET_CONNECT_TO_DST, PROXY_HANDSHAKE_DONE} from './defs';
|
import {IPreset, SOCKET_CONNECT_TO_REMOTE} from './defs';
|
||||||
|
|
||||||
const IV_LEN = 16;
|
const IV_LEN = 16;
|
||||||
const HMAC_LEN = 16;
|
const HMAC_LEN = 16;
|
||||||
@ -76,7 +76,7 @@ export default class ExpBaseAuthStreamPreset extends IPreset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onNotified(action) {
|
onNotified(action) {
|
||||||
if (__IS_CLIENT__ && action.type === PROXY_HANDSHAKE_DONE) {
|
if (__IS_CLIENT__ && action.type === SOCKET_CONNECT_TO_REMOTE) {
|
||||||
const {host, port} = action.payload.targetAddress;
|
const {host, port} = action.payload.targetAddress;
|
||||||
this._host = Buffer.from(host);
|
this._host = Buffer.from(host);
|
||||||
this._port = numberToBuffer(port);
|
this._port = numberToBuffer(port);
|
||||||
@ -145,7 +145,7 @@ export default class ExpBaseAuthStreamPreset extends IPreset {
|
|||||||
|
|
||||||
// notify to connect to the real server
|
// notify to connect to the real server
|
||||||
broadcast({
|
broadcast({
|
||||||
type: SOCKET_CONNECT_TO_DST,
|
type: SOCKET_CONNECT_TO_REMOTE,
|
||||||
payload: {
|
payload: {
|
||||||
targetAddress: {
|
targetAddress: {
|
||||||
host: addr,
|
host: addr,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import net from 'net';
|
import net from 'net';
|
||||||
import ip from 'ip';
|
import ip from 'ip';
|
||||||
import {isValidHostname, numberToBuffer, hash} from '../utils';
|
import {isValidHostname, numberToBuffer, hash} from '../utils';
|
||||||
import {IPreset, SOCKET_CONNECT_TO_DST, PROXY_HANDSHAKE_DONE} from './defs';
|
import {IPreset, SOCKET_CONNECT_TO_REMOTE} from './defs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description
|
||||||
@ -65,7 +65,7 @@ export default class ExpBaseWithPaddingPreset extends IPreset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onNotified(action) {
|
onNotified(action) {
|
||||||
if (__IS_CLIENT__ && action.type === PROXY_HANDSHAKE_DONE) {
|
if (__IS_CLIENT__ && action.type === SOCKET_CONNECT_TO_REMOTE) {
|
||||||
const {host, port} = action.payload.targetAddress;
|
const {host, port} = action.payload.targetAddress;
|
||||||
this._host = Buffer.from(host);
|
this._host = Buffer.from(host);
|
||||||
this._port = numberToBuffer(port);
|
this._port = numberToBuffer(port);
|
||||||
@ -127,7 +127,7 @@ export default class ExpBaseWithPaddingPreset extends IPreset {
|
|||||||
|
|
||||||
// notify to connect to the real server
|
// notify to connect to the real server
|
||||||
broadcast({
|
broadcast({
|
||||||
type: SOCKET_CONNECT_TO_DST,
|
type: SOCKET_CONNECT_TO_REMOTE,
|
||||||
payload: {
|
payload: {
|
||||||
targetAddress: {
|
targetAddress: {
|
||||||
host: addr,
|
host: addr,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import ip from 'ip';
|
import ip from 'ip';
|
||||||
import {isValidHostname, numberToBuffer} from '../utils';
|
import {isValidHostname, numberToBuffer} from '../utils';
|
||||||
import {IPreset, SOCKET_CONNECT_TO_DST, PROXY_HANDSHAKE_DONE} from './defs';
|
import {IPreset, SOCKET_CONNECT_TO_REMOTE} from './defs';
|
||||||
|
|
||||||
const ATYP_V4 = 0x01;
|
const ATYP_V4 = 0x01;
|
||||||
const ATYP_V6 = 0x04;
|
const ATYP_V6 = 0x04;
|
||||||
@ -55,7 +55,7 @@ export default class SsBasePreset extends IPreset {
|
|||||||
_staging = Buffer.alloc(0);
|
_staging = Buffer.alloc(0);
|
||||||
|
|
||||||
onNotified(action) {
|
onNotified(action) {
|
||||||
if (__IS_CLIENT__ && action.type === PROXY_HANDSHAKE_DONE) {
|
if (__IS_CLIENT__ && action.type === SOCKET_CONNECT_TO_REMOTE) {
|
||||||
const {type, host, port} = action.payload.targetAddress;
|
const {type, host, port} = action.payload.targetAddress;
|
||||||
this._atyp = type;
|
this._atyp = type;
|
||||||
this._port = numberToBuffer(port);
|
this._port = numberToBuffer(port);
|
||||||
@ -137,7 +137,7 @@ export default class SsBasePreset extends IPreset {
|
|||||||
|
|
||||||
// notify to connect to the real server
|
// notify to connect to the real server
|
||||||
broadcast({
|
broadcast({
|
||||||
type: SOCKET_CONNECT_TO_DST,
|
type: SOCKET_CONNECT_TO_REMOTE,
|
||||||
payload: {
|
payload: {
|
||||||
targetAddress: {
|
targetAddress: {
|
||||||
type: atyp,
|
type: atyp,
|
||||||
|
Loading…
Reference in New Issue
Block a user