1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

format code

This commit is contained in:
V2Ray 2015-10-06 17:24:57 +02:00
parent 7a24dc3e09
commit 78daf8a879
7 changed files with 26 additions and 26 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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 {

View File

@ -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,

View File

@ -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())
}
}

View File

@ -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:]