rpc.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package connection
  2. import (
  3. "context"
  4. "io"
  5. rpc "zombiezen.com/go/capnproto2/rpc"
  6. "github.com/cloudflare/cloudflared/logger"
  7. "github.com/cloudflare/cloudflared/tunnelrpc"
  8. tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
  9. )
  10. // NewTunnelRPCClient creates and returns a new RPC client, which will communicate
  11. // using a stream on the given muxer
  12. func NewTunnelRPCClient(
  13. ctx context.Context,
  14. stream io.ReadWriteCloser,
  15. logger logger.Service,
  16. ) (client tunnelpogs.TunnelServer_PogsClient, err error) {
  17. conn := rpc.NewConn(
  18. tunnelrpc.NewTransportLogger(logger, rpc.StreamTransport(stream)),
  19. tunnelrpc.ConnLog(logger),
  20. )
  21. registrationClient := tunnelpogs.RegistrationServer_PogsClient{Client: conn.Bootstrap(ctx), Conn: conn}
  22. client = tunnelpogs.TunnelServer_PogsClient{RegistrationServer_PogsClient: registrationClient, Client: conn.Bootstrap(ctx), Conn: conn}
  23. return client, nil
  24. }
  25. func NewRegistrationRPCClient(
  26. ctx context.Context,
  27. stream io.ReadWriteCloser,
  28. logger logger.Service,
  29. ) (client tunnelpogs.RegistrationServer_PogsClient, err error) {
  30. conn := rpc.NewConn(
  31. tunnelrpc.NewTransportLogger(logger, rpc.StreamTransport(stream)),
  32. tunnelrpc.ConnLog(logger),
  33. )
  34. client = tunnelpogs.RegistrationServer_PogsClient{Client: conn.Bootstrap(ctx), Conn: conn}
  35. return client, nil
  36. }