Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func setupDebugging(opts state.NylonOptions) {
}
}

func readCentralConfig(centralPath, nodePath string) (*state.CentralCfg, error) {
func readCentralConfig(centralPath, nodePath string, tunables *state.RouterTunables) (*state.CentralCfg, error) {
var centralCfg state.CentralCfg

file, err := os.ReadFile(centralPath)
Expand All @@ -58,7 +58,7 @@ func readCentralConfig(centralPath, nodePath string) (*state.CentralCfg, error)
return nil, fmt.Errorf("central.yaml not found and node.yaml has no dist config")
}

cfg, err := FetchConfig(nodeCfg.Dist.Url, nodeCfg.Dist.Key)
cfg, err := FetchConfig(nodeCfg.Dist.Url, nodeCfg.Dist.Key, tunables.MaxConfigSize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -103,7 +103,8 @@ func Bootstrap(centralPath, nodePath, logPath string, verbose bool, opts state.N
level = slog.LevelDebug
}

centralCfg, err := readCentralConfig(centralPath, nodePath)
tunables := state.DefaultRouterTunables()
centralCfg, err := readCentralConfig(centralPath, nodePath, &tunables)
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions core/nylon_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// fetches and unbundles central config from url
func FetchConfig(repoStr string, key state.NyPublicKey) (*state.CentralCfg, error) {
func FetchConfig(repoStr string, key state.NyPublicKey, maxSize int64) (*state.CentralCfg, error) {
repo, err := url.Parse(repoStr)
if err != nil {
return nil, fmt.Errorf("failed to parse repo URL %s: %w", repoStr, err)
Expand Down Expand Up @@ -56,7 +56,7 @@ func FetchConfig(repoStr string, key state.NyPublicKey) (*state.CentralCfg, erro
if err != nil {
return nil, fmt.Errorf("failed to fetch %s: %w", repo.String(), err)
}
cfgBody, err = io.ReadAll(res.Body)
cfgBody, err = io.ReadAll(io.LimitReader(res.Body, maxSize))
if err != nil {
res.Body.Close()
return nil, fmt.Errorf("failed to read response from %s: %w", repo.String(), err)
Expand Down Expand Up @@ -85,7 +85,7 @@ func checkForConfigUpdates(n *Nylon) error {
for _, repoStr := range repos {
go func(repo string) {
err := func() error {
config, err := FetchConfig(repo, key)
config, err := FetchConfig(repo, key, n.MaxConfigSize)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions state/tunables.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type RouterTunables struct {

EndpointResolveExpiry time.Duration
EndpointResolveDelay time.Duration

MaxConfigSize int64
}

// NylonOptions contains runtime flags set at startup (typically from CLI flags).
Expand Down Expand Up @@ -87,6 +89,8 @@ func DefaultRouterTunables() RouterTunables {

EndpointResolveExpiry: time.Minute * 1,
EndpointResolveDelay: time.Second * 15,

MaxConfigSize: 1 << 20, // 1 MB
}
}

Expand Down
Loading