Repository navigation
Finalmask header-custom: Support Lua script as well - #7174
Closed
CluvexStudio wants to merge 2 commits into
Closed
CluvexStudio wants to merge 2 commits into
CluvexStudio wants to merge 2 commits into
Conversation
Member
|
我的意思是 lua mask 应该有能力在自己的地方完全实现 header custom 的功能 而不是再加一个lua |
Contributor
|
|
Contributor
Author
@Fangliding got it, one lua mask then. i'll move these hooks into a mask of their own, closing this one, the new pr will have the same hooks |
Member
|
|
Collaborator
|
全弄到 fm.lua 就行了,这样原有的配置方式不变, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
builds on the lua engine from #6823 and the noise hook from #7124, docs will follow once #909 is merged
--
header-customtakes ascript, which can't be set together withclients,servers,errorsor the udpclient,server. the script's path resolves like the other lua ones andinfraonly compiles it, so a typo is caught at startup while the pool is created the first time a layer needs a header-- tcp:
HandleHeader(stream, address, role)runs the whole handshake,stream:Write(bytes),stream:Read(size)andstream:Sleep(ms).roleisclientorserver, so one file serves both ends like the static config does. returning an error fails the connection, which is whatheader auth failedalready does, and a server canstream:Writea fake answer before it returns, the way the staticerrorssequences work-- udp:
HandleHeaderWrite(header, address, role)builds the prefix withheader:Add(bytes)andheader:AddRandom(size),HandleHeaderRead(packet, address, role)returns how many bytes to strip, or nil to drop the packet, and reads it throughpacket:Len(),packet:Byte(at),packet:Match(at, bytes)andpacket:Slice(from, to)-- no new module: the engine registers the public
RegisterLuaofxray.finalmask.noise, so a header script getsRandomandRandomBetweenfrom there, plusxray.logeverything a static header does can be written in lua: fixed bytes,
rand,randRangebyte by byte, the delays, the server's error answer, andcapture/reusebecome plain locals because a handshake happens in one call."mode": "standalone"still refuses a script, the udp handshake there would want its own hookno LTable on either path, one stream, one builder and one packet view per instance, reused, and the numbers are checked: a handshake takes at most 65535 bytes in and 65535 out, a udp header at most 1024, and every size, index and delay is validated before it is converted so a huge float or a nan can't slip through. a shared config can't make the hooks allocate without bound
the tcp hook holds its pooled instance for the handshake, since
stream:Readwaits for the peer. that is the half duplex part of @Meo597's idea, the payload never goes through lua, so this needs no event framework. if you'd rather wait for one, say so and i'll park the tcp halfBenchmarkLuaHeaderis in the package: per packet a udp header costs about ten times the static one, 424 bytes in eight allocations against 24 in three, so the static lists stay the better choice at high packet rates. the tcp hook runs once per connectiontimeouts: 30s for a handshake because it waits for the peer, 1s per udp packet, and the instance init stays 120s