gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/grpc/credentials/alts/internal/common.go (about) 1 /* 2 * 3 * Copyright 2018 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 // Package internal contains common core functionality for ALTS. 20 package internal 21 22 import ( 23 "context" 24 "net" 25 26 "gitee.com/ks-custle/core-gm/grpc/credentials" 27 ) 28 29 const ( 30 // ClientSide identifies the client in this communication. 31 ClientSide Side = iota 32 // ServerSide identifies the server in this communication. 33 ServerSide 34 ) 35 36 // PeerNotRespondingError is returned when a peer server is not responding 37 // after a channel has been established. It is treated as a temporary connection 38 // error and re-connection to the server should be attempted. 39 var PeerNotRespondingError = &peerNotRespondingError{} 40 41 // Side identifies the party's role: client or server. 42 type Side int 43 44 type peerNotRespondingError struct{} 45 46 // Return an error message for the purpose of logging. 47 func (e *peerNotRespondingError) Error() string { 48 return "peer server is not responding and re-connection should be attempted." 49 } 50 51 // Temporary indicates if this connection error is temporary or fatal. 52 func (e *peerNotRespondingError) Temporary() bool { 53 return true 54 } 55 56 // Handshaker defines a ALTS handshaker interface. 57 type Handshaker interface { 58 // ClientHandshake starts and completes a client-side handshaking and 59 // returns a secure connection and corresponding auth information. 60 ClientHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) 61 // ServerHandshake starts and completes a server-side handshaking and 62 // returns a secure connection and corresponding auth information. 63 ServerHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error) 64 // Close terminates the Handshaker. It should be called when the caller 65 // obtains the secure connection. 66 Close() 67 }