Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code related to segment requests #3748

Merged
merged 3 commits into from
May 12, 2020
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
3 changes: 1 addition & 2 deletions go/cs/segreq/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ go_test(
"helpers_test.go",
"provider_test.go",
"splitter_test.go",
"validator_test.go",
],
embed = [":go_default_library"],
deps = [
"//go/cs/segreq/mock_segreq:go_default_library",
"//go/lib/addr:go_default_library",
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/ctrl/seg:go_default_library",
"//go/lib/infra/mock_infra:go_default_library",
"//go/lib/infra/modules/segfetcher:go_default_library",
"//go/lib/infra/modules/segfetcher/mock_segfetcher:go_default_library",
"//go/lib/pathdb/mock_pathdb:go_default_library",
"//go/lib/pathdb/query:go_default_library",
"//go/lib/revcache:go_default_library",
Expand Down
45 changes: 4 additions & 41 deletions go/cs/segreq/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@ import (
"time"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/infra/modules/segfetcher"
"github.com/scionproto/scion/go/lib/pathdb"
"github.com/scionproto/scion/go/lib/pathdb/query"
"github.com/scionproto/scion/go/proto"
)

// LocalInfo indicates whether something is always local.
type LocalInfo interface {
IsSegLocal(ctx context.Context, src, dst addr.IA) (bool, error)
IsParamsLocal(*query.Params) bool
}

// PathDB is a wrapper around the path db that handles retries and changes
// GetNextQuery behavior for usage in segfetcher.
// PathDB is a wrapper around the path db that changes GetNextQuery behavior
// for usage in segfetcher.
type PathDB struct {
pathdb.PathDB
LocalInfo LocalInfo
RetrySleep time.Duration
LocalInfo segfetcher.LocalInfo
}

func (db *PathDB) GetNextQuery(ctx context.Context, src, dst addr.IA,
Expand Down Expand Up @@ -69,30 +61,6 @@ func (i *CoreLocalInfo) IsSegLocal(ctx context.Context, src, dst addr.IA) (bool,
return isCore, nil
}

// IsParamsLocal returns whether params is a core segment request.
func (i *CoreLocalInfo) IsParamsLocal(params *query.Params) bool {
if len(params.SegTypes) != 1 {
return false
}
if params.SegTypes[0] == proto.PathSegType_core {
return true
}
if params.SegTypes[0] == proto.PathSegType_down {
for _, ia := range params.StartsAt {
if ia.I != i.LocalIA.I {
return false
}
}
for _, ia := range params.EndsAt {
if ia.I != i.LocalIA.I {
return false
}
}
return true
}
return false
}

// NonCoreLocalInfo is the local info for non core PSes.
type NonCoreLocalInfo struct {
LocalIA addr.IA
Expand All @@ -105,8 +73,3 @@ func (i *NonCoreLocalInfo) IsSegLocal(ctx context.Context, src, dst addr.IA) (bo
// be an up segment.
return i.LocalIA.Equal(src), nil
}

// IsParamsLocal returns whether params is a up segments request.
func (i *NonCoreLocalInfo) IsParamsLocal(params *query.Params) bool {
return len(params.SegTypes) == 1 && params.SegTypes[0] == proto.PathSegType_up
}
12 changes: 6 additions & 6 deletions go/cs/segreq/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/stretchr/testify/require"

"github.com/scionproto/scion/go/cs/segreq"
"github.com/scionproto/scion/go/cs/segreq/mock_segreq"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/infra/modules/segfetcher/mock_segfetcher"
"github.com/scionproto/scion/go/lib/pathdb/mock_pathdb"
"github.com/scionproto/scion/go/lib/xtest"
)
Expand All @@ -36,15 +36,15 @@ func TestPSPathDBGetNextQuery(t *testing.T) {
Src addr.IA
Dst addr.IA
PreparePathDB func(db *mock_pathdb.MockPathDB, src, dst addr.IA)
PrepareLocalInfo func(i *mock_segreq.MockLocalInfo, src, dst addr.IA)
PrepareLocalInfo func(i *mock_segfetcher.MockLocalInfo, src, dst addr.IA)
ErrorAssertion require.ErrorAssertionFunc
AssertNextQueryAfterNow assert.BoolAssertionFunc
}{
"LocalInfo error": {
Src: xtest.MustParseIA("1-ff00:0:111"),
Dst: xtest.MustParseIA("1-ff00:0:120"),
PreparePathDB: func(db *mock_pathdb.MockPathDB, src, dst addr.IA) {},
PrepareLocalInfo: func(i *mock_segreq.MockLocalInfo, src, dst addr.IA) {
PrepareLocalInfo: func(i *mock_segfetcher.MockLocalInfo, src, dst addr.IA) {
i.EXPECT().IsSegLocal(gomock.Any(), src, dst).
Return(false, errors.New("test err"))
},
Expand All @@ -55,7 +55,7 @@ func TestPSPathDBGetNextQuery(t *testing.T) {
Src: xtest.MustParseIA("1-ff00:0:111"),
Dst: xtest.MustParseIA("1-ff00:0:120"),
PreparePathDB: func(db *mock_pathdb.MockPathDB, src, dst addr.IA) {},
PrepareLocalInfo: func(i *mock_segreq.MockLocalInfo, src, dst addr.IA) {
PrepareLocalInfo: func(i *mock_segfetcher.MockLocalInfo, src, dst addr.IA) {
i.EXPECT().IsSegLocal(gomock.Any(), src, dst).
Return(true, nil)
},
Expand All @@ -69,7 +69,7 @@ func TestPSPathDBGetNextQuery(t *testing.T) {
db.EXPECT().GetNextQuery(gomock.Any(), src, dst, gomock.Any()).
Return(time.Now().Add(time.Hour), nil)
},
PrepareLocalInfo: func(i *mock_segreq.MockLocalInfo, src, dst addr.IA) {
PrepareLocalInfo: func(i *mock_segfetcher.MockLocalInfo, src, dst addr.IA) {
i.EXPECT().IsSegLocal(gomock.Any(), src, dst).
Return(false, nil)
},
Expand All @@ -82,7 +82,7 @@ func TestPSPathDBGetNextQuery(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
pdb := mock_pathdb.NewMockPathDB(ctrl)
li := mock_segreq.NewMockLocalInfo(ctrl)
li := mock_segfetcher.NewMockLocalInfo(ctrl)
test.PreparePathDB(pdb, test.Src, test.Dst)
test.PrepareLocalInfo(li, test.Src, test.Dst)
db := &segreq.PathDB{
Expand Down
21 changes: 4 additions & 17 deletions go/cs/segreq/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package segreq

import (
"time"

"github.com/scionproto/scion/go/cs/handlers"
"github.com/scionproto/scion/go/cs/metrics"
"github.com/scionproto/scion/go/lib/common"
Expand Down Expand Up @@ -116,18 +114,8 @@ func (h *handler) Handle(request *infra.Request) *infra.HandlerResult {
return infra.MetricsResultOk
}

func createValidator(args handlers.HandlerArgs, core bool) segfetcher.Validator {
base := BaseValidator{
CoreChecker: CoreChecker{Inspector: args.ASInspector},
}
if !core {
return &base
}
return &CoreValidator{BaseValidator: base}
}

// CreateLocalInfo creates the local info oracle.
func CreateLocalInfo(args handlers.HandlerArgs, core bool) LocalInfo {
func CreateLocalInfo(args handlers.HandlerArgs, core bool) segfetcher.LocalInfo {
if core {
return &CoreLocalInfo{
CoreChecker: CoreChecker{Inspector: args.ASInspector},
Expand All @@ -139,11 +127,10 @@ func CreateLocalInfo(args handlers.HandlerArgs, core bool) LocalInfo {
}
}

func createPathDB(db pathdb.PathDB, localInfo LocalInfo) pathdb.PathDB {
func createPathDB(db pathdb.PathDB, localInfo segfetcher.LocalInfo) pathdb.PathDB {
return &PathDB{
PathDB: db,
LocalInfo: localInfo,
RetrySleep: 500 * time.Millisecond,
PathDB: db,
LocalInfo: localInfo,
}
}

Expand Down
13 changes: 0 additions & 13 deletions go/cs/segreq/mock_segreq/BUILD.bazel

This file was deleted.

65 changes: 0 additions & 65 deletions go/cs/segreq/mock_segreq/segreq.go

This file was deleted.

Loading