Skip to content

Commit

Permalink
✨ feat: Add server useObfs hook
Browse files Browse the repository at this point in the history
  • Loading branch information
MoIzadloo committed Apr 19, 2023
1 parent 88fcdde commit 6660b34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/helper/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AuthMethod } from './authMethod'
import Connection from './connection'
import { ObfsBuilder } from '../obfs/obfs'

interface Req {
connect: (connection: Connection) => void
Expand All @@ -15,13 +16,16 @@ export class Handlers {
public userId: (userId: string) => boolean
public auth: AuthMethod[]
public req: Req
public obfs: ObfsBuilder[]
constructor(
req: Req,
auth: AuthMethod[] = [],
obfs: ObfsBuilder[] = [],
userId: (userId: string) => boolean = () => true
) {
this.req = req
this.auth = auth
this.obfs = obfs
this.userId = userId
}
}
6 changes: 6 additions & 0 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Handlers } from '../helper/handlers'
import { AuthMethod } from '../helper/authMethod'
import { connect, associate, bind } from './handlers'
import Event from '../helper/event'
import { ObfsBuilder } from '../obfs/obfs'

type ConnectionListener = ((socket: net.Socket) => void) | undefined

Expand Down Expand Up @@ -104,6 +105,11 @@ export class Server {
return this
}

public useObfs(method: ObfsBuilder): Server {
this.handlers.obfs.push(method)
return this
}

/**
* Get the primary's server handle, and listen on it
* @param port - Port to listen on
Expand Down
3 changes: 3 additions & 0 deletions src/server/state/socks5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class ObfsState extends State {
private obfsMethods = [none(), http()]

parse(): void {
if (this.context.handlers.obfs.length > 0) {
this.obfsMethods = this.context.handlers.obfs
}
const message = this.context.cat()
for (const m of this.obfsMethods) {
const method = m(this.context, ObfsMethod.SERVER)
Expand Down

0 comments on commit 6660b34

Please sign in to comment.