Files
NexaVPN/backend/internal/gateway/service.go
nessi 3e2169f217 feat: add VPN DNS service with dynamic service catalog resolution and CoreDNS integration
Add ServiceDNSRecord type and gateway API endpoint to expose active service domain-to-IP mappings. Implement ListServiceDNSRecords repository method querying services table with proxy_ip resolution using effectiveAccessProxyIP helper.

Add vpn-dns microservice built on CoreDNS with periodic sync from backend API. Generate Corefile with configurable upstream DNS servers and hosts plugin for service overrides.
2026-03-18 13:30:34 +01:00

70 lines
1.6 KiB
Go

package gateway
import (
"context"
"github.com/google/uuid"
"nexavpn/backend/internal/wireguard"
)
type Service struct {
repo Repository
}
func NewService(repo Repository) *Service {
return &Service{repo: repo}
}
func (s *Service) List(ctx context.Context) ([]Gateway, error) {
return s.repo.List(ctx)
}
func (s *Service) SelectActive(ctx context.Context) (Gateway, error) {
return s.repo.FirstActive(ctx)
}
func (s *Service) BuildSyncBundle(ctx context.Context, gatewayID string) (wireguard.GatewayBundle, error) {
id, err := uuid.Parse(gatewayID)
if err != nil {
return wireguard.GatewayBundle{}, err
}
return s.repo.BuildSyncBundle(ctx, id)
}
func (s *Service) ListServiceDNSRecords(ctx context.Context) ([]ServiceDNSRecord, error) {
return s.repo.ListServiceDNSRecords(ctx)
}
func (s *Service) Update(ctx context.Context, gatewayID string, input UpdateRequest) (Gateway, error) {
id, err := uuid.Parse(gatewayID)
if err != nil {
return Gateway{}, err
}
return s.repo.Update(ctx, id, input)
}
func (s *Service) StoreTelemetry(ctx context.Context, gatewayID string, snapshot TelemetrySnapshot) error {
id, err := uuid.Parse(gatewayID)
if err != nil {
return err
}
return s.repo.StoreTelemetry(ctx, id, snapshot)
}
func (s *Service) Bootstrap(ctx context.Context, input BootstrapRequest) (Gateway, error) {
if input.Name == "" {
input.Name = "primary-gateway"
}
if input.ListenPort == 0 {
input.ListenPort = 51820
}
if input.VPNCIDR == "" {
input.VPNCIDR = "100.96.0.0/24"
}
if len(input.DNSServers) == 0 {
input.DNSServers = []string{"10.20.0.53"}
}
return s.repo.UpsertByName(ctx, input)
}