common.go 2.2 KB

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