Skip to content

Commit

Permalink
Remove unnecesary code
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnavarro committed Sep 22, 2022
1 parent 71bb506 commit a067db5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 64 deletions.
3 changes: 0 additions & 3 deletions config/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ type Router struct {
// In the future we will support "dht" and other Types here.
Type RouterType

Enabled Flag `json:",omitempty"`

// Parameters are extra configuration that this router might need.
// A common one for reframe router is "Endpoint".
Parameters interface{}
Expand Down Expand Up @@ -95,7 +93,6 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error {
}

r.Router.Type = out.Type
r.Router.Enabled = out.Enabled
r.Router.Parameters = p

return nil
Expand Down
15 changes: 5 additions & 10 deletions config/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@ func TestRouterParameters(t *testing.T) {
Type: "custom",
Routers: map[string]RouterParser{
"router-dht": {Router{
Type: RouterTypeDHT,
Enabled: True,
Type: RouterTypeDHT,
Parameters: DHTRouterParams{
Mode: "auto",
AcceleratedDHTClient: true,
PublicIPNetwork: false,
},
}},
"router-reframe": {Router{
Type: RouterTypeReframe,
Enabled: True,
Type: RouterTypeReframe,
Parameters: ReframeRouterParams{
Endpoint: "reframe-endpoint",
},
}},
"router-parallel": {Router{
Type: RouterTypeParallel,
Enabled: True,
Type: RouterTypeParallel,
Parameters: ComposableRouterParams{
Routers: []ConfigRouter{
{
Expand All @@ -52,8 +49,7 @@ func TestRouterParameters(t *testing.T) {
}},
},
"router-sequential": {Router{
Type: RouterTypeSequential,
Enabled: True,
Type: RouterTypeSequential,
Parameters: ComposableRouterParams{
Routers: []ConfigRouter{
{
Expand Down Expand Up @@ -120,8 +116,7 @@ func TestRouterMissingParameters(t *testing.T) {
Type: "custom",
Routers: map[string]RouterParser{
"router-wrong-reframe": {Router{
Type: RouterTypeReframe,
Enabled: True,
Type: RouterTypeReframe,
Parameters: DHTRouterParams{
Mode: "auto",
AcceleratedDHTClient: true,
Expand Down
11 changes: 0 additions & 11 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ config file at runtime.
- [`Routing`](#routing)
- [`Routing.Routers`](#routingrouters)
- [`Routing.Routers: Type`](#routingrouters-type)
- [`Routing.Routers: Enabled`](#routingrouters-enabled)
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
- [`Routing: Methods`](#routing-methods)
- [`Routing.Type`](#routingtype)
Expand Down Expand Up @@ -1297,16 +1296,6 @@ Currently supported types:

Type: `string`

#### `Routing.Routers: Enabled`

**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**

Optional flag to disable the specified router without removing it from the configuration file.

Default: `true`

Type: `flag` (`null`/missing will apply the default)

#### `Routing.Routers: Parameters`

**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**
Expand Down
31 changes: 9 additions & 22 deletions routing/delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,9 @@ func Parse(routers config.Routers, methods config.Methods, extraDHT *ExtraDHTPar

// Create all needed routers from method names
for mn, m := range methods {
r, ok := createdRouters[m.RouterName]
var router routing.Routing
if ok {
router = r
} else {
r, err := parse(make(map[string]bool), createdRouters, m.RouterName, routers, extraDHT, extraReframe)
if err != nil {
return nil, err
}
router = r
router, err := parse(make(map[string]bool), createdRouters, m.RouterName, routers, extraDHT, extraReframe)
if err != nil {
return nil, err
}

switch mn {
Expand Down Expand Up @@ -105,12 +98,9 @@ func parse(visited map[string]bool,
crp := cfg.Parameters.(*config.ComposableRouterParams)
var pr []*routinghelpers.ParallelRouter
for _, cr := range crp.Routers {
ri, ok := createdRouters[cr.RouterName]
if !ok {
ri, err = parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraReframe)
if err != nil {
return nil, err
}
ri, err := parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraReframe)
if err != nil {
return nil, err
}

pr = append(pr, &routinghelpers.ParallelRouter{
Expand All @@ -127,12 +117,9 @@ func parse(visited map[string]bool,
crp := cfg.Parameters.(*config.ComposableRouterParams)
var sr []*routinghelpers.SequentialRouter
for _, cr := range crp.Routers {
ri, ok := createdRouters[cr.RouterName]
if !ok {
ri, err = parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraReframe)
if err != nil {
return nil, err
}
ri, err := parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraReframe)
if err != nil {
return nil, err
}

sr = append(sr, &routinghelpers.SequentialRouter{
Expand Down
27 changes: 9 additions & 18 deletions routing/delegated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ func TestParser(t *testing.T) {
router, err := Parse(config.Routers{
"r1": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeReframe,
Enabled: config.True,
Type: config.RouterTypeReframe,
Parameters: &config.ReframeRouterParams{
Endpoint: "testEndpoint",
},
},
},
"r2": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeSequential,
Enabled: config.True,
Type: config.RouterTypeSequential,
Parameters: &config.ComposableRouterParams{
Routers: []config.ConfigRouter{
{
Expand Down Expand Up @@ -114,35 +112,31 @@ func TestParserRecursive(t *testing.T) {
router, err := Parse(config.Routers{
"reframe1": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeReframe,
Enabled: config.True,
Type: config.RouterTypeReframe,
Parameters: &config.ReframeRouterParams{
Endpoint: "testEndpoint1",
},
},
},
"reframe2": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeReframe,
Enabled: config.True,
Type: config.RouterTypeReframe,
Parameters: &config.ReframeRouterParams{
Endpoint: "testEndpoint2",
},
},
},
"reframe3": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeReframe,
Enabled: config.True,
Type: config.RouterTypeReframe,
Parameters: &config.ReframeRouterParams{
Endpoint: "testEndpoint3",
},
},
},
"composable1": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeSequential,
Enabled: config.True,
Type: config.RouterTypeSequential,
Parameters: &config.ComposableRouterParams{
Routers: []config.ConfigRouter{
{
Expand All @@ -157,8 +151,7 @@ func TestParserRecursive(t *testing.T) {
},
"composable2": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeParallel,
Enabled: config.True,
Type: config.RouterTypeParallel,
Parameters: &config.ComposableRouterParams{
Routers: []config.ConfigRouter{
{
Expand Down Expand Up @@ -202,8 +195,7 @@ func TestParserRecursiveLoop(t *testing.T) {
_, err := Parse(config.Routers{
"composable1": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeSequential,
Enabled: config.True,
Type: config.RouterTypeSequential,
Parameters: &config.ComposableRouterParams{
Routers: []config.ConfigRouter{
{
Expand All @@ -215,8 +207,7 @@ func TestParserRecursiveLoop(t *testing.T) {
},
"composable2": config.RouterParser{
Router: config.Router{
Type: config.RouterTypeParallel,
Enabled: config.True,
Type: config.RouterTypeParallel,
Parameters: &config.ComposableRouterParams{
Routers: []config.ConfigRouter{
{
Expand Down

0 comments on commit a067db5

Please sign in to comment.