mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
format code
This commit is contained in:
parent
7a24dc3e09
commit
78daf8a879
@ -11,9 +11,9 @@ const (
|
||||
func ReadFrom(reader io.Reader) ([]byte, error) {
|
||||
buffer := make([]byte, bufferSize)
|
||||
nBytes, err := reader.Read(buffer)
|
||||
if nBytes == 0 {
|
||||
buffer = nil
|
||||
}
|
||||
if nBytes == 0 {
|
||||
buffer = nil
|
||||
}
|
||||
return buffer[:nBytes], err
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ func dumpOutput(conn net.Conn, output chan<- []byte, finish *sync.Mutex, udp boo
|
||||
defer close(output)
|
||||
|
||||
response, err := v2net.ReadFrom(conn)
|
||||
log.Info("Freedom receives %d bytes from %s", len(response), conn.RemoteAddr().String())
|
||||
log.Info("Freedom receives %d bytes from %s", len(response), conn.RemoteAddr().String())
|
||||
if len(response) > 0 {
|
||||
output <- response
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
"time"
|
||||
|
||||
"github.com/v2ray/v2ray-core"
|
||||
"github.com/v2ray/v2ray-core/common/errors"
|
||||
@ -198,10 +198,10 @@ func (server *SocksServer) handleUDP(reader *v2net.TimeOutReader, writer io.Writ
|
||||
}
|
||||
|
||||
reader.SetTimeOut(300) /* 5 minutes */
|
||||
v2net.ReadFrom(reader) // Just in case of anything left in the socket
|
||||
// The TCP connection closes after this method returns. We need to wait until
|
||||
// the client closes it.
|
||||
// TODO: get notified from UDP part
|
||||
v2net.ReadFrom(reader) // Just in case of anything left in the socket
|
||||
// The TCP connection closes after this method returns. We need to wait until
|
||||
// the client closes it.
|
||||
// TODO: get notified from UDP part
|
||||
<-time.After(5 * time.Minute)
|
||||
|
||||
return nil
|
||||
|
@ -25,7 +25,7 @@ func (server *SocksServer) ListenUDP(port uint16) error {
|
||||
log.Error("Socks failed to listen UDP on port %d: %v", port, err)
|
||||
return err
|
||||
}
|
||||
// TODO: make this configurable
|
||||
// TODO: make this configurable
|
||||
udpAddress = v2net.IPAddress([]byte{127, 0, 0, 1}, port)
|
||||
|
||||
go server.AcceptPackets(conn)
|
||||
@ -44,7 +44,7 @@ func (server *SocksServer) AcceptPackets(conn *net.UDPConn) error {
|
||||
log.Error("Socks failed to read UDP packets: %v", err)
|
||||
continue
|
||||
}
|
||||
log.Info("Client UDP connection from %v", addr)
|
||||
log.Info("Client UDP connection from %v", addr)
|
||||
request, err := protocol.ReadUDPRequest(buffer[:nBytes])
|
||||
if err != nil {
|
||||
log.Error("Socks failed to parse UDP request: %v", err)
|
||||
@ -57,7 +57,7 @@ func (server *SocksServer) AcceptPackets(conn *net.UDPConn) error {
|
||||
}
|
||||
|
||||
udpPacket := v2net.NewPacket(request.Destination(), request.Data, false)
|
||||
log.Info("Send packet to %s with %d bytes", udpPacket.Destination().String(), len(request.Data))
|
||||
log.Info("Send packet to %s with %d bytes", udpPacket.Destination().String(), len(request.Data))
|
||||
go server.handlePacket(conn, udpPacket, addr, request.Address)
|
||||
}
|
||||
}
|
||||
@ -67,12 +67,12 @@ func (server *SocksServer) handlePacket(conn *net.UDPConn, packet v2net.Packet,
|
||||
close(ray.InboundInput())
|
||||
|
||||
if data, ok := <-ray.InboundOutput(); ok {
|
||||
response := &protocol.Socks5UDPRequest {
|
||||
Fragment: 0,
|
||||
Address: targetAddr,
|
||||
Data: data,
|
||||
}
|
||||
log.Info("Writing back UDP response with %d bytes from %s to %s", len(data), targetAddr.String(), clientAddr.String())
|
||||
response := &protocol.Socks5UDPRequest{
|
||||
Fragment: 0,
|
||||
Address: targetAddr,
|
||||
Data: data,
|
||||
}
|
||||
log.Info("Writing back UDP response with %d bytes from %s to %s", len(data), targetAddr.String(), clientAddr.String())
|
||||
udpMessage := response.Bytes(nil)
|
||||
nBytes, err := conn.WriteToUDP(udpMessage, clientAddr)
|
||||
if err != nil {
|
||||
|
@ -60,12 +60,12 @@ func (config VNextConfig) ToVNextServer(network string) VNextServer {
|
||||
panic(log.Error("Unable to parse VNext IP: %s", config.Address))
|
||||
}
|
||||
address := v2net.IPAddress(ip, config.Port)
|
||||
var dest v2net.Destination
|
||||
if network == "tcp" {
|
||||
dest = v2net.NewTCPDestination(address)
|
||||
} else {
|
||||
dest = v2net.NewUDPDestination(address)
|
||||
}
|
||||
var dest v2net.Destination
|
||||
if network == "tcp" {
|
||||
dest = v2net.NewTCPDestination(address)
|
||||
} else {
|
||||
dest = v2net.NewUDPDestination(address)
|
||||
}
|
||||
return VNextServer{
|
||||
Destination: dest,
|
||||
Users: users,
|
||||
|
@ -93,6 +93,6 @@ func (handler *VMessInboundHandler) handlePacket(conn *net.UDPConn, request *pro
|
||||
|
||||
if hasData {
|
||||
conn.WriteToUDP(buffer.Bytes(), clientAddr)
|
||||
log.Info("VMessIn sending %d bytes to %s", len(buffer.Bytes()), clientAddr.String())
|
||||
log.Info("VMessIn sending %d bytes to %s", len(buffer.Bytes()), clientAddr.String())
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<-
|
||||
log.Warning("VMessOut: unexepcted response header. The connection is probably hijacked.")
|
||||
return
|
||||
}
|
||||
log.Info("VMessOut received %d bytes from %s", len(buffer) - 4, conn.RemoteAddr().String())
|
||||
log.Info("VMessOut received %d bytes from %s", len(buffer)-4, conn.RemoteAddr().String())
|
||||
|
||||
output <- buffer[4:]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user