Add L7/PROXY protocol data model, config, and architecture docs
Extend the config, database schema, and server internals to support per-route L4/L7 mode selection and PROXY protocol fields. This is the foundation for L7 HTTP/2 reverse proxying and multi-hop PROXY protocol support described in the updated ARCHITECTURE.md. Config: Listener gains ProxyProtocol; Route gains Mode, TLSCert, TLSKey, BackendTLS, SendProxyProtocol. L7 routes validated at load time (cert/key pair must exist and parse). Mode defaults to "l4". DB: Migration v2 adds columns to listeners and routes tables. CRUD and seeding updated to persist all new fields. Server: RouteInfo replaces bare backend string in route lookup. handleConn dispatches on route.Mode (L7 path stubbed with error). ListenerState and ListenerData carry ProxyProtocol flag. All existing L4 tests pass unchanged. New tests cover migration v2, L7 field persistence, config validation for mode/cert/key, and proxy_protocol flag round-tripping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,16 +4,22 @@ import "fmt"
|
||||
|
||||
// Route is a database route record.
|
||||
type Route struct {
|
||||
ID int64
|
||||
ListenerID int64
|
||||
Hostname string
|
||||
Backend string
|
||||
ID int64
|
||||
ListenerID int64
|
||||
Hostname string
|
||||
Backend string
|
||||
Mode string // "l4" or "l7"
|
||||
TLSCert string
|
||||
TLSKey string
|
||||
BackendTLS bool
|
||||
SendProxyProtocol bool
|
||||
}
|
||||
|
||||
// ListRoutes returns all routes for a listener.
|
||||
func (s *Store) ListRoutes(listenerID int64) ([]Route, error) {
|
||||
rows, err := s.db.Query(
|
||||
"SELECT id, listener_id, hostname, backend FROM routes WHERE listener_id = ? ORDER BY hostname",
|
||||
`SELECT id, listener_id, hostname, backend, mode, tls_cert, tls_key, backend_tls, send_proxy_protocol
|
||||
FROM routes WHERE listener_id = ? ORDER BY hostname`,
|
||||
listenerID,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -24,7 +30,8 @@ func (s *Store) ListRoutes(listenerID int64) ([]Route, error) {
|
||||
var routes []Route
|
||||
for rows.Next() {
|
||||
var r Route
|
||||
if err := rows.Scan(&r.ID, &r.ListenerID, &r.Hostname, &r.Backend); err != nil {
|
||||
if err := rows.Scan(&r.ID, &r.ListenerID, &r.Hostname, &r.Backend,
|
||||
&r.Mode, &r.TLSCert, &r.TLSKey, &r.BackendTLS, &r.SendProxyProtocol); err != nil {
|
||||
return nil, fmt.Errorf("scanning route: %w", err)
|
||||
}
|
||||
routes = append(routes, r)
|
||||
@@ -33,10 +40,11 @@ func (s *Store) ListRoutes(listenerID int64) ([]Route, error) {
|
||||
}
|
||||
|
||||
// CreateRoute inserts a route and returns its ID.
|
||||
func (s *Store) CreateRoute(listenerID int64, hostname, backend string) (int64, error) {
|
||||
func (s *Store) CreateRoute(listenerID int64, hostname, backend, mode, tlsCert, tlsKey string, backendTLS, sendProxyProtocol bool) (int64, error) {
|
||||
result, err := s.db.Exec(
|
||||
"INSERT INTO routes (listener_id, hostname, backend) VALUES (?, ?, ?)",
|
||||
listenerID, hostname, backend,
|
||||
`INSERT INTO routes (listener_id, hostname, backend, mode, tls_cert, tls_key, backend_tls, send_proxy_protocol)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
listenerID, hostname, backend, mode, tlsCert, tlsKey, backendTLS, sendProxyProtocol,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("inserting route: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user