From 6174c4588b18e61efc1d9981ec1aa37dfd7cb5e4 Mon Sep 17 00:00:00 2001 From: Devin Carr Date: Wed, 26 Jun 2024 13:34:49 -0700 Subject: [PATCH] TUN-8489: Add default noop logger for capnprpc --- tunnelrpc/quic/cloudflared_client.go | 2 +- tunnelrpc/quic/cloudflared_server.go | 4 +--- tunnelrpc/quic/session_client.go | 2 +- tunnelrpc/quic/session_server.go | 4 +--- tunnelrpc/registration_client.go | 2 +- tunnelrpc/registration_server.go | 5 +---- tunnelrpc/utils.go | 20 ++++++++++++++++++++ 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tunnelrpc/quic/cloudflared_client.go b/tunnelrpc/quic/cloudflared_client.go index 7cefd388..85a96b5f 100644 --- a/tunnelrpc/quic/cloudflared_client.go +++ b/tunnelrpc/quic/cloudflared_client.go @@ -32,7 +32,7 @@ func NewCloudflaredClient(ctx context.Context, stream io.ReadWriteCloser, reques return nil, fmt.Errorf("expect to write %d bytes for RPC stream protocol signature, wrote %d", len(rpcStreamProtocolSignature), n) } transport := tunnelrpc.SafeTransport(stream) - conn := rpc.NewConn(transport) + conn := tunnelrpc.NewClientConn(transport) client := pogs.NewCloudflaredServer_PogsClient(conn.Bootstrap(ctx), conn) return &CloudflaredClient{ client: client, diff --git a/tunnelrpc/quic/cloudflared_server.go b/tunnelrpc/quic/cloudflared_server.go index cb2c8b1a..2bba6f1c 100644 --- a/tunnelrpc/quic/cloudflared_server.go +++ b/tunnelrpc/quic/cloudflared_server.go @@ -6,8 +6,6 @@ import ( "io" "time" - "zombiezen.com/go/capnproto2/rpc" - "github.com/cloudflare/cloudflared/tunnelrpc" "github.com/cloudflare/cloudflared/tunnelrpc/pogs" ) @@ -58,7 +56,7 @@ func (s *CloudflaredServer) handleRPC(ctx context.Context, stream io.ReadWriteCl defer transport.Close() main := pogs.CloudflaredServer_ServerToClient(s.sessionManager, s.configManager) - rpcConn := rpc.NewConn(transport, rpc.MainInterface(main.Client)) + rpcConn := tunnelrpc.NewServerConn(transport, main.Client) defer rpcConn.Close() // We ignore the errors here because if cloudflared fails to handle a request, we will just move on. diff --git a/tunnelrpc/quic/session_client.go b/tunnelrpc/quic/session_client.go index 05c49910..75e36906 100644 --- a/tunnelrpc/quic/session_client.go +++ b/tunnelrpc/quic/session_client.go @@ -31,7 +31,7 @@ func NewSessionClient(ctx context.Context, stream io.ReadWriteCloser, requestTim return nil, fmt.Errorf("expect to write %d bytes for RPC stream protocol signature, wrote %d", len(rpcStreamProtocolSignature), n) } transport := tunnelrpc.SafeTransport(stream) - conn := rpc.NewConn(transport) + conn := tunnelrpc.NewClientConn(transport) return &SessionClient{ client: pogs.NewSessionManager_PogsClient(conn.Bootstrap(ctx), conn), transport: transport, diff --git a/tunnelrpc/quic/session_server.go b/tunnelrpc/quic/session_server.go index f5269e3c..1d724742 100644 --- a/tunnelrpc/quic/session_server.go +++ b/tunnelrpc/quic/session_server.go @@ -6,8 +6,6 @@ import ( "io" "time" - "zombiezen.com/go/capnproto2/rpc" - "github.com/cloudflare/cloudflared/tunnelrpc" "github.com/cloudflare/cloudflared/tunnelrpc/pogs" ) @@ -48,7 +46,7 @@ func (s *SessionManagerServer) Serve(ctx context.Context, stream io.ReadWriteClo defer transport.Close() main := pogs.SessionManager_ServerToClient(s.sessionManager) - rpcConn := rpc.NewConn(transport, rpc.MainInterface(main.Client)) + rpcConn := tunnelrpc.NewServerConn(transport, main.Client) defer rpcConn.Close() select { diff --git a/tunnelrpc/registration_client.go b/tunnelrpc/registration_client.go index e27ad610..f41819f3 100644 --- a/tunnelrpc/registration_client.go +++ b/tunnelrpc/registration_client.go @@ -35,7 +35,7 @@ type registrationClient struct { func NewRegistrationClient(ctx context.Context, stream io.ReadWriteCloser, requestTimeout time.Duration) RegistrationClient { transport := SafeTransport(stream) - conn := rpc.NewConn(transport) + conn := NewClientConn(transport) client := pogs.NewRegistrationServer_PogsClient(conn.Bootstrap(ctx), conn) return ®istrationClient{ client: client, diff --git a/tunnelrpc/registration_server.go b/tunnelrpc/registration_server.go index 84044e84..a40e3fb3 100644 --- a/tunnelrpc/registration_server.go +++ b/tunnelrpc/registration_server.go @@ -4,8 +4,6 @@ import ( "context" "io" - "zombiezen.com/go/capnproto2/rpc" - "github.com/cloudflare/cloudflared/tunnelrpc/pogs" ) @@ -28,8 +26,7 @@ func (s *RegistrationServer) Serve(ctx context.Context, stream io.ReadWriteClose defer transport.Close() main := pogs.RegistrationServer_ServerToClient(s.registrationServer) - rpcConn := rpc.NewConn(transport, rpc.MainInterface(main.Client)) - defer rpcConn.Close() + rpcConn := NewServerConn(transport, main.Client) select { case <-rpcConn.Done(): diff --git a/tunnelrpc/utils.go b/tunnelrpc/utils.go index dd99dcea..27ac15c7 100644 --- a/tunnelrpc/utils.go +++ b/tunnelrpc/utils.go @@ -1,10 +1,12 @@ package tunnelrpc import ( + "context" "io" "time" "github.com/pkg/errors" + capnp "zombiezen.com/go/capnproto2" "zombiezen.com/go/capnproto2/rpc" ) @@ -67,3 +69,21 @@ func isTemporaryError(e error) bool { t, ok := e.(temp) return ok && t.Temporary() } + +// NoopCapnpLogger provides a logger to discard all capnp rpc internal logging messages as +// they are by default provided to stdout if no logger interface is provided. These logging +// messages in cloudflared have typically not provided a high amount of pratical value +// as the messages are extremely verbose and don't provide a good insight into the message +// contents or rpc method names. +type noopCapnpLogger struct{} + +func (noopCapnpLogger) Infof(ctx context.Context, format string, args ...interface{}) {} +func (noopCapnpLogger) Errorf(ctx context.Context, format string, args ...interface{}) {} + +func NewClientConn(transport rpc.Transport) *rpc.Conn { + return rpc.NewConn(transport, rpc.ConnLog(noopCapnpLogger{})) +} + +func NewServerConn(transport rpc.Transport, client capnp.Client) *rpc.Conn { + return rpc.NewConn(transport, rpc.MainInterface(client), rpc.ConnLog(noopCapnpLogger{})) +}