cloudflared-mirror/connection/rpc.go

42 lines
1.3 KiB
Go
Raw Normal View History

2019-11-21 17:03:13 +00:00
package connection
import (
"context"
"io"
2019-11-21 17:03:13 +00:00
rpc "zombiezen.com/go/capnproto2/rpc"
"github.com/cloudflare/cloudflared/logger"
2019-11-21 17:03:13 +00:00
"github.com/cloudflare/cloudflared/tunnelrpc"
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
)
// NewTunnelRPCClient creates and returns a new RPC client, which will communicate
2019-11-21 17:03:13 +00:00
// using a stream on the given muxer
func NewTunnelRPCClient(
2019-11-21 17:03:13 +00:00
ctx context.Context,
stream io.ReadWriteCloser,
logger logger.Service,
2019-11-21 17:03:13 +00:00
) (client tunnelpogs.TunnelServer_PogsClient, err error) {
conn := rpc.NewConn(
tunnelrpc.NewTransportLogger(logger, rpc.StreamTransport(stream)),
tunnelrpc.ConnLog(logger),
)
registrationClient := tunnelpogs.RegistrationServer_PogsClient{Client: conn.Bootstrap(ctx), Conn: conn}
client = tunnelpogs.TunnelServer_PogsClient{RegistrationServer_PogsClient: registrationClient, Client: conn.Bootstrap(ctx), Conn: conn}
2019-11-21 17:03:13 +00:00
return client, nil
}
func NewRegistrationRPCClient(
ctx context.Context,
stream io.ReadWriteCloser,
logger logger.Service,
) (client tunnelpogs.RegistrationServer_PogsClient, err error) {
conn := rpc.NewConn(
tunnelrpc.NewTransportLogger(logger, rpc.StreamTransport(stream)),
tunnelrpc.ConnLog(logger),
)
client = tunnelpogs.RegistrationServer_PogsClient{Client: conn.Bootstrap(ctx), Conn: conn}
return client, nil
2019-11-21 17:03:13 +00:00
}