Skip to content

Commit

Permalink
BS, DISP: Use net.UDPAddr instead of addr.AppAddr (#3375)
Browse files Browse the repository at this point in the history
Contributes #3344
  • Loading branch information
karampok authored Nov 18, 2019
1 parent 0e532f5 commit f27ecfc
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 101 deletions.
13 changes: 6 additions & 7 deletions go/beacon_srv/internal/beaconing/originator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/scionproto/scion/go/beacon_srv/internal/beacon"
"github.com/scionproto/scion/go/beacon_srv/internal/ifstate"
"github.com/scionproto/scion/go/beacon_srv/internal/onehop"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/ctrl/seg"
Expand Down Expand Up @@ -72,9 +71,9 @@ func TestOriginatorRun(t *testing.T) {
Sender: onehop.Sender{
IA: xtest.MustParseIA("1-ff00:0:110"),
Conn: conn,
Addr: &addr.AppAddr{
L3: addr.HostFromIPStr("127.0.0.1"),
L4: 4242,
Addr: &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 4242,
},
MAC: mac,
},
Expand Down Expand Up @@ -126,9 +125,9 @@ func TestOriginatorRun(t *testing.T) {
Sender: onehop.Sender{
IA: xtest.MustParseIA("1-ff00:0:110"),
Conn: conn,
Addr: &addr.AppAddr{
L3: addr.HostFromIPStr("127.0.0.1"),
L4: 4242,
Addr: &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 4242,
},
MAC: mac,
},
Expand Down
13 changes: 6 additions & 7 deletions go/beacon_srv/internal/beaconing/propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/scionproto/scion/go/beacon_srv/internal/beaconing/mock_beaconing"
"github.com/scionproto/scion/go/beacon_srv/internal/ifstate"
"github.com/scionproto/scion/go/beacon_srv/internal/onehop"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest"
"github.com/scionproto/scion/go/lib/scrypto"
Expand Down Expand Up @@ -161,9 +160,9 @@ func TestPropagatorRun(t *testing.T) {
Sender: onehop.Sender{
IA: topoProvider.Get().IA(),
Conn: conn,
Addr: &addr.AppAddr{
L3: addr.HostFromIPStr("127.0.0.1"),
L4: 4242,
Addr: &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 4242,
},
MAC: macSender,
},
Expand Down Expand Up @@ -233,9 +232,9 @@ func TestPropagatorRun(t *testing.T) {
Sender: onehop.Sender{
IA: topoProvider.Get().IA(),
Conn: conn,
Addr: &addr.AppAddr{
L3: addr.HostFromIPStr("127.0.0.1"),
L4: 4242,
Addr: &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 4242,
},
MAC: macSender,
},
Expand Down
1 change: 0 additions & 1 deletion go/beacon_srv/internal/keepalive/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ go_test(
"//go/beacon_srv/internal/ifstate:go_default_library",
"//go/beacon_srv/internal/keepalive/mock_keepalive:go_default_library",
"//go/beacon_srv/internal/onehop:go_default_library",
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/ctrl:go_default_library",
"//go/lib/ctrl/ifid:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions go/beacon_srv/internal/keepalive/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package keepalive

import (
"context"
"net"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/scionproto/scion/go/beacon_srv/internal/onehop"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/infra"
Expand All @@ -49,9 +49,9 @@ func TestSenderRun(t *testing.T) {
Sender: &onehop.Sender{
IA: xtest.MustParseIA("1-ff00:0:111"),
Conn: conn,
Addr: &addr.AppAddr{
L3: addr.HostFromIPStr("127.0.0.1"),
L4: 4242,
Addr: &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 4242,
},
MAC: mac,
},
Expand Down
6 changes: 3 additions & 3 deletions go/beacon_srv/internal/onehop/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Sender struct {
// IA is the ISD-AS of the local AS.
IA addr.IA
// Addr is the address that is set as the source.
Addr *addr.AppAddr
Addr *net.UDPAddr
// Conn is used to send the packets.
Conn snet.PacketConn
// macMtx protects the MAC.
Expand Down Expand Up @@ -90,12 +90,12 @@ func (s *Sender) CreatePkt(msg *Msg) (*snet.SCIONPacket, error) {
Destination: msg.Dst,
Source: snet.SCIONAddress{
IA: s.IA,
Host: s.Addr.L3,
Host: addr.HostFromIP(s.Addr.IP),
},
Path: (*spath.Path)(path),
Extensions: []common.Extension{&layers.ExtnOHP{}},
L4Header: &l4.UDP{
SrcPort: s.Addr.L4,
SrcPort: uint16(s.Addr.Port),
},
Payload: msg.Pld,
},
Expand Down
12 changes: 6 additions & 6 deletions go/beacon_srv/internal/onehop/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func TestSenderCreatePkt(t *testing.T) {
Convey("CreatePkt creates a correct packet", t, func() {
s := &Sender{
IA: xtest.MustParseIA("1-ff00:0:110"),
Addr: &addr.AppAddr{
L3: addr.HostFromIPStr("127.0.0.1"),
L4: 4242,
Addr: &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 4242,
},
MAC: createMac(t),
}
Expand All @@ -102,9 +102,9 @@ func TestSenderSend(t *testing.T) {
s := &Sender{
IA: xtest.MustParseIA("1-ff00:0:110"),
Conn: conn,
Addr: &addr.AppAddr{
L3: addr.HostFromIPStr("127.0.0.1"),
L4: 4242,
Addr: &net.UDPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 4242,
},
MAC: createMac(t),
}
Expand Down
18 changes: 12 additions & 6 deletions go/beacon_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"hash"
"net"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -294,20 +295,25 @@ func (t *periodicTasks) Start() error {
if topoAddress == nil {
return serrors.New("Unable to find topo address")
}
bs := &net.UDPAddr{
IP: topoAddress.L3.IP(),
Port: int(topoAddress.L4),
}

var err error
if t.registrars, err = t.startSegRegRunners(); err != nil {
return err
}
if t.revoker, err = t.startRevoker(); err != nil {
return err
}
if t.keepalive, err = t.startKeepaliveSender(topoAddress); err != nil {
if t.keepalive, err = t.startKeepaliveSender(bs); err != nil {
return err
}
if t.originator, err = t.startOriginator(topoAddress); err != nil {
if t.originator, err = t.startOriginator(bs); err != nil {
return err
}
if t.propagator, err = t.startPropagator(topoAddress); err != nil {
if t.propagator, err = t.startPropagator(bs); err != nil {
return err
}

Expand Down Expand Up @@ -341,7 +347,7 @@ func (t *periodicTasks) startRevoker() (*periodic.Runner, error) {
cfg.BS.ExpiredCheckInterval.Duration), nil
}

func (t *periodicTasks) startKeepaliveSender(a *addr.AppAddr) (*periodic.Runner, error) {
func (t *periodicTasks) startKeepaliveSender(a *net.UDPAddr) (*periodic.Runner, error) {
s := &keepalive.Sender{
Sender: &onehop.Sender{
Conn: t.conn,
Expand All @@ -356,7 +362,7 @@ func (t *periodicTasks) startKeepaliveSender(a *addr.AppAddr) (*periodic.Runner,
cfg.BS.KeepaliveInterval.Duration), nil
}

func (t *periodicTasks) startOriginator(a *addr.AppAddr) (*periodic.Runner, error) {
func (t *periodicTasks) startOriginator(a *net.UDPAddr) (*periodic.Runner, error) {
topo := t.topoProvider.Get()
if !topo.Core() {
return nil, nil
Expand Down Expand Up @@ -392,7 +398,7 @@ func (t *periodicTasks) startOriginator(a *addr.AppAddr) (*periodic.Runner, erro
cfg.BS.OriginationInterval.Duration), nil
}

func (t *periodicTasks) startPropagator(a *addr.AppAddr) (*periodic.Runner, error) {
func (t *periodicTasks) startPropagator(a *net.UDPAddr) (*periodic.Runner, error) {
topo := t.topoProvider.Get()
signer, err := t.createSigner(topo.IA())
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion go/examples/discovery_client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ go_library(
importpath = "github.com/scionproto/scion/go/examples/discovery_client",
visibility = ["//visibility:private"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/discovery:go_default_library",
"//go/lib/discovery/topofetcher:go_default_library",
Expand Down
32 changes: 13 additions & 19 deletions go/examples/discovery_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import (
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"strconv"
"sync"
"time"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/discovery"
"github.com/scionproto/scion/go/lib/discovery/topofetcher"
Expand All @@ -45,8 +44,6 @@ var (
timeout = flag.Duration("timeout", 2*time.Second, "Timeout for single request")
ds = flag.String("addr", "", "Discovery service to query for initial topology "+
"(form \"host:port\" or \"[host]:port\"")
// FIXME(roosd): Use AppAddr parsing once code base does no longer assume L4 is UDP.
dsAddr addr.AppAddr
)

func main() {
Expand Down Expand Up @@ -118,19 +115,8 @@ func validateFlags() error {
if *ds != "" && *topoPath != "" {
return serrors.New("Both topology and discovery service address specified")
}
if *ds != "" {
host, port, err := net.SplitHostPort(*ds)
if err != nil {
return common.NewBasicError("Unable to parse discovery service address", err)
}
if dsAddr.L3 = addr.HostFromIPStr(host); dsAddr.L3 == nil {
return common.NewBasicError("Unable to parse host", nil, "host", host)
}
p, err := strconv.Atoi(port)
if err != nil {
return common.NewBasicError("Unable to parse port", nil, "port", port)
}
dsAddr.L4 = uint16(p)
if _, err := url.Parse(*ds); err != nil {
return err
}
return nil
}
Expand All @@ -140,11 +126,19 @@ func getTopo() (*topology.Topo, error) {
log.Info("Fetch initial topology from discovery service", "addr", ds)
ctx, cancelF := context.WithTimeout(context.Background(), *timeout)
defer cancelF()
return discovery.FetchTopo(ctx, discovery.FetchParams{

a, err := net.ResolveUDPAddr("udp", *ds)
if err != nil {
return nil, err
}

ret, _, err := discovery.FetchTopoRaw(ctx, discovery.FetchParams{
File: file(),
Mode: mode(),
Https: *https,
}, &dsAddr, nil)
}, a,
nil)
return ret, err
}
log.Info("Load initial topology from disk", "topo", topoPath)
return topology.LoadFromFile(*topoPath)
Expand Down
1 change: 0 additions & 1 deletion go/lib/discovery/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ go_library(
importpath = "github.com/scionproto/scion/go/lib/discovery",
visibility = ["//visibility:public"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/periodic:go_default_library",
"//go/lib/serrors:go_default_library",
Expand Down
6 changes: 3 additions & 3 deletions go/lib/discovery/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package discovery

import (
"fmt"
"net"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/periodic"
"github.com/scionproto/scion/go/lib/topology"
)
Expand All @@ -35,11 +35,11 @@ type InstancePool interface {
type InstanceInfo interface {
fmt.Stringer
// Update updates the address.
Update(*addr.AppAddr)
Update(*net.UDPAddr)
// Key returns the key of the instance.
Key() string
// Addr returns the address of the instance.
Addr() *addr.AppAddr
Addr() *net.UDPAddr
// FailCount returns a number indicating how often
// the instance has failed.
FailCount() int
Expand Down
17 changes: 4 additions & 13 deletions go/lib/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"

"golang.org/x/net/context/ctxhttp"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/topology"
Expand Down Expand Up @@ -115,19 +115,10 @@ const (
Base = "discovery/v1"
)

// FetchTopo fetches the topology with the specified parameters from the
// discovery service. If client is nil, the default http client is used.
func FetchTopo(ctx context.Context, params FetchParams, ds *addr.AppAddr,
client *http.Client) (*topology.Topo, error) {

topo, _, err := FetchTopoRaw(ctx, params, ds, client)
return topo, err
}

// FetchTopoRaw fetches the topology with the specified parameters from the
// discovery service. If client is nil, the default http client is used.
// Both the topology and the raw response body are returned.
func FetchTopoRaw(ctx context.Context, params FetchParams, ds *addr.AppAddr,
func FetchTopoRaw(ctx context.Context, params FetchParams, ds *net.UDPAddr,
client *http.Client) (*topology.Topo, common.RawBytes, error) {

url, err := createURL(params, ds)
Expand All @@ -154,15 +145,15 @@ func FetchTopoRaw(ctx context.Context, params FetchParams, ds *addr.AppAddr,
}

// createURL builds the url to the topology file.
func createURL(params FetchParams, ds *addr.AppAddr) (string, error) {
func createURL(params FetchParams, ds *net.UDPAddr) (string, error) {
if ds == nil {
return "", serrors.New("Addr not set")
}
protocol := "http"
if params.Https {
protocol = "https"
}
return fmt.Sprintf("%s://%s:%d/%s", protocol, ds.L3.IP(), ds.L4,
return fmt.Sprintf("%s://%s:%d/%s", protocol, ds.IP, ds.Port,
Path(params.Mode, params.File)), nil
}

Expand Down
14 changes: 9 additions & 5 deletions go/lib/discovery/discoveryinfo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["info.go"],
importpath = "github.com/scionproto/scion/go/lib/discovery/discoveryinfo",
visibility = ["//visibility:public"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/discovery:go_default_library",
],
deps = ["//go/lib/discovery:go_default_library"],
)

go_test(
name = "go_default_test",
srcs = ["info_test.go"],
embed = [":go_default_library"],
deps = ["@com_github_stretchr_testify//assert:go_default_library"],
)
Loading

0 comments on commit f27ecfc

Please sign in to comment.