Skip to content

Commit

Permalink
Merge pull request #656 from i-hate-nicknames/feature/add-min-hops-co…
Browse files Browse the repository at this point in the history
…nfig

Feature/add min hops config
  • Loading branch information
jdknives authored Mar 18, 2021
2 parents 6c9a0dd + 8bd07e2 commit 5b4e24a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 7 additions & 1 deletion pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Config struct {
RouteGroupDialer setupclient.RouteGroupDialer
SetupNodes []cipher.PubKey
RulesGCInterval time.Duration
MinHops uint16
MaxHops uint16
}

// SetDefaults sets default values for certain empty values.
Expand All @@ -76,6 +78,10 @@ func (c *Config) SetDefaults() {
if c.RulesGCInterval <= 0 {
c.RulesGCInterval = DefaultRulesGCInterval
}

if c.MaxHops == 0 {
c.MaxHops = maxHops
}
}

// DialOptions describes dial options.
Expand Down Expand Up @@ -827,7 +833,7 @@ fetchRoutesAgain:
ctx := context.Background()

paths, err := r.conf.RouteFinder.FindRoutes(ctx, []routing.PathEdges{forward, backward},
&rfclient.RouteOptions{MinHops: minHops, MaxHops: maxHops})
&rfclient.RouteOptions{MinHops: r.conf.MinHops, MaxHops: r.conf.MaxHops})

if err == rfclient.ErrTransportNotFound {
return nil, nil, err
Expand Down
1 change: 1 addition & 0 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func initRouter(v *Visor) bool {
RouteGroupDialer: setupclient.NewSetupNodeDialer(),
SetupNodes: conf.SetupNodes,
RulesGCInterval: 0, // TODO
MinHops: v.conf.Routing.MinHops,
}

r, err := router.New(v.net, &rConf)
Expand Down
6 changes: 4 additions & 2 deletions pkg/visor/visorconfig/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func Parse(log *logging.MasterLogger, path string, raw []byte) (*V1, error) {
}

switch cc.Version {
case V1Name: // Current version.
// parse any v1-compatible version with v1 parse procedure
case V110Name:
fallthrough
case V100Name:
return parseV1(cc, raw)
case V0Name, V0NameOldFormat, "":
return parseV0(cc, raw)
Expand All @@ -47,7 +50,6 @@ func parseV1(cc *Common, raw []byte) (*V1, error) {
conf := MakeBaseConfig(cc)

dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&conf); err != nil {
return nil, err
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/visor/visorconfig/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ import (

//go:generate readmegen -n V1 -o ./README.md ./v1.go

// V1Name is the semantic version string for V1.
const V1Name = "v1.0.0"
// V100Name is the semantic version string for v1.0.0.
const V100Name = "v1.0.0"

// V110Name is the semantic version string for v1.1.0.
// Added MinHops field to V1Routing section of config
const V110Name = "v1.1.0"

// V1Name is the semantic version string for the most recent version of V1.
const V1Name = V110Name

// V1 is visor config v1.0.0
type V1 struct {
Expand Down Expand Up @@ -70,6 +77,7 @@ type V1Routing struct {
SetupNodes []cipher.PubKey `json:"setup_nodes,omitempty"`
RouteFinder string `json:"route_finder"`
RouteFinderTimeout Duration `json:"route_finder_timeout,omitempty"`
MinHops uint16 `json:"min_hops"`
}

// V1UptimeTracker configures uptime tracker.
Expand Down

0 comments on commit 5b4e24a

Please sign in to comment.