Skip to content

Commit

Permalink
Add seghandler to verify and store segs & revs
Browse files Browse the repository at this point in the history
Generalizes `SegReplyHandler` from segfetcher package into `seghandler.Handler`.
This can be used to for all kind of segment storing and verification also for hidden paths etc.

Fixes #3076
  • Loading branch information
lukedirtwalker committed Sep 2, 2019
1 parent f5de4c4 commit 7de23fa
Show file tree
Hide file tree
Showing 19 changed files with 649 additions and 568 deletions.
6 changes: 1 addition & 5 deletions go/lib/infra/modules/segfetcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ go_library(
"requester.go",
"resolver.go",
"revocation.go",
"segreplyhandler.go",
"segs.go",
"splitter.go",
"validator.go",
Expand All @@ -23,7 +22,7 @@ go_library(
"//go/lib/ctrl/seg:go_default_library",
"//go/lib/infra:go_default_library",
"//go/lib/infra/messenger:go_default_library",
"//go/lib/infra/modules/segverifier:go_default_library",
"//go/lib/infra/modules/seghandler:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/pathdb:go_default_library",
"//go/lib/pathdb/query:go_default_library",
Expand All @@ -39,7 +38,6 @@ go_test(
"requester_test.go",
"resolver_test.go",
"revocation_test.go",
"segreplyhandler_test.go",
],
embed = [":go_default_library"],
deps = [
Expand All @@ -49,8 +47,6 @@ go_test(
"//go/lib/ctrl/seg:go_default_library",
"//go/lib/infra:go_default_library",
"//go/lib/infra/modules/segfetcher/mock_segfetcher:go_default_library",
"//go/lib/infra/modules/segverifier:go_default_library",
"//go/lib/mocks/net/mock_net: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
23 changes: 19 additions & 4 deletions go/lib/infra/modules/segfetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ import (

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/infra/modules/seghandler"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/pathdb"
"github.com/scionproto/scion/go/lib/revcache"
)

// ReplyHandler handles replies.
type ReplyHandler interface {
Handle(ctx context.Context, recs seghandler.Segments, server net.Addr,
earlyTrigger <-chan struct{}) *seghandler.ProcessedResult
}

// FetcherConfig is the configuration for the fetcher.
type FetcherConfig struct {
// QueryInterval specifies after how much time segments should be
Expand Down Expand Up @@ -62,9 +70,9 @@ func (cfg FetcherConfig) New() *Fetcher {
Splitter: cfg.Splitter,
Resolver: NewResolver(cfg.PathDB, cfg.RevCache, !cfg.SciondMode),
Requester: &DefaultRequester{API: cfg.RequestAPI, DstProvider: cfg.DstProvider},
ReplyHandler: &SegReplyHandler{
Verifier: &SegVerifier{Verifier: cfg.VerificationFactory.NewVerifier()},
Storage: &DefaultStorage{PathDB: cfg.PathDB, RevCache: cfg.RevCache},
ReplyHandler: &seghandler.Handler{
Verifier: &seghandler.DefaultVerifier{Verifier: cfg.VerificationFactory.NewVerifier()},
Storage: &seghandler.DefaultStorage{PathDB: cfg.PathDB, RevCache: cfg.RevCache},
},
PathDB: cfg.PathDB,
QueryInterval: cfg.QueryInterval,
Expand Down Expand Up @@ -144,7 +152,7 @@ func (f *Fetcher) waitOnProcessed(ctx context.Context, replies <-chan ReplyOrErr
if reply.Reply == nil || reply.Reply.Recs == nil {
continue
}
r := f.ReplyHandler.Handle(ctx, reply.Reply, f.verifyServer(reply), nil)
r := f.ReplyHandler.Handle(ctx, replyToRecs(reply.Reply), f.verifyServer(reply), nil)
select {
case <-r.FullReplyProcessed():
if err := r.Err(); err != nil {
Expand Down Expand Up @@ -182,3 +190,10 @@ func (f *Fetcher) verifyServer(reply ReplyOrErr) net.Addr {
}
return reply.Peer
}

func replyToRecs(reply *path_mgmt.SegReply) seghandler.Segments {
return seghandler.Segments{
Segs: reply.Recs.Recs,
SRevInfos: reply.Recs.SRevInfos,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_library(
deps = [
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/infra/modules/segfetcher:go_default_library",
"//go/lib/infra/modules/segverifier:go_default_library",
"//go/lib/infra/modules/seghandler:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
],
)
97 changes: 4 additions & 93 deletions 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.

Loading

0 comments on commit 7de23fa

Please sign in to comment.