common.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // Package internal contains common core functionality for ALTS.
  19. package internal
  20. import (
  21. "context"
  22. "net"
  23. "google.golang.org/grpc/credentials"
  24. )
  25. const (
  26. // ClientSide identifies the client in this communication.
  27. ClientSide Side = iota
  28. // ServerSide identifies the server in this communication.
  29. ServerSide
  30. )
  31. // PeerNotRespondingError is returned when a peer server is not responding
  32. // after a channel has been established. It is treated as a temporary connection
  33. // error and re-connection to the server should be attempted.
  34. var PeerNotRespondingError = &peerNotRespondingError{}
  35. // Side identifies the party's role: client or server.
  36. type Side int
  37. type peerNotRespondingError struct{}
  38. // Return an error message for the purpose of logging.
  39. func (e *peerNotRespondingError) Error() string {
  40. return "peer server is not responding and re-connection should be attempted."
  41. }
  42. // Temporary indicates if this connection error is temporary or fatal.
  43. func (e *peerNotRespondingError) Temporary() bool {
  44. return true
  45. }
  46. // Handshaker defines a ALTS handshaker interface.
  47. type Handshaker interface {
  48. // ClientHandshake starts and completes a client-side handshaking and
  49. // returns a secure connection and corresponding auth information.
  50. ClientHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error)
  51. // ServerHandshake starts and completes a server-side handshaking and
  52. // returns a secure connection and corresponding auth information.
  53. ServerHandshake(ctx context.Context) (net.Conn, credentials.AuthInfo, error)
  54. // Close terminates the Handshaker. It should be called when the caller
  55. // obtains the secure connection.
  56. Close()
  57. }