diff --git a/go/cs/segreq/BUILD.bazel b/go/cs/segreq/BUILD.bazel index f33efce6fe..1f5a2fa2d5 100644 --- a/go/cs/segreq/BUILD.bazel +++ b/go/cs/segreq/BUILD.bazel @@ -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", diff --git a/go/cs/segreq/db.go b/go/cs/segreq/db.go index ba31f5b4c6..bb78443fc0 100644 --- a/go/cs/segreq/db.go +++ b/go/cs/segreq/db.go @@ -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, @@ -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 @@ -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 -} diff --git a/go/cs/segreq/db_test.go b/go/cs/segreq/db_test.go index e2ac093a59..dce5163430 100644 --- a/go/cs/segreq/db_test.go +++ b/go/cs/segreq/db_test.go @@ -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" ) @@ -36,7 +36,7 @@ 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 }{ @@ -44,7 +44,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(false, errors.New("test err")) }, @@ -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) }, @@ -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) }, @@ -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{ diff --git a/go/cs/segreq/handler.go b/go/cs/segreq/handler.go index 07d3f04166..b7b8d9f16d 100644 --- a/go/cs/segreq/handler.go +++ b/go/cs/segreq/handler.go @@ -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" @@ -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}, @@ -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, } } diff --git a/go/cs/segreq/mock_segreq/BUILD.bazel b/go/cs/segreq/mock_segreq/BUILD.bazel deleted file mode 100644 index c4e35f8823..0000000000 --- a/go/cs/segreq/mock_segreq/BUILD.bazel +++ /dev/null @@ -1,13 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["segreq.go"], - importpath = "github.com/scionproto/scion/go/cs/segreq/mock_segreq", - visibility = ["//visibility:public"], - deps = [ - "//go/lib/addr:go_default_library", - "//go/lib/pathdb/query:go_default_library", - "@com_github_golang_mock//gomock:go_default_library", - ], -) diff --git a/go/cs/segreq/mock_segreq/segreq.go b/go/cs/segreq/mock_segreq/segreq.go deleted file mode 100644 index a78cc2a96c..0000000000 --- a/go/cs/segreq/mock_segreq/segreq.go +++ /dev/null @@ -1,65 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/scionproto/scion/go/cs/segreq (interfaces: LocalInfo) - -// Package mock_segreq is a generated GoMock package. -package mock_segreq - -import ( - context "context" - gomock "github.com/golang/mock/gomock" - addr "github.com/scionproto/scion/go/lib/addr" - query "github.com/scionproto/scion/go/lib/pathdb/query" - reflect "reflect" -) - -// MockLocalInfo is a mock of LocalInfo interface -type MockLocalInfo struct { - ctrl *gomock.Controller - recorder *MockLocalInfoMockRecorder -} - -// MockLocalInfoMockRecorder is the mock recorder for MockLocalInfo -type MockLocalInfoMockRecorder struct { - mock *MockLocalInfo -} - -// NewMockLocalInfo creates a new mock instance -func NewMockLocalInfo(ctrl *gomock.Controller) *MockLocalInfo { - mock := &MockLocalInfo{ctrl: ctrl} - mock.recorder = &MockLocalInfoMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockLocalInfo) EXPECT() *MockLocalInfoMockRecorder { - return m.recorder -} - -// IsParamsLocal mocks base method -func (m *MockLocalInfo) IsParamsLocal(arg0 *query.Params) bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsParamsLocal", arg0) - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsParamsLocal indicates an expected call of IsParamsLocal -func (mr *MockLocalInfoMockRecorder) IsParamsLocal(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsParamsLocal", reflect.TypeOf((*MockLocalInfo)(nil).IsParamsLocal), arg0) -} - -// IsSegLocal mocks base method -func (m *MockLocalInfo) IsSegLocal(arg0 context.Context, arg1, arg2 addr.IA) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsSegLocal", arg0, arg1, arg2) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// IsSegLocal indicates an expected call of IsSegLocal -func (mr *MockLocalInfoMockRecorder) IsSegLocal(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSegLocal", reflect.TypeOf((*MockLocalInfo)(nil).IsSegLocal), arg0, arg1, arg2) -} diff --git a/go/lib/infra/modules/segfetcher/mock_segfetcher/BUILD.bazel b/go/lib/infra/modules/segfetcher/mock_segfetcher/BUILD.bazel index ecc17cb448..d3cd80c868 100644 --- a/go/lib/infra/modules/segfetcher/mock_segfetcher/BUILD.bazel +++ b/go/lib/infra/modules/segfetcher/mock_segfetcher/BUILD.bazel @@ -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", diff --git a/go/lib/infra/modules/segfetcher/mock_segfetcher/segfetcher.go b/go/lib/infra/modules/segfetcher/mock_segfetcher/segfetcher.go index d6ef5b8400..4f5e7d6d64 100644 --- a/go/lib/infra/modules/segfetcher/mock_segfetcher/segfetcher.go +++ b/go/lib/infra/modules/segfetcher/mock_segfetcher/segfetcher.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/scionproto/scion/go/lib/infra/modules/segfetcher (interfaces: DstProvider,ReplyHandler,Requester,RequestAPI,Resolver,Splitter) +// Source: github.com/scionproto/scion/go/lib/infra/modules/segfetcher (interfaces: DstProvider,ReplyHandler,Requester,RequestAPI,Resolver,Splitter,LocalInfo) // Package mock_segfetcher is a generated GoMock package. package mock_segfetcher @@ -7,6 +7,7 @@ package mock_segfetcher import ( context "context" gomock "github.com/golang/mock/gomock" + addr "github.com/scionproto/scion/go/lib/addr" path_mgmt "github.com/scionproto/scion/go/lib/ctrl/path_mgmt" segfetcher "github.com/scionproto/scion/go/lib/infra/modules/segfetcher" seghandler "github.com/scionproto/scion/go/lib/infra/modules/seghandler" @@ -240,3 +241,41 @@ func (mr *MockSplitterMockRecorder) Split(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Split", reflect.TypeOf((*MockSplitter)(nil).Split), arg0, arg1) } + +// MockLocalInfo is a mock of LocalInfo interface +type MockLocalInfo struct { + ctrl *gomock.Controller + recorder *MockLocalInfoMockRecorder +} + +// MockLocalInfoMockRecorder is the mock recorder for MockLocalInfo +type MockLocalInfoMockRecorder struct { + mock *MockLocalInfo +} + +// NewMockLocalInfo creates a new mock instance +func NewMockLocalInfo(ctrl *gomock.Controller) *MockLocalInfo { + mock := &MockLocalInfo{ctrl: ctrl} + mock.recorder = &MockLocalInfoMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockLocalInfo) EXPECT() *MockLocalInfoMockRecorder { + return m.recorder +} + +// IsSegLocal mocks base method +func (m *MockLocalInfo) IsSegLocal(arg0 context.Context, arg1, arg2 addr.IA) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSegLocal", arg0, arg1, arg2) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// IsSegLocal indicates an expected call of IsSegLocal +func (mr *MockLocalInfoMockRecorder) IsSegLocal(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSegLocal", reflect.TypeOf((*MockLocalInfo)(nil).IsSegLocal), arg0, arg1, arg2) +} diff --git a/tools/gomocks b/tools/gomocks index 9ed11a6c28..fd66b871c0 100755 --- a/tools/gomocks +++ b/tools/gomocks @@ -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"), @@ -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"),