registration_server.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package tunnelrpc
  2. import (
  3. "context"
  4. "io"
  5. "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
  6. )
  7. // RegistrationServer provides a handler interface for a client to provide methods to handle the different types of
  8. // requests that can be communicated by the stream.
  9. type RegistrationServer struct {
  10. registrationServer pogs.RegistrationServer
  11. }
  12. func NewRegistrationServer(registrationServer pogs.RegistrationServer) *RegistrationServer {
  13. return &RegistrationServer{
  14. registrationServer: registrationServer,
  15. }
  16. }
  17. // Serve listens for all RegistrationServer RPCs, including UnregisterConnection until the underlying connection
  18. // is terminated.
  19. func (s *RegistrationServer) Serve(ctx context.Context, stream io.ReadWriteCloser) error {
  20. transport := SafeTransport(stream)
  21. defer transport.Close()
  22. main := pogs.RegistrationServer_ServerToClient(s.registrationServer)
  23. rpcConn := NewServerConn(transport, main.Client)
  24. select {
  25. case <-rpcConn.Done():
  26. return rpcConn.Wait()
  27. case <-ctx.Done():
  28. return ctx.Err()
  29. }
  30. }