2024-05-24 18:40:10 +00:00
|
|
|
package tunnelrpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/tunnelrpc/pogs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RegistrationServer provides a handler interface for a client to provide methods to handle the different types of
|
|
|
|
// requests that can be communicated by the stream.
|
|
|
|
type RegistrationServer struct {
|
|
|
|
registrationServer pogs.RegistrationServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRegistrationServer(registrationServer pogs.RegistrationServer) *RegistrationServer {
|
|
|
|
return &RegistrationServer{
|
|
|
|
registrationServer: registrationServer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serve listens for all RegistrationServer RPCs, including UnregisterConnection until the underlying connection
|
|
|
|
// is terminated.
|
|
|
|
func (s *RegistrationServer) Serve(ctx context.Context, stream io.ReadWriteCloser) error {
|
|
|
|
transport := SafeTransport(stream)
|
|
|
|
defer transport.Close()
|
|
|
|
|
|
|
|
main := pogs.RegistrationServer_ServerToClient(s.registrationServer)
|
2024-06-26 20:34:49 +00:00
|
|
|
rpcConn := NewServerConn(transport, main.Client)
|
2024-05-24 18:40:10 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-rpcConn.Done():
|
|
|
|
return rpcConn.Wait()
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
}
|