本文整理匯總了Golang中github.com/v2ray/v2ray-core/io/vmess.VMessRequest.ToBytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang VMessRequest.ToBytes方法的具體用法?Golang VMessRequest.ToBytes怎麽用?Golang VMessRequest.ToBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/v2ray/v2ray-core/io/vmess.VMessRequest
的用法示例。
在下文中一共展示了VMessRequest.ToBytes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleRequest
func handleRequest(conn *net.TCPConn, request *vmessio.VMessRequest, input <-chan []byte, finish chan<- bool) {
defer close(finish)
encryptRequestWriter, err := v2io.NewAesEncryptWriter(request.RequestKey[:], request.RequestIV[:], conn)
if err != nil {
log.Error("VMessOut: Failed to create encrypt writer: %v", err)
return
}
buffer, err := request.ToBytes(v2hash.NewTimeHash(v2hash.HMACHash{}), v2math.GenerateRandomInt64InRange)
if err != nil {
log.Error("VMessOut: Failed to serialize VMess request: %v", err)
return
}
// Send first packet of payload together with request, in favor of small requests.
payload, open := <-input
if open {
encryptRequestWriter.Crypt(payload)
buffer = append(buffer, payload...)
_, err = conn.Write(buffer)
if err != nil {
log.Error("VMessOut: Failed to write VMess request: %v", err)
return
}
v2net.ChanToWriter(encryptRequestWriter, input)
}
return
}
示例2: handleRequest
func handleRequest(conn *net.TCPConn, request *vmessio.VMessRequest, input <-chan []byte, finish chan<- bool) error {
defer close(finish)
encryptRequestWriter, err := v2io.NewAesEncryptWriter(request.RequestKey[:], request.RequestIV[:], conn)
if err != nil {
log.Error("Failed to create encrypt writer: %v", err)
return err
}
buffer, err := request.ToBytes(v2hash.NewTimeHash(v2hash.HMACHash{}), v2math.GenerateRandomInt64InRange)
if err != nil {
log.Error("VMessOut: Failed to serialize VMess request: %v", err)
}
//conn.Write(buffer)
data, open := <-input
if open {
encryptRequestWriter.Crypt(data)
buffer = append(buffer, data...)
}
_, err = conn.Write(buffer)
if err != nil {
log.Error("VMessOut: Failed to write VMess request: %v", err)
}
if !open {
return nil
}
v2net.ChanToWriter(encryptRequestWriter, input)
return nil
}