11import Fastify from 'fastify' ;
22import { createServer } from 'node:http' ;
3- import { Mrrowisp } from "mrrowisp " ;
3+ import { server as wisp , logging } from "@mercuryworkshop/wisp-js/server " ;
44import createRammerhead from '../lib/rammerhead/src/server/index.js' ;
55import fastifyHelmet from '@fastify/helmet' ;
66import fastifyStatic from '@fastify/static' ;
@@ -21,40 +21,29 @@ import { existsSync, unlinkSync } from 'node:fs';
2121 */
2222console . log ( serverUrl ) ;
2323
24- const wisp = new Mrrowisp ( {
25- port : 6001 ,
26- allowUDP : false ,
27- allowLoopbackIPs : true ,
28- whitelist : {
29- ports : [ 80 , 443 , 9050 , 7000 , 7001 ] ,
30- } ,
31- tcpBufferSize : 65535 ,
32- streamLimitPerHost : 256 ,
33- streamLimitTotal : 8192 ,
34- dnsTTLSeconds : 300 ,
35- dnsMethod : "resolve" ,
36- dnsResultOrder : "ipv4first" ,
37- enableV2 : true ,
38- bandwidthLimitKbps : 51200 ,
39- connectionsLimitPerIP : 100 ,
40- connectionWindowSeconds : 10 ,
41- maxMessageSize : 262144 ,
42- writeTimeoutSeconds : 30 ,
43- frameReadTimeoutSeconds : 60 ,
44- banDurationSeconds : 86400 ,
45- banMaxStrikes : 5 ,
46- banEscalationMultiplier : 2 ,
47- maxHandshakeFailures : 20 ,
48- maxPacketRate : 2000 ,
49- maxConnectionLifetimeSeconds : 7200 ,
50- maxStreamsPerConnection : 256 ,
51- maxConnectionsPerIP : 100 ,
52- globalMaxConnections : 10000 ,
53- writeQueueSize : 16384 ,
54- maxInboundBytesPerSecond : 10485760 ,
55- } ) ;
56-
57- wisp . start ( ) ;
24+ // Wisp Configuration: Refer to the documentation at https://www.npmjs.com/package/@mercuryworkshop /wisp-js
25+
26+ logging . set_level ( logging . NONE ) ;
27+ wisp . options . allow_udp_streams = false ;
28+ wisp . options . allow_loopback_ips = true ;
29+
30+ // For security reasons only allow these ports. Any additional regional proxies or default sandboxed Tor ports should be added here.
31+ wisp . options . port_whitelist = [
32+ 80 ,
33+ 443 ,
34+ 9050 ,
35+ 7000 ,
36+ 7001
37+ ] ;
38+
39+ wisp . options . port_blacklist = [
40+ [ 6881 , 6889 ] ,
41+ 6969 ,
42+ 1337 ,
43+ [ 6969 , 6969 ] ,
44+ 51413 ,
45+ [ 49152 , 65535 ]
46+ ] ;
5847
5948// The server will check for the existence of this file when a shutdown is requested.
6049// The shutdown script in run-command.js will temporarily produce this file.
@@ -80,8 +69,8 @@ const rammerheadScopes = [
8069] . map ( ( pathname ) => pathname . replace ( '/' , serverUrl . pathname ) ) ;
8170
8271const rammerheadSession = new RegExp (
83- `^${ serverUrl . pathname . replaceAll ( '.' , '\\.' ) } [a-z0-9]{32}`
84- ) ,
72+ `^${ serverUrl . pathname . replaceAll ( '.' , '\\.' ) } [a-z0-9]{32}`
73+ ) ,
8574 shouldRouteRh = ( req ) => {
8675 try {
8776 const url = new URL ( req . url , serverUrl ) ;
@@ -112,7 +101,7 @@ const serverFactory = (handler) => {
112101 . on ( 'upgrade' , ( req , socket , head ) => {
113102 if ( shouldRouteRh ( req ) ) routeRhUpgrade ( req , socket , head ) ;
114103 else if ( req . url . endsWith ( getAltPrefix ( 'wisp' , serverUrl . pathname ) ) )
115- wisp . route ( req , socket , head ) ;
104+ wisp . routeRequest ( req , socket , head ) ;
116105 } ) ;
117106} ;
118107
@@ -195,33 +184,33 @@ app.register(fastifyStatic, {
195184 */
196185
197186const supportedTypes = {
198- default : config . disguiseFiles ? 'image/vnd.microsoft.icon' : 'text/html' ,
199- html : 'text/html' ,
200- txt : 'text/plain' ,
201- xml : 'application/xml' ,
202- ico : 'image/vnd.microsoft.icon' ,
203- } ,
187+ default : config . disguiseFiles ? 'image/vnd.microsoft.icon' : 'text/html' ,
188+ html : 'text/html' ,
189+ txt : 'text/plain' ,
190+ xml : 'application/xml' ,
191+ ico : 'image/vnd.microsoft.icon' ,
192+ } ,
204193 disguise = 'ico' ;
205194
206195if ( config . disguiseFiles ) {
207196 const getActualPath = ( path ) =>
208- path . slice ( 0 , path . length - 1 - disguise . length ) ,
197+ path . slice ( 0 , path . length - 1 - disguise . length ) ,
209198 shouldNotHandle = new RegExp ( `\\.(?!html$|${ disguise } $)[\\w-]+$` , 'i' ) ,
210199 loaderFile = tryReadFile (
211200 '../views/dist/pages/misc/deobf/loader.html' ,
212201 import . meta. url ,
213202 false
214203 ) ;
215204 let exemptDirs = [
216- 'assets' ,
217- 'uv' ,
218- 'scram' ,
219- 'epoxy' ,
220- 'libcurl' ,
221- 'baremux' ,
222- 'wisp' ,
223- 'chii' ,
224- ] . map ( ( dir ) => getAltPrefix ( dir , serverUrl . pathname ) . slice ( 1 , - 1 ) ) ,
205+ 'assets' ,
206+ 'uv' ,
207+ 'scram' ,
208+ 'epoxy' ,
209+ 'libcurl' ,
210+ 'baremux' ,
211+ 'wisp' ,
212+ 'chii' ,
213+ ] . map ( ( dir ) => getAltPrefix ( dir , serverUrl . pathname ) . slice ( 1 , - 1 ) ) ,
225214 exemptPages = [ 'login' , 'test-shutdown' , 'favicon.ico' ] ;
226215 for ( const [ key , value ] of Object . entries ( externalPages ) )
227216 if ( 'string' === typeof value ) exemptPages . push ( key ) ;
@@ -292,7 +281,6 @@ app.get(serverUrl.pathname + ':path', (req, reply) => {
292281 // is present, gracefully shut the server down.
293282 if ( reqPath === 'test-shutdown' && existsSync ( shutdown ) ) {
294283 console . log ( 'InvisiProxy is shutting down.' ) ;
295- wisp . stop ( ) ;
296284 app . close ( ) ;
297285 unlinkSync ( shutdown ) ;
298286 process . exitCode = 0 ;
0 commit comments