Source File
record.go
Belonging Package
google.golang.org/grpc/credentials/alts/internal/conn
package conn
import (
core
)
type ALTSRecordFunc func(s core.Side, keyData []byte) (ALTSRecordCrypto, error)
altsWriteBufferMaxSize = 512 * 1024 // 512KiB
)
var (
protocols = make(map[string]ALTSRecordFunc)
)
func ( net.Conn, core.Side, string, []byte, []byte) (net.Conn, error) {
:= protocols[]
if == nil {
return nil, fmt.Errorf("negotiated unknown next_protocol %q", )
}
, := (, )
if != nil {
return nil, fmt.Errorf("protocol %q: %v", , )
}
:= MsgLenFieldSize + msgTypeFieldSize + .EncryptionOverhead()
:= altsRecordDefaultLength -
var []byte
for len() == 0 {
if len(.protected) == cap(.protected) {
:= make([]byte, len(.protected), cap(.protected)+altsRecordDefaultLength)
copy(, .protected)
.protected =
}
, = .Conn.Read(.protected[len(.protected):min(cap(.protected), len(.protected)+altsRecordDefaultLength)])
if != nil {
return 0,
}
.protected = .protected[:len(.protected)+]
, .nextFrame, = ParseFramedMsg(.protected, altsRecordLengthLimit)
if != nil {
return 0,
}
:= [MsgLenFieldSize:]
:= binary.LittleEndian.Uint32([:msgTypeFieldSize])
if &0xff != altsRecordMsgType {
return 0, fmt.Errorf("received frame with incorrect message type %v, expected lower byte %v",
, altsRecordMsgType)
}
:= [msgTypeFieldSize:]
:= len()
if > altsWriteBufferMaxSize {
= altsWriteBufferMaxSize
const = altsWriteBufferMaxSize / altsRecordDefaultLength
= * .payloadLengthLimit
}
if len(.writeBuf) < {
.writeBuf = make([]byte, )
}
for := 0; < len(); += {
:= +
if > len() {
= len()
}
:= [:]
:= 0
for len() > 0 {
:= len()
if > .payloadLengthLimit {
= .payloadLengthLimit
}
:= [:]
= [:]
, = .crypto.Encrypt([:msgTypeFieldSize], )
if != nil {
return ,
}
:= int(math.Floor(float64() / float64(altsRecordDefaultLength)))
return + *.payloadLengthLimit,
}
}
return , nil
}
func (, int) int {
if < {
return
}
return
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |