@outtacontrol/socks-router
Advanced tools
Comparing version 1.0.2 to 1.0.4
@@ -19,3 +19,3 @@ const { createServer } = require("@outtacontrol/socks"); | ||
// }, | ||
// execute(info, socket) { | ||
// intercept(info, socket) { | ||
// // do something with the socket... | ||
@@ -22,0 +22,0 @@ // } |
@@ -1,11 +0,11 @@ | ||
import { Route } from './interfaces/Route'; | ||
import { SocksRoute } from './interfaces/SocksRoute'; | ||
import { SocksConnectionCallback } from "./interfaces/SocksConnectionCallback"; | ||
export declare class Router { | ||
private routes; | ||
constructor(routes?: Route[]); | ||
use(route: Route): void; | ||
constructor(routes?: SocksRoute[]); | ||
use(route: SocksRoute): void; | ||
getHandler(): SocksConnectionCallback; | ||
} | ||
export declare function createRouter(routes?: Route[]): Router; | ||
export declare function createRouter(routes?: SocksRoute[]): Router; | ||
export default createRouter; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -14,2 +14,7 @@ "use strict"; | ||
for (const route of this.routes) { | ||
// execute bootstrap code if exist | ||
if (route.initialize && !route.isReady) { | ||
await route.initialize(); | ||
route.isReady = true; | ||
} | ||
const validDomain = isUriValid_1.isUriValid(info, route.uri); | ||
@@ -27,4 +32,4 @@ if (!validDomain) { | ||
else if (validated === true) { | ||
if (route.execute) { | ||
await route.execute(info, accept(true)); | ||
if (route.intercept) { | ||
await route.intercept(info, accept(true)); | ||
return; | ||
@@ -31,0 +36,0 @@ } |
/// <reference types="node" /> | ||
import { SocksProxyInfo } from "./SocksProxyInfo"; | ||
import { Socket } from "net"; | ||
export interface Execute { | ||
export interface SocksRouteInterceptor { | ||
(info: SocksProxyInfo, socket: Socket): Promise<void>; | ||
} | ||
//# sourceMappingURL=Execute.d.ts.map |
/// <reference types="node" /> | ||
import { Url } from "url"; | ||
import { Validator } from "./Validator"; | ||
import { Execute } from "./Execute"; | ||
export interface Route { | ||
uri?: Url; | ||
validate?: Validator; | ||
initialize?: ?validate; | ||
Validator: any; | ||
execute?: Execute; | ||
} | ||
//# sourceMappingURL=Route.d.ts.map |
import { SocksProxyInfo } from "./SocksProxyInfo"; | ||
export interface Validator { | ||
export interface SocksRouteValidator { | ||
(info: SocksProxyInfo): Promise<boolean | void>; | ||
} | ||
//# sourceMappingURL=Validator.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { Route } from "../interfaces/Route"; | ||
export declare function blacklist(list: string[]): Route; | ||
import { SocksRoute } from "../interfaces/SocksRoute"; | ||
export declare function blacklist(list: string[]): SocksRoute; | ||
//# sourceMappingURL=blacklist.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { Route } from "../interfaces/Route"; | ||
export declare function whitelist(list: string[]): Route; | ||
import { SocksRoute } from "../interfaces/SocksRoute"; | ||
export declare function whitelist(list: string[]): SocksRoute; | ||
//# sourceMappingURL=whitelist.d.ts.map |
{ | ||
"name": "@outtacontrol/socks-router", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "routes requests on the socks v5 server.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -18,3 +18,7 @@ # Universal Router | ||
// uri: {hostname: "...", port: "8080"}, | ||
// validate(info) { | ||
// | ||
// async initialize() { | ||
// // ... some initialization code (only executed once before an action takes place on the route) | ||
// }, | ||
// async validate(info) { | ||
// // // no return or empty return is just continuing the loop | ||
@@ -24,3 +28,3 @@ // // return true; // executes the interception method | ||
// }, | ||
// execute(info, socket) { | ||
// asnyc intercept(info, socket) { | ||
// // do something with the socket... | ||
@@ -27,0 +31,0 @@ // } |
import { Route } from './interfaces/Route'; | ||
import { SocksRoute } from './interfaces/SocksRoute'; | ||
import { SocksConnectionCallback } from "./interfaces/SocksConnectionCallback"; | ||
@@ -8,9 +8,9 @@ import { isUriValid } from "./util/isUriValid"; | ||
private routes: Route[]; | ||
private routes: SocksRoute[]; | ||
public constructor(routes: Route[] = []) { | ||
public constructor(routes: SocksRoute[] = []) { | ||
this.routes = routes; | ||
} | ||
public use(route: Route): void { | ||
public use(route: SocksRoute): void { | ||
this.routes.push(route); | ||
@@ -22,2 +22,9 @@ } | ||
for (const route of this.routes) { | ||
// execute bootstrap code if exist | ||
if (route.initialize && !route.isReady) { | ||
await route.initialize(); | ||
route.isReady = true; | ||
} | ||
const validDomain = isUriValid(info, route.uri); | ||
@@ -37,4 +44,4 @@ if (!validDomain) { | ||
else if (validated === true) { | ||
if (route.execute) { | ||
await route.execute(info, accept(true)); | ||
if (route.intercept) { | ||
await route.intercept(info, accept(true)); | ||
return; | ||
@@ -50,3 +57,3 @@ } | ||
export function createRouter(routes: Route[] = []): Router { | ||
export function createRouter(routes: SocksRoute[] = []): Router { | ||
let router = new Router(routes); | ||
@@ -53,0 +60,0 @@ return router; |
import { parse } from "url"; | ||
import { Route } from "../interfaces/Route"; | ||
import { SocksRoute } from "../interfaces/SocksRoute"; | ||
import { isUriValid } from '../util/isUriValid'; | ||
export function blacklist(list: string[]): Route { | ||
export function blacklist(list: string[]): SocksRoute { | ||
return { | ||
@@ -7,0 +7,0 @@ async validate(info) { |
import { parse } from "url"; | ||
import { Route } from "../interfaces/Route"; | ||
import { SocksRoute } from "../interfaces/SocksRoute"; | ||
import { isUriValid } from "../util/isUriValid"; | ||
export function whitelist(list: string[]): Route { | ||
export function whitelist(list: string[]): SocksRoute { | ||
return { | ||
@@ -7,0 +7,0 @@ async validate(info) { |
@@ -32,3 +32,3 @@ const assert = require('assert'); | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -79,3 +79,3 @@ } | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -127,3 +127,3 @@ } | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -130,0 +130,0 @@ } |
@@ -19,3 +19,3 @@ const assert = require('assert'); | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -39,3 +39,3 @@ } | ||
// host/port not defined => validate/execute | ||
testCases.push((async function testValidateExecute() { | ||
testCases.push((async function testValidateintercept() { | ||
const app = createRouter(); | ||
@@ -52,3 +52,3 @@ let callAcceptAmount = 0; | ||
}, | ||
async execute(info, socket) { | ||
async intercept(info, socket) { | ||
assert.deepEqual(info, { dstAddr: 'example.com', dstPort: 80 }); | ||
@@ -87,3 +87,3 @@ assert.ok(socket instanceof Socket, "socket must be defined"); | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -120,3 +120,3 @@ } | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -152,3 +152,3 @@ } | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -184,3 +184,3 @@ } | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -216,3 +216,3 @@ } | ||
}, | ||
async execute() { | ||
async intercept() { | ||
callExecuteAmount++; | ||
@@ -219,0 +219,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43638
81
753
37