Skip to content

Commit

Permalink
fix wrong socks package import;
Browse files Browse the repository at this point in the history
fix some double free;
fix twice websocket client handshake event handle
  • Loading branch information
selcarpa committed Jul 21, 2023
1 parent f84247d commit 496262d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/main/kotlin/inbounds/Socks.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package inbounds


import io.netty.contrib.handler.codec.socks.SocksMessage
import io.netty.contrib.handler.codec.socks.SocksProtocolVersion
import io.netty.contrib.handler.codec.socksx.SocksMessage
import io.netty.contrib.handler.codec.socksx.SocksVersion
import io.netty.contrib.handler.codec.socksx.v5.*
import io.netty5.channel.ChannelHandlerContext
import io.netty5.channel.SimpleChannelInboundHandler
Expand All @@ -23,8 +23,8 @@ class SocksServerHandler(private val inbound: Inbound) : SimpleChannelInboundHan
private var authed = false

public override fun messageReceived(ctx: ChannelHandlerContext, socksRequest: SocksMessage) {
when (socksRequest.protocolVersion()!!) {
SocksProtocolVersion.SOCKS5 -> socks5Connect(ctx, socksRequest)
when (socksRequest.version()!!) {
SocksVersion.SOCKS5 -> socks5Connect(ctx, socksRequest)
else -> {
ctx.close()
}
Expand Down Expand Up @@ -52,10 +52,10 @@ class SocksServerHandler(private val inbound: Inbound) : SimpleChannelInboundHan
if (inbound.socks5Setting?.auth != null || !authed) {
ctx.close()
}
if ((socksRequest as Socks5CommandRequest).type() === Socks5CommandType.CONNECT) {
if (socksRequest.type() === Socks5CommandType.CONNECT) {
ctx.pipeline().addLast(SocksServerConnectHandler(inbound))
ctx.pipeline().remove(this)
ctx.fireChannelRead(socksRequest)
ctx.pipeline().remove(this)
} else {
ctx.close()
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/stream/Surfer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.netty.contrib.handler.proxy.HttpProxyHandler
import io.netty.contrib.handler.proxy.ProxyConnectionEvent
import io.netty.contrib.handler.proxy.Socks5ProxyHandler
import io.netty5.bootstrap.Bootstrap
import io.netty5.buffer.Buffer
import io.netty5.channel.*
import io.netty5.channel.nio.AbstractNioByteChannel
import io.netty5.channel.socket.DatagramPacket
Expand Down Expand Up @@ -489,7 +490,13 @@ open class RelayInboundHandler(private val relayChannel: Channel, private val in
relayChannel.pipeline().names(),
msg.javaClass.name
)
relayChannel.writeAndFlush(msg).addListener {
relayChannel.writeAndFlush(
if (msg is Buffer) {
msg.copy()
}else{
msg
}
).addListener {
if (!it.isSuccess) {
logger.error(
"relay inbound write message:${msg.javaClass.name} to [${
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/stream/Websocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class WebsocketDuplexHandler(private val handleShakePromise: Promise<Channel>) :
if (evt is WebSocketHandshakeCompletionEvent) {
handleShakePromise.setSuccess(ctx.channel())
}
if (evt is WebSocketClientHandshakeCompletionEvent) {
handleShakePromise.setSuccess(ctx.channel())
super.channelInboundEvent(ctx, evt)
}
}


Expand Down

0 comments on commit 496262d

Please sign in to comment.