From 8894db37e6c115f4bad3a078325d0089c2600bad Mon Sep 17 00:00:00 2001 From: diphantxm Date: Fri, 12 Apr 2024 17:40:46 +0300 Subject: [PATCH] remove unix socket port type and add flag to skip ssl --- router/app/app.go | 4 ++-- router/instance/instance.go | 10 +++++----- router/port/port.go | 2 -- router/rulerouter/rulerouter.go | 6 +++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/router/app/app.go b/router/app/app.go index d73c908fe..dde709a64 100644 --- a/router/app/app.go +++ b/router/app/app.go @@ -66,7 +66,7 @@ func (app *App) ServeRouter(ctx context.Context) error { spqrlog.Zero.Info(). Str("address", address). Msg("SPQR Router is ready by postgresql proto") - _ = app.spqr.Run(ctx, listener, pt) + _ = app.spqr.Run(ctx, listener, pt, false) }(addr, portType) } lwg.Wait() @@ -127,7 +127,7 @@ func (app *App) ServceUnixSocket(ctx context.Context) error { spqrlog.Zero.Info(). Msg("SPQR Router is ready by unix socket") go func() { - _ = app.spqr.Run(ctx, listener, port.UnixSocketPortType) + _ = app.spqr.Run(ctx, listener, port.DefaultRouterPortType, true) }() <-ctx.Done() diff --git a/router/instance/instance.go b/router/instance/instance.go index 466a17d90..0b0e1ef8e 100644 --- a/router/instance/instance.go +++ b/router/instance/instance.go @@ -156,8 +156,8 @@ func NewRouter(ctx context.Context, rcfg *config.Router, ns string, persist bool return r, nil } -func (r *InstanceImpl) serv(netconn net.Conn, pt port.RouterPortType) error { - routerClient, err := r.RuleRouter.PreRoute(netconn, pt) +func (r *InstanceImpl) serv(netconn net.Conn, pt port.RouterPortType, skipSSL bool) error { + routerClient, err := r.RuleRouter.PreRoute(netconn, pt, skipSSL) if err != nil { _ = netconn.Close() return err @@ -192,7 +192,7 @@ func (r *InstanceImpl) serv(netconn net.Conn, pt port.RouterPortType) error { return frontend.Frontend(r.Qrouter, routerClient, cmngr, r.RuleRouter.Config(), r.Writer) } -func (r *InstanceImpl) Run(ctx context.Context, listener net.Listener, pt port.RouterPortType) error { +func (r *InstanceImpl) Run(ctx context.Context, listener net.Listener, pt port.RouterPortType, skipSSL bool) error { if r.cfg.WithJaeger { closer, err := r.initJaegerTracer(r.RuleRouter.Config()) if err != nil { @@ -242,7 +242,7 @@ func (r *InstanceImpl) Run(ctx context.Context, listener net.Listener, pt port.R _ = conn.Close() } else { go func() { - if err := r.serv(conn, pt); err != nil { + if err := r.serv(conn, pt, skipSSL); err != nil { spqrlog.Zero.Error().Err(err).Msg("error serving client") } }() @@ -284,7 +284,7 @@ func (r *InstanceImpl) RunAdm(ctx context.Context, listener net.Listener) error return nil case conn := <-cChan: go func() { - if err := r.serv(conn, port.ADMRouterPortType); err != nil { + if err := r.serv(conn, port.ADMRouterPortType, false); err != nil { spqrlog.Zero.Error().Err(err).Msg("") } }() diff --git a/router/port/port.go b/router/port/port.go index 21b0c66f2..8d26c212d 100644 --- a/router/port/port.go +++ b/router/port/port.go @@ -8,6 +8,4 @@ const ( RORouterPortType = RouterPortType(1) ADMRouterPortType = RouterPortType(2) - - UnixSocketPortType = RouterPortType(3) ) diff --git a/router/rulerouter/rulerouter.go b/router/rulerouter/rulerouter.go index 71523bbaa..58d00127b 100644 --- a/router/rulerouter/rulerouter.go +++ b/router/rulerouter/rulerouter.go @@ -30,7 +30,7 @@ type RuleRouter interface { Shutdown() error Reload(configPath string) error - PreRoute(conn net.Conn, pt port.RouterPortType) (rclient.RouterClient, error) + PreRoute(conn net.Conn, pt port.RouterPortType, skipSSL bool) (rclient.RouterClient, error) PreRouteInitializedClientAdm(cl rclient.RouterClient) (rclient.RouterClient, error) ObsoleteRoute(key route.Key) error @@ -169,11 +169,11 @@ func NewRouter(tlsconfig *tls.Config, rcfg *config.Router, notifier *notifier.No } // TODO : unit tests -func (r *RuleRouterImpl) PreRoute(conn net.Conn, pt port.RouterPortType) (rclient.RouterClient, error) { +func (r *RuleRouterImpl) PreRoute(conn net.Conn, pt port.RouterPortType, skipSSL bool) (rclient.RouterClient, error) { cl := rclient.NewPsqlClient(conn, pt, r.Config().Qr.DefaultRouteBehaviour) tlsConfig := r.tlsconfig - if pt == port.UnixSocketPortType { + if skipSSL { tlsConfig = nil } if err := cl.Init(tlsConfig); err != nil {