Source File
alts.go
Belonging Package
google.golang.org/grpc/credentials/alts
protocolVersionMaxMajor = 2
protocolVersionMaxMinor = 1
protocolVersionMinMajor = 2
protocolVersionMinMinor = 1
)
var (
once sync.Once
maxRPCVersion = &altspb.RpcProtocolVersions_Version{
Major: protocolVersionMaxMajor,
Minor: protocolVersionMaxMinor,
}
minRPCVersion = &altspb.RpcProtocolVersions_Version{
Major: protocolVersionMinMajor,
Minor: protocolVersionMinMinor,
PeerRPCVersions() *altspb.RpcProtocolVersions
}
func () *ClientOptions {
return &ClientOptions{
HandshakerServiceAddress: hypervisorHandshakerServiceAddress,
}
}
func () *ServerOptions {
return &ServerOptions{
HandshakerServiceAddress: hypervisorHandshakerServiceAddress,
}
}
func ( *ClientOptions) credentials.TransportCredentials {
return newALTS(core.ClientSide, .TargetServiceAccounts, .HandshakerServiceAddress)
}
func ( *ServerOptions) credentials.TransportCredentials {
return newALTS(core.ServerSide, nil, .HandshakerServiceAddress)
}
func ( core.Side, []string, string) credentials.TransportCredentials {
once.Do(func() {
vmOnGCP = isRunningOnGCP()
})
if == "" {
= hypervisorHandshakerServiceAddress
}
return &altsTC{
info: &credentials.ProtocolInfo{
SecurityProtocol: "alts",
SecurityVersion: "1.0",
},
side: ,
accounts: ,
hsAddress: ,
}
}
var context.CancelFunc
, = context.WithCancel()
defer func() {
if != nil {
()
}
}()
:= handshaker.DefaultClientHandshakerOptions()
.TargetName =
.TargetServiceAccounts = .accounts
.RPCVersions = &altspb.RpcProtocolVersions{
MaxRpcVersion: maxRPCVersion,
MinRpcVersion: minRPCVersion,
}
, := handshaker.NewClientHandshaker(, , , )
if != nil {
return nil, nil,
}
defer func() {
if != nil {
.Close()
}
}()
, , := .ClientHandshake()
if != nil {
return nil, nil,
}
, := .(AuthInfo)
if ! {
return nil, nil, errors.New("client-side auth info is not of type alts.AuthInfo")
}
, := checkRPCVersions(.RPCVersions, .PeerRPCVersions())
if ! {
return nil, nil, fmt.Errorf("server-side RPC versions are not compatible with this client, local versions: %v, peer versions: %v", .RPCVersions, .PeerRPCVersions())
}
return , , nil
}
, := context.WithTimeout(context.Background(), defaultTimeout)
defer ()
:= handshaker.DefaultServerHandshakerOptions()
.RPCVersions = &altspb.RpcProtocolVersions{
MaxRpcVersion: maxRPCVersion,
MinRpcVersion: minRPCVersion,
}
, := handshaker.NewServerHandshaker(, , , )
if != nil {
return nil, nil,
}
defer func() {
if != nil {
.Close()
}
}()
, , := .ServerHandshake()
if != nil {
return nil, nil,
}
, := .(AuthInfo)
if ! {
return nil, nil, errors.New("server-side auth info is not of type alts.AuthInfo")
}
, := checkRPCVersions(.RPCVersions, .PeerRPCVersions())
if ! {
return nil, nil, fmt.Errorf("client-side RPC versions is not compatible with this server, local versions: %v, peer versions: %v", .RPCVersions, .PeerRPCVersions())
}
return , , nil
}
func ( *altsTC) () credentials.ProtocolInfo {
return *.info
}
func ( *altsTC) () credentials.TransportCredentials {
:= *.info
var []string
if .accounts != nil {
= make([]string, len(.accounts))
copy(, .accounts)
}
return &altsTC{
info: &,
side: .side,
hsAddress: .hsAddress,
accounts: ,
}
}
func ( *altsTC) ( string) error {
.info.ServerName =
return nil
}
:= .GetMaxRpcVersion()
if compareRPCVersions(.GetMaxRpcVersion(), .GetMaxRpcVersion()) > 0 {
= .GetMaxRpcVersion()
}
:= .GetMinRpcVersion()
if compareRPCVersions(.GetMinRpcVersion(), .GetMinRpcVersion()) > 0 {
= .GetMinRpcVersion()
}
if compareRPCVersions(, ) < 0 {
return false, nil
}
return true,
![]() |
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. |