本文整理汇总了Golang中github.com/v2ray/v2ray-core/log.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startCommunicate
func (handler *VMessOutboundHandler) startCommunicate(request *vmessio.VMessRequest, dest v2net.Address, ray core.OutboundRay) error {
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{dest.IP, int(dest.Port), ""})
log.Debug("VMessOutbound dialing tcp: %s", dest.String())
if err != nil {
log.Error("Failed to open tcp (%s): %v", dest.String(), err)
return err
}
defer conn.Close()
input := ray.OutboundInput()
output := ray.OutboundOutput()
requestWriter := vmessio.NewVMessRequestWriter()
err = requestWriter.Write(conn, request)
if err != nil {
log.Error("Failed to write VMess request: %v", err)
close(output)
return err
}
requestKey := request.RequestKey[:]
requestIV := request.RequestIV[:]
responseKey := md5.Sum(requestKey)
responseIV := md5.Sum(requestIV)
response := vmessio.VMessResponse{}
nBytes, err := conn.Read(response[:])
if err != nil {
close(output)
log.Error("Failed to read VMess response (%d bytes): %v", nBytes, err)
return err
}
log.Debug("Got response %v", response)
// TODO: check response
encryptRequestWriter, err := v2io.NewAesEncryptWriter(requestKey, requestIV, conn)
if err != nil {
close(output)
log.Error("Failed to create encrypt writer: %v", err)
return err
}
decryptResponseReader, err := v2io.NewAesDecryptReader(responseKey[:], responseIV[:], conn)
if err != nil {
close(output)
log.Error("Failed to create decrypt reader: %v", err)
return err
}
readFinish := make(chan bool)
writeFinish := make(chan bool)
go handler.dumpInput(encryptRequestWriter, input, readFinish)
go handler.dumpOutput(decryptResponseReader, output, writeFinish)
<-readFinish
conn.CloseWrite()
log.Debug("VMessOut closing write")
<-writeFinish
return nil
}
示例2: startCommunicate
func startCommunicate(request *vmessio.VMessRequest, dest v2net.Address, ray core.OutboundRay) error {
input := ray.OutboundInput()
output := ray.OutboundOutput()
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{dest.IP, int(dest.Port), ""})
log.Debug("VMessOutbound dialing tcp: %s", dest.String())
if err != nil {
log.Error("Failed to open tcp (%s): %v", dest.String(), err)
close(output)
return err
}
log.Debug("VMessOut: Tunneling request for %s", request.Address.String())
defer conn.Close()
requestFinish := make(chan bool)
responseFinish := make(chan bool)
go handleRequest(conn, request, input, requestFinish)
go handleResponse(conn, request, output, responseFinish)
<-requestFinish
conn.CloseWrite()
<-responseFinish
return nil
}
示例3: HandleConnection
func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error {
defer connection.Close()
reader := vmessio.NewVMessRequestReader(handler.clients)
request, err := reader.Read(connection)
if err != nil {
log.Debug("Failed to parse VMess request: %v", err)
return err
}
log.Debug("Received request for %s", request.Address.String())
ray := handler.vPoint.NewInboundConnectionAccepted(request.Address)
input := ray.InboundInput()
output := ray.InboundOutput()
readFinish := make(chan bool)
writeFinish := make(chan bool)
go handleInput(request, connection, input, readFinish)
responseKey := md5.Sum(request.RequestKey[:])
responseIV := md5.Sum(request.RequestIV[:])
response := vmessio.NewVMessResponse(request)
responseWriter, err := v2io.NewAesEncryptWriter(responseKey[:], responseIV[:], connection)
if err != nil {
return log.Error("Failed to create encrypt writer: %v", err)
}
//responseWriter.Write(response[:])
// Optimize for small response packet
buffer := make([]byte, 0, 1024)
buffer = append(buffer, response[:]...)
data, open := <-output
if open {
buffer = append(buffer, data...)
}
responseWriter.Write(buffer)
if open {
go handleOutput(request, responseWriter, output, writeFinish)
} else {
close(writeFinish)
}
<-writeFinish
if tcpConn, ok := connection.(*net.TCPConn); ok {
log.Debug("VMessIn closing write")
tcpConn.CloseWrite()
}
<-readFinish
return nil
}
示例4: DumpInput
func (vconn *FreedomConnection) DumpInput(conn net.Conn, input <-chan []byte, finish chan<- bool) {
for {
data, open := <-input
if !open {
finish <- true
log.Debug("Freedom finishing input.")
break
}
nBytes, err := conn.Write(data)
log.Debug("Freedom wrote %d bytes with error %v", nBytes, err)
}
}
示例5: dumpOutput
func (server *SocksServer) dumpOutput(conn net.Conn, output <-chan []byte, finish chan<- bool) {
for {
buffer, open := <-output
if !open {
finish <- true
log.Debug("Socks finishing output")
break
}
nBytes, err := conn.Write(buffer)
log.Debug("Writing %d bytes with error %v", nBytes, err)
}
}
示例6: dumpInput
func (handler *VMessOutboundHandler) dumpInput(writer io.Writer, input <-chan []byte, finish chan<- bool) {
for {
buffer, open := <-input
if !open {
finish <- true
log.Debug("VMessOutbound finishing input.")
break
}
nBytes, err := writer.Write(buffer)
log.Debug("VMessOutbound: Wrote %d bytes with error %v", nBytes, err)
}
}
示例7: HandleConnection
func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error {
defer connection.Close()
reader := vmessio.NewVMessRequestReader(handler.clients)
request, err := reader.Read(connection)
if err != nil {
log.Debug("Failed to parse VMess request: %v", err)
return err
}
log.Debug("Received request for %s", request.Address.String())
response := vmessio.NewVMessResponse(request)
nBytes, err := connection.Write(response[:])
if err != nil {
return log.Error("Failed to write VMess response (%d bytes): %v", nBytes, err)
}
requestKey := request.RequestKey[:]
requestIV := request.RequestIV[:]
responseKey := md5.Sum(requestKey)
responseIV := md5.Sum(requestIV)
requestReader, err := v2io.NewAesDecryptReader(requestKey, requestIV, connection)
if err != nil {
return log.Error("Failed to create decrypt reader: %v", err)
}
responseWriter, err := v2io.NewAesEncryptWriter(responseKey[:], responseIV[:], connection)
if err != nil {
return log.Error("Failed to create encrypt writer: %v", err)
}
ray := handler.vPoint.NewInboundConnectionAccepted(request.Address)
input := ray.InboundInput()
output := ray.InboundOutput()
readFinish := make(chan bool)
writeFinish := make(chan bool)
go handler.dumpInput(requestReader, input, readFinish)
go handler.dumpOutput(responseWriter, output, writeFinish)
<-writeFinish
if tcpConn, ok := connection.(*net.TCPConn); ok {
log.Debug("VMessIn closing write")
tcpConn.CloseWrite()
}
<-readFinish
return nil
}
示例8: DumpOutput
func (vconn *FreedomConnection) DumpOutput(conn net.Conn, output chan<- []byte, finish chan<- bool) {
for {
buffer := make([]byte, 512)
nBytes, err := conn.Read(buffer)
log.Debug("Freedom reading %d bytes with error %v", nBytes, err)
if err == io.EOF {
close(output)
finish <- true
log.Debug("Freedom finishing output.")
break
}
output <- buffer[:nBytes]
}
}
示例9: dumpOutput
func (handler *VMessOutboundHandler) dumpOutput(reader io.Reader, output chan<- []byte, finish chan<- bool) {
for {
buffer := make([]byte, BufferSize)
nBytes, err := reader.Read(buffer)
log.Debug("VMessOutbound: Reading %d bytes, with error %v", nBytes, err)
if err == io.EOF {
close(output)
finish <- true
log.Debug("VMessOutbound finishing output.")
break
}
output <- buffer[:nBytes]
}
}
示例10: dumpInput
func (server *SocksServer) dumpInput(conn net.Conn, input chan<- []byte, finish chan<- bool) {
for {
buffer := make([]byte, 512)
nBytes, err := conn.Read(buffer)
log.Debug("Reading %d bytes, with error %v", nBytes, err)
if err == io.EOF {
close(input)
finish <- true
log.Debug("Socks finishing input.")
break
}
input <- buffer[:nBytes]
}
}
示例11: CloseConn
func (vconn *FreedomConnection) CloseConn(conn net.Conn, readFinish <-chan bool, writeFinish <-chan bool) {
<-writeFinish
if tcpConn, ok := conn.(*net.TCPConn); ok {
log.Debug("Closing freedom write.")
tcpConn.CloseWrite()
}
<-readFinish
conn.Close()
}
示例12: HandleConnection
func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error {
defer connection.Close()
reader := vmessio.NewVMessRequestReader(handler.clients)
request, err := reader.Read(connection)
if err != nil {
return err
}
log.Debug("Received request for %s", request.Address.String())
response := vmessio.NewVMessResponse(request)
nBytes, err := connection.Write(response[:])
log.Debug("Writing VMess response %v", response)
if err != nil {
return log.Error("Failed to write VMess response (%d bytes): %v", nBytes, err)
}
requestKey := request.RequestKey[:]
requestIV := request.RequestIV[:]
responseKey := md5.Sum(requestKey)
responseIV := md5.Sum(requestIV)
requestReader, err := v2io.NewAesDecryptReader(requestKey, requestIV, connection)
if err != nil {
return log.Error("Failed to create decrypt reader: %v", err)
}
responseWriter, err := v2io.NewAesEncryptWriter(responseKey[:], responseIV[:], connection)
if err != nil {
return log.Error("Failed to create encrypt writer: %v", err)
}
ray := handler.vPoint.NewInboundConnectionAccepted(request.Address)
input := ray.InboundInput()
output := ray.InboundOutput()
finish := make(chan bool, 2)
go handler.dumpInput(requestReader, input, finish)
go handler.dumpOutput(responseWriter, output, finish)
handler.waitForFinish(finish)
return nil
}
示例13: Read
// Read reads blocks from underlying reader, the length of blocks must be
// a multiply of BlockSize()
func (reader CryptionReader) Read(blocks []byte) (int, error) {
nBytes, err := reader.reader.Read(blocks)
log.Debug("CryptionReader: Read %d bytes", nBytes)
if nBytes > 0 {
reader.stream.XORKeyStream(blocks[:nBytes], blocks[:nBytes])
}
if err != nil {
log.Error("Error reading blocks: %v", err)
}
return nBytes, err
}
示例14: dumpOutput
func (server *SocksServer) dumpOutput(conn net.Conn, output <-chan []byte, finish chan<- bool) {
for {
buffer, open := <-output
if !open {
finish <- true
break
}
nBytes, _ := conn.Write(buffer)
log.Debug("Writing %d bytes", nBytes)
}
}
示例15: Listen
func (server *SocksServer) Listen(port uint16) error {
listener, err := net.Listen("tcp", ":"+strconv.Itoa(int(port)))
if err != nil {
log.Error("Error on listening port %d: %v", port, err)
return err
}
log.Debug("Working on tcp:%d", port)
server.accepting = true
go server.AcceptConnections(listener)
return nil
}