Skip to content

Commit

Permalink
Remove unused RetrySleep and IsParamsLocal from segreq/db
Browse files Browse the repository at this point in the history
These have become unused by removing the request holding feature in #3604.
  • Loading branch information
matzf committed May 6, 2020
1 parent 27281da commit 9745548
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 136 deletions.
2 changes: 1 addition & 1 deletion go/cs/segreq/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ go_test(
],
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
11 changes: 4 additions & 7 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 @@ -117,7 +115,7 @@ func (h *handler) Handle(request *infra.Request) *infra.HandlerResult {
}

// 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 @@ -129,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.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "github.com/scionproto/scion/go/lib/infra/modules/segfetcher/mock_segfetcher",
visibility = ["//visibility:public"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/infra/modules/segfetcher:go_default_library",
"//go/lib/infra/modules/seghandler:go_default_library",
Expand Down
41 changes: 40 additions & 1 deletion go/lib/infra/modules/segfetcher/mock_segfetcher/segfetcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tools/gomocks
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ MOCK_TARGETS = [
"BeaconInserter,BeaconProvider,SegmentProvider,SegmentStore"),
(SCION_PACKAGE_PREFIX + "/go/cs/keepalive", "IfStatePusher,RevDropper"),
(SCION_PACKAGE_PREFIX + "/go/cs/revocation", "Store"),
(SCION_PACKAGE_PREFIX + "/go/cs/segreq", "LocalInfo"),
(SCION_PACKAGE_PREFIX + "/go/cs/segutil", "Policy"),
(SCION_PACKAGE_PREFIX + "/go/hidden_path_srv/internal/registration", "Validator"),
(SCION_PACKAGE_PREFIX + "/go/hidden_path_srv/internal/hpsegreq", "Fetcher"),
Expand All @@ -46,7 +45,7 @@ MOCK_TARGETS = [
"ASInspector,Messenger,ResponseWriter,TrustStore,Verifier"),
(SCION_PACKAGE_PREFIX + "/go/lib/infra/messenger", "LocalSVCRouter,Resolver"),
(SCION_PACKAGE_PREFIX + "/go/lib/infra/modules/segfetcher",
"DstProvider,ReplyHandler,Requester,RequestAPI,Resolver,Splitter"),
"DstProvider,ReplyHandler,Requester,RequestAPI,Resolver,Splitter,LocalInfo"),
(SCION_PACKAGE_PREFIX + "/go/lib/infra/modules/seghandler", "Storage,Verifier"),
(SCION_PACKAGE_PREFIX + "/go/lib/infra/modules/trust",
"CryptoProvider,DB,KeyRing,Inserter,Recurser,Resolver,Router,RPC"),
Expand Down

0 comments on commit 9745548

Please sign in to comment.