From 2979c6cce629e9324479f78b6a81323e65c5a351 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 30 Jan 2020 10:25:10 +0100 Subject: [PATCH] SIG: Dispatcher bypass (#3646) --- go/sig/internal/sigcmn/BUILD.bazel | 1 + go/sig/internal/sigcmn/common.go | 44 ++++++++++++++++++++++++------ go/sig/internal/sigconfig/conf.go | 4 +++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/go/sig/internal/sigcmn/BUILD.bazel b/go/sig/internal/sigcmn/BUILD.bazel index 9712762b5a..71566f7437 100644 --- a/go/sig/internal/sigcmn/BUILD.bazel +++ b/go/sig/internal/sigcmn/BUILD.bazel @@ -6,6 +6,7 @@ go_library( importpath = "github.com/scionproto/scion/go/sig/internal/sigcmn", visibility = ["//visibility:public"], deps = [ + "//go/godispatcher/dispatcher:go_default_library", "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", "//go/lib/env:go_default_library", diff --git a/go/sig/internal/sigcmn/common.go b/go/sig/internal/sigcmn/common.go index 5a293a8eae..e6e46114b6 100644 --- a/go/sig/internal/sigcmn/common.go +++ b/go/sig/internal/sigcmn/common.go @@ -20,6 +20,7 @@ import ( "net" "time" + "github.com/scionproto/scion/go/godispatcher/dispatcher" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/env" @@ -48,11 +49,12 @@ var ( IA addr.IA Host addr.HostAddr - PathMgr pathmgr.Resolver - Network *snet.SCIONNetwork - CtrlConn snet.Conn - MgmtAddr *mgmt.Addr - encapPort uint16 + PathMgr pathmgr.Resolver + Dispatcher reliable.Dispatcher + Network *snet.SCIONNetwork + CtrlConn snet.Conn + MgmtAddr *mgmt.Addr + encapPort uint16 ) func Init(cfg sigconfig.SigConf, sdCfg env.SciondClient) error { @@ -81,6 +83,11 @@ func Init(cfg sigconfig.SigConf, sdCfg env.SciondClient) error { func initNetwork(cfg sigconfig.SigConf, sdCfg env.SciondClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) { + var err error + Dispatcher, err = newDispatcher(cfg) + if err != nil { + return nil, nil, serrors.WrapStr("unable to initialize SCION dispatcher", err) + } if sdCfg.FakeData != "" { return initNetworkWithFakeSCIOND(cfg, sdCfg) } @@ -90,13 +97,12 @@ func initNetwork(cfg sigconfig.SigConf, func initNetworkWithFakeSCIOND(cfg sigconfig.SigConf, sdCfg env.SciondClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) { - ds := reliable.NewDispatcher(cfg.Dispatcher) sciondConn, err := fake.NewFromFile(sdCfg.FakeData) if err != nil { return nil, nil, serrors.WrapStr("unable to initialize fake SCIOND service", err) } pathResolver := pathmgr.New(sciondConn, pathmgr.Timers{}) - network := snet.NewNetworkWithPR(cfg.IA, ds, &snetmigrate.PathQuerier{ + network := snet.NewNetworkWithPR(cfg.IA, Dispatcher, &snetmigrate.PathQuerier{ Resolver: pathResolver, IA: cfg.IA, }, pathResolver) @@ -106,14 +112,13 @@ func initNetworkWithFakeSCIOND(cfg sigconfig.SigConf, func initNetworkWithRealSCIOND(cfg sigconfig.SigConf, sdCfg env.SciondClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) { - ds := reliable.NewDispatcher(cfg.Dispatcher) // TODO(karampok). To be kept until https://github.com/scionproto/scion/issues/3377 deadline := time.Now().Add(sdCfg.InitialConnectPeriod.Duration) var retErr error for tries := 0; time.Now().Before(deadline); tries++ { resolver, err := snetmigrate.ResolverFromSD(sdCfg.Path) if err == nil { - return snet.NewNetworkWithPR(cfg.IA, ds, &snetmigrate.PathQuerier{ + return snet.NewNetworkWithPR(cfg.IA, Dispatcher, &snetmigrate.PathQuerier{ Resolver: resolver, IA: cfg.IA, }, resolver), resolver, nil @@ -125,6 +130,27 @@ func initNetworkWithRealSCIOND(cfg sigconfig.SigConf, return nil, nil, retErr } +func newDispatcher(cfg sigconfig.SigConf) (reliable.Dispatcher, error) { + if cfg.DispatcherBypass == "" { + log.Info("Regular SCION dispatcher", "addr", cfg.DispatcherBypass) + return reliable.NewDispatcher(cfg.Dispatcher), nil + } + // Initialize dispatcher bypass. + log.Info("Bypassing SCION dispatcher", "addr", cfg.DispatcherBypass) + dispServer, err := dispatcher.NewServer(cfg.DispatcherBypass) + if err != nil { + return nil, serrors.WrapStr("unable to initialize bypass dispatcher", err) + } + go func() { + defer log.LogPanicAndExit() + err := dispServer.Serve() + if err != nil { + log.Error("Bypass dispatcher failed", "err", err) + } + }() + return dispServer, nil +} + func EncapSnetAddr() *snet.UDPAddr { return &snet.UDPAddr{IA: IA, Host: &net.UDPAddr{IP: Host.IP(), Port: int(encapPort)}} } diff --git a/go/sig/internal/sigconfig/conf.go b/go/sig/internal/sigconfig/conf.go index c62fdb8c7f..a74d05e0d8 100644 --- a/go/sig/internal/sigconfig/conf.go +++ b/go/sig/internal/sigconfig/conf.go @@ -102,6 +102,10 @@ type SigConf struct { SrcIP4 net.IP // IPv6 source address hint to put into routing table. SrcIP6 net.IP + // DispatcherBypass is the overlay address (e.g. ":30041") to use when bypassing SCION + // dispatcher. If the field is empty bypass is not done and SCION dispatcher is used + // instead. + DispatcherBypass string } // InitDefaults sets the default values to unset values.