Skip to content

Commit

Permalink
remove unix socket port type and add flag to skip ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm committed Apr 12, 2024
1 parent 517c8fe commit 8894db3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions router/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions router/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
}()
Expand Down Expand Up @@ -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("")
}
}()
Expand Down
2 changes: 0 additions & 2 deletions router/port/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ const (
RORouterPortType = RouterPortType(1)

ADMRouterPortType = RouterPortType(2)

UnixSocketPortType = RouterPortType(3)
)
6 changes: 3 additions & 3 deletions router/rulerouter/rulerouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8894db3

Please sign in to comment.