• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log.Debug函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/v2ray/v2ray-core/log.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Debug函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:nikedog,项目名称:v2ray-core,代码行数:60,代码来源:vmessout.go


示例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
}
开发者ID:Jamalmo,项目名称:v2ray-core,代码行数:27,代码来源:vmessout.go


示例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
}
开发者ID:Jamalmo,项目名称:v2ray-core,代码行数:55,代码来源:vmessin.go


示例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)
	}
}
开发者ID:zelotoj,项目名称:v2ray-core,代码行数:12,代码来源:freedom.go


示例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)
	}
}
开发者ID:noah70,项目名称:v2ray-core,代码行数:12,代码来源:socks.go


示例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)
	}
}
开发者ID:zelotoj,项目名称:v2ray-core,代码行数:12,代码来源:vmessout.go


示例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
}
开发者ID:neverisland,项目名称:v2ray-core,代码行数:52,代码来源:vmessin.go


示例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]
	}
}
开发者ID:zelotoj,项目名称:v2ray-core,代码行数:14,代码来源:freedom.go


示例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]
	}
}
开发者ID:zelotoj,项目名称:v2ray-core,代码行数:14,代码来源:vmessout.go


示例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]
	}
}
开发者ID:noah70,项目名称:v2ray-core,代码行数:14,代码来源:socks.go


示例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()
}
开发者ID:Jamalmo,项目名称:v2ray-core,代码行数:9,代码来源:freedom.go


示例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
}
开发者ID:h82258652,项目名称:v2ray-core,代码行数:43,代码来源:vmessin.go


示例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
}
开发者ID:noah70,项目名称:v2ray-core,代码行数:13,代码来源:encryption.go


示例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)
	}
}
开发者ID:nicedayzhu,项目名称:v2ray-core,代码行数:11,代码来源:socks.go


示例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
}
开发者ID:yatwql,项目名称:v2ray-core,代码行数:11,代码来源:socks.go


示例16: Start

func (vconn *FreedomConnection) Start(ray core.OutboundRay) error {
	input := ray.OutboundInput()
	output := ray.OutboundOutput()
	conn, err := net.Dial("tcp", vconn.dest.String())
	if err != nil {
		return log.Error("Failed to open tcp: %s", vconn.dest.String())
	}
	log.Debug("Sending outbound tcp: %s", vconn.dest.String())

	finish := make(chan bool, 2)
	go vconn.DumpInput(conn, input, finish)
	go vconn.DumpOutput(conn, output, finish)
	go vconn.CloseConn(conn, finish)
	return nil
}
开发者ID:zelotoj,项目名称:v2ray-core,代码行数:15,代码来源:freedom.go


示例17: handleResponse

func handleResponse(conn *net.TCPConn, request *vmessio.VMessRequest, output chan<- []byte, finish chan<- bool) error {
	defer close(finish)
	responseKey := md5.Sum(request.RequestKey[:])
	responseIV := md5.Sum(request.RequestIV[:])

	response := vmessio.VMessResponse{}
	nBytes, err := conn.Read(response[:])
	if err != nil {
		log.Error("Failed to read VMess response (%d bytes): %v", nBytes, err)
		return err
	}
	log.Debug("Got response %v", response)
	// TODO: check response

	decryptResponseReader, err := v2io.NewAesDecryptReader(responseKey[:], responseIV[:], conn)
	if err != nil {
		log.Error("Failed to create decrypt reader: %v", err)
		return err
	}

	v2net.ReaderToChan(output, decryptResponseReader)
	return nil
}
开发者ID:neverisland,项目名称:v2ray-core,代码行数:23,代码来源:vmessout.go


示例18: Read

func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
	buffer := make([]byte, 256)

	nBytes, err := reader.Read(buffer[:core.IDBytesLen])
	if err != nil {
		return nil, err
	}

	log.Debug("Read user hash: %v", buffer[:nBytes])

	userId, timeSec, valid := r.vUserSet.GetUser(buffer[:nBytes])
	if !valid {
		return nil, ErrorInvalidUser
	}

	aesCipher, err := aes.NewCipher(userId.CmdKey())
	if err != nil {
		return nil, err
	}
	aesStream := cipher.NewCFBDecrypter(aesCipher, v2hash.Int64Hash(timeSec))
	decryptor := v2io.NewCryptionReader(aesStream, reader)

	if err != nil {
		return nil, err
	}

	nBytes, err = decryptor.Read(buffer[0:1])
	if err != nil {
		return nil, err
	}

	randomLength := buffer[0]
	if randomLength <= 0 || randomLength > 32 {
		return nil, fmt.Errorf("Unexpected random length %d", randomLength)
	}
	_, err = decryptor.Read(buffer[:randomLength])
	if err != nil {
		return nil, err
	}

	nBytes, err = decryptor.Read(buffer[0:1])
	if err != nil {
		return nil, err
	}

	request := &VMessRequest{
		UserId:  *userId,
		Version: buffer[0],
	}

	if request.Version != Version {
		log.Error("Unknown VMess version %d", request.Version)
		return nil, ErrorInvalidVerion
	}

	// TODO: check number of bytes returned
	_, err = decryptor.Read(request.RequestIV[:])
	if err != nil {
		return nil, err
	}
	_, err = decryptor.Read(request.RequestKey[:])
	if err != nil {
		return nil, err
	}
	_, err = decryptor.Read(request.ResponseHeader[:])
	if err != nil {
		return nil, err
	}
	_, err = decryptor.Read(buffer[0:1])
	if err != nil {
		return nil, err
	}
	request.Command = buffer[0]

	_, err = decryptor.Read(buffer[0:2])
	if err != nil {
		return nil, err
	}
	port := binary.BigEndian.Uint16(buffer[0:2])

	_, err = decryptor.Read(buffer[0:1])
	if err != nil {
		return nil, err
	}
	switch buffer[0] {
	case addrTypeIPv4:
		_, err = decryptor.Read(buffer[1:5])
		if err != nil {
			return nil, err
		}
		request.Address = v2net.IPAddress(buffer[1:5], port)
	case addrTypeIPv6:
		_, err = decryptor.Read(buffer[1:17])
		if err != nil {
			return nil, err
		}
		request.Address = v2net.IPAddress(buffer[1:17], port)
	case addrTypeDomain:
		_, err = decryptor.Read(buffer[1:2])
		if err != nil {
//.........这里部分代码省略.........
开发者ID:neverisland,项目名称:v2ray-core,代码行数:101,代码来源:vmess.go


示例19: Write

func (w *VMessRequestWriter) Write(writer io.Writer, request *VMessRequest) error {
	buffer := make([]byte, 0, 300)

	counter := w.randomRangeInt64(time.Now().UTC().Unix(), 30)
	idHash := w.idHash.Hash(request.UserId.Bytes, counter)

	log.Debug("Writing userhash: %v", idHash)
	buffer = append(buffer, idHash...)

	encryptionBegin := len(buffer)

	randomLength := mrand.Intn(32) + 1
	randomContent := make([]byte, randomLength)
	_, err := rand.Read(randomContent)
	if err != nil {
		return err
	}
	buffer = append(buffer, byte(randomLength))
	buffer = append(buffer, randomContent...)

	buffer = append(buffer, request.Version)
	buffer = append(buffer, request.RequestIV[:]...)
	buffer = append(buffer, request.RequestKey[:]...)
	buffer = append(buffer, request.ResponseHeader[:]...)
	buffer = append(buffer, request.Command)

	portBytes := make([]byte, 2)
	binary.BigEndian.PutUint16(portBytes, request.Address.Port)
	buffer = append(buffer, portBytes...)

	switch {
	case request.Address.IsIPv4():
		buffer = append(buffer, addrTypeIPv4)
		buffer = append(buffer, request.Address.IP...)
	case request.Address.IsIPv6():
		buffer = append(buffer, addrTypeIPv6)
		buffer = append(buffer, request.Address.IP...)
	case request.Address.IsDomain():
		buffer = append(buffer, addrTypeDomain)
		buffer = append(buffer, byte(len(request.Address.Domain)))
		buffer = append(buffer, []byte(request.Address.Domain)...)
	}

	paddingLength := mrand.Intn(32) + 1
	paddingBuffer := make([]byte, paddingLength)
	_, err = rand.Read(paddingBuffer)
	if err != nil {
		return err
	}
	buffer = append(buffer, byte(paddingLength))
	buffer = append(buffer, paddingBuffer...)
	encryptionEnd := len(buffer)

	aesCipher, err := aes.NewCipher(request.UserId.CmdKey())
	if err != nil {
		return err
	}
	aesStream := cipher.NewCFBEncrypter(aesCipher, v2hash.Int64Hash(counter))
	cWriter := v2io.NewCryptionWriter(aesStream, writer)

	_, err = writer.Write(buffer[0:encryptionBegin])
	if err != nil {
		return err
	}
	_, err = cWriter.Write(buffer[encryptionBegin:encryptionEnd])
	if err != nil {
		return err
	}

	return nil
}
开发者ID:neverisland,项目名称:v2ray-core,代码行数:71,代码来源:vmess.go


示例20: DumpOutput

func (vconn *FreedomConnection) DumpOutput(conn net.Conn, output chan<- []byte, finish chan<- bool) {
	v2net.ReaderToChan(output, conn)
	close(output)
	log.Debug("Freedom closing output")
	finish <- true
}
开发者ID:Jamalmo,项目名称:v2ray-core,代码行数:6,代码来源:freedom.go



注:本文中的github.com/v2ray/v2ray-core/log.Debug函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log.Error函数代码示例发布时间:2022-05-28
下一篇:
Golang vmess.VMessRequest类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap