diff --git a/proxy/trojan/protocol.go b/proxy/trojan/protocol.go index 6b5f29f0e..0dddd2984 100644 --- a/proxy/trojan/protocol.go +++ b/proxy/trojan/protocol.go @@ -292,23 +292,20 @@ type PacketSplitReader struct { Payload *PacketPayload } -func (r *PacketSplitReader) ReadFrom(p []byte) (int, gonet.Addr, error) { - var err error - +func (r *PacketSplitReader) ReadFrom(p []byte) (n int, addr gonet.Addr, err error) { if r.Payload == nil || r.Payload.Buffer.IsEmpty() { r.Payload, err = r.Reader.ReadMultiBufferWithMetadata() if err != nil { - return 0, nil, err + return } } - addr := &gonet.UDPAddr{ + addr = &gonet.UDPAddr{ IP: r.Payload.Target.Address.IP(), Port: int(r.Payload.Target.Port), } - mb, nBytes := buf.SplitBytes(r.Payload.Buffer, p) - r.Payload.Buffer = mb + r.Payload.Buffer, n = buf.SplitBytes(r.Payload.Buffer, p) - return nBytes, addr, nil + return } diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index e8739a35f..10ab41e6d 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -210,7 +210,6 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade udpDispatcherConstructor := udp.NewSplitDispatcher switch s.packetEncoding { case packetaddr.PacketAddrType_None: - break case packetaddr.PacketAddrType_Packet: packetAddrDispatcherFactory := udp.NewPacketAddrDispatcherCreator(ctx) udpDispatcherConstructor = packetAddrDispatcherFactory.NewPacketAddrDispatcher