2019-11-21 17:03:13 +00:00
|
|
|
package connection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-28 09:10:30 +00:00
|
|
|
"io"
|
2019-11-21 17:03:13 +00:00
|
|
|
|
|
|
|
rpc "zombiezen.com/go/capnproto2/rpc"
|
|
|
|
|
2020-04-29 20:51:32 +00:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2020-09-28 09:10:30 +00:00
|
|
|
// 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
|
2020-09-28 09:10:30 +00:00
|
|
|
func NewTunnelRPCClient(
|
2019-11-21 17:03:13 +00:00
|
|
|
ctx context.Context,
|
2020-09-28 09:10:30 +00:00
|
|
|
stream io.ReadWriteCloser,
|
2020-04-29 20:51:32 +00:00
|
|
|
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),
|
|
|
|
)
|
2020-09-28 09:10:30 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-09-28 09:10:30 +00:00
|
|
|
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
|
|
|
}
|