Skip to content

Commit

Permalink
Do not use appaddr in cert_integration (#3553)
Browse files Browse the repository at this point in the history
* Do not use appaddr in cert_integration

* Remove appaddr from integration
  • Loading branch information
karampok authored Jan 6, 2020
1 parent 0d79331 commit a4d6258
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions go/acceptance/sigcmn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var (
IAIPMap = make(map[addr.IA]addr.HostIPv4)
)

var SigAddr integration.HostAddr = func(ia addr.IA) snet.Addr {
return snet.Addr{Host: &addr.AppAddr{L3: IAIPMap[ia]}, IA: ia}
var SigAddr integration.HostAddr = func(ia addr.IA) *snet.UDPAddr {
return snet.NewUDPAddr(ia, nil, nil, &net.UDPAddr{IP: net.IP(IAIPMap[ia])})
}

func ReadTestingConf() error {
Expand Down
8 changes: 4 additions & 4 deletions go/integration/cert_req/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

var (
remoteIA addr.IA
svc snet.Addr
svc net.Addr
)

func main() {
Expand Down Expand Up @@ -131,7 +131,7 @@ func (c client) requestCert(parentCtx context.Context) (*cert.Chain, error) {
logger.Info("Request to SVC: Chain request", "req", req, "svc", svc)
ctx, cancelF := context.WithTimeout(parentCtx, integration.DefaultIOTimeout)
defer cancelF()
rawChain, err := c.msgr.GetCertChain(ctx, req, &svc, messenger.NextId())
rawChain, err := c.msgr.GetCertChain(ctx, req, svc, messenger.NextId())
if err != nil {
return nil, common.NewBasicError("Unable to get chain", err)
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (c client) requestTRC(parentCtx context.Context, chain *cert.Chain) error {
logger.Info("Request to SVC: TRC request", "req", req, "svc", svc)
ctx, cancelF := context.WithTimeout(parentCtx, integration.DefaultIOTimeout)
defer cancelF()
rawTrc, err := c.msgr.GetTRC(ctx, req, &svc, messenger.NextId())
rawTrc, err := c.msgr.GetTRC(ctx, req, svc, messenger.NextId())
if err != nil {
return common.NewBasicError("Unable to get trc", err)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func getRemote() error {
if svcHost, err = getSVCAddress(); err != nil {
return err
}
svc = snet.Addr{IA: integration.Local.IA, Host: addr.AppAddrFromUDP(svcHost)}
svc = snet.NewUDPAddr(integration.Local.IA, nil, nil, svcHost)
return nil
}

Expand Down
13 changes: 7 additions & 6 deletions go/lib/integration/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (bi *binaryIntegration) Name() string {
}

// StartServer starts a server and blocks until the ReadySignal is received on Stdout.
func (bi *binaryIntegration) StartServer(ctx context.Context, dst snet.Addr) (Waiter, error) {
func (bi *binaryIntegration) StartServer(ctx context.Context, dst *snet.UDPAddr) (Waiter, error) {
args := replacePattern(DstIAReplace, dst.IA.String(), bi.serverArgs)
args = replacePattern(DstHostReplace, dst.Host.L3.String(), args)
args = replacePattern(DstHostReplace, dst.Host.IP.String(), args)
r := &binaryWaiter{
exec.CommandContext(ctx, bi.cmd, args...),
}
Expand Down Expand Up @@ -151,11 +151,12 @@ func (bi *binaryIntegration) StartServer(ctx context.Context, dst snet.Addr) (Wa
}
}

func (bi *binaryIntegration) StartClient(ctx context.Context, src, dst snet.Addr) (Waiter, error) {
func (bi *binaryIntegration) StartClient(ctx context.Context,
src, dst *snet.UDPAddr) (Waiter, error) {
args := replacePattern(SrcIAReplace, src.IA.String(), bi.clientArgs)
args = replacePattern(SrcHostReplace, src.Host.L3.String(), args)
args = replacePattern(SrcHostReplace, src.Host.IP.String(), args)
args = replacePattern(DstIAReplace, dst.IA.String(), args)
args = replacePattern(DstHostReplace, dst.Host.L3.String(), args)
args = replacePattern(DstHostReplace, dst.Host.IP.String(), args)
args = replacePattern(ServerPortReplace, serverPorts[dst.IA], args)
r := &binaryWaiter{
exec.CommandContext(ctx, bi.cmd, args...),
Expand Down Expand Up @@ -212,7 +213,7 @@ func (bi *binaryIntegration) writeLog(name, id, startInfo string, ep io.ReadClos
}
}

func clientId(src, dst snet.Addr) string {
func clientId(src, dst *snet.UDPAddr) string {
return fmt.Sprintf("%s_%s", src.IA.FileFmt(false), dst.IA.FileFmt(false))
}

Expand Down
5 changes: 3 additions & 2 deletions go/lib/integration/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func dockerize(bi *binaryIntegration) Integration {
}

// StartServer starts a server and blocks until the ReadySignal is received on Stdout.
func (di *dockerIntegration) StartServer(ctx context.Context, dst snet.Addr) (Waiter, error) {
func (di *dockerIntegration) StartServer(ctx context.Context, dst *snet.UDPAddr) (Waiter, error) {
bi := *di.binaryIntegration
env := fmt.Sprintf("%s=1", GoIntegrationEnv)
bi.serverArgs = append([]string{dockerArg, dst.IA.FileFmt(false), env, bi.cmd},
Expand All @@ -59,7 +59,8 @@ func (di *dockerIntegration) StartServer(ctx context.Context, dst snet.Addr) (Wa
return bi.StartServer(ctx, dst)
}

func (di *dockerIntegration) StartClient(ctx context.Context, src, dst snet.Addr) (Waiter, error) {
func (di *dockerIntegration) StartClient(ctx context.Context,
src, dst *snet.UDPAddr) (Waiter, error) {
bi := *di.binaryIntegration
bi.clientArgs = append([]string{dockerArg, src.IA.FileFmt(false), bi.cmd}, bi.clientArgs...)
bi.cmd = dockerCmd
Expand Down
27 changes: 13 additions & 14 deletions go/lib/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ type Integration interface {
// StartServer should start the server listening on the address dst.
// StartServer should return after it is ready to accept clients.
// The context should be used to make the server cancellable.
StartServer(ctx context.Context, dst snet.Addr) (Waiter, error)
StartServer(ctx context.Context, dst *snet.UDPAddr) (Waiter, error)
// StartClient should start the client on the src address connecting to the dst address.
// StartClient should return immediately.
// The context should be used to make the client cancellable.
StartClient(ctx context.Context, src, dst snet.Addr) (Waiter, error)
StartClient(ctx context.Context, src, dst *snet.UDPAddr) (Waiter, error)
}

// Waiter is a descriptor of a process running in the integration test.
Expand Down Expand Up @@ -132,8 +132,7 @@ func validateFlags(name string) error {

// IAPair is a source, destination pair. The client (Src) will dial the server (Dst).
type IAPair struct {
Src snet.Addr
Dst snet.Addr
Src, Dst *snet.UDPAddr
}

// IAPairs returns all IAPairs that should be tested.
Expand All @@ -146,12 +145,12 @@ func UniqueIAPairs(hostAddr HostAddr) []IAPair {
return generateAllSrcDst(hostAddr, true)
}

func generateSrcDst(hostAddr HostAddr) ([]snet.Addr, []snet.Addr) {
srcASes := make([]snet.Addr, 0, len(srcIAs))
func generateSrcDst(hostAddr HostAddr) ([]*snet.UDPAddr, []*snet.UDPAddr) {
srcASes := make([]*snet.UDPAddr, 0, len(srcIAs))
for _, src := range srcIAs {
srcASes = append(srcASes, hostAddr(src))
}
dstASes := make([]snet.Addr, 0, len(dstIAs))
dstASes := make([]*snet.UDPAddr, 0, len(dstIAs))
for _, dst := range dstIAs {
dstASes = append(dstASes, hostAddr(dst))
}
Expand Down Expand Up @@ -179,22 +178,22 @@ func generateAllSrcDst(hostAddr HostAddr, unique bool) []IAPair {
return pairs
}

type HostAddr func(ia addr.IA) snet.Addr
type HostAddr func(ia addr.IA) *snet.UDPAddr

// DispAddr reads the BS host Addr from the topology for the specified IA. In general this
// could be the IP of any service (PS/BS/CS) in that IA because they share the same dispatcher in
// the dockerized topology.
// The host IP is used as client or server address in the tests because the testing container is
// connecting to the dispatcher of the services.
var DispAddr HostAddr = func(ia addr.IA) snet.Addr {
var DispAddr HostAddr = func(ia addr.IA) *snet.UDPAddr {
path := fmt.Sprintf("gen/ISD%d/AS%s/endhost/topology.json", ia.I, ia.A.FileFmt())
topo, err := topology.RWTopologyFromJSONFile(path)
if err != nil {
log.Error("Error loading topology", "err", err)
os.Exit(1)
}
bs := topo.BS["bs"+ia.FileFmt(false)+"-1"]
return snet.Addr{Host: addr.AppAddrFromUDP(bs.SCIONAddress), IA: ia}
return snet.NewUDPAddr(ia, nil, nil, bs.SCIONAddress)
}

// interface kept similar to go 1.10
Expand Down Expand Up @@ -224,7 +223,7 @@ func WithTimestamp(s string) string {

// StartServer runs a server. The server can be stopped by calling Close() on the returned Closer.
// To start a server with a custom context use in.StartServer directly.
func StartServer(in Integration, dst snet.Addr) (io.Closer, error) {
func StartServer(in Integration, dst *snet.UDPAddr) (io.Closer, error) {
serverCtx, serverCancel := context.WithCancel(context.Background())
s, err := in.StartServer(serverCtx, dst)
if err != nil {
Expand Down Expand Up @@ -265,9 +264,9 @@ func ExecuteTimed(name string, f func() error) error {
}

// ExtractUniqueDsts returns all unique destinations in pairs.
func ExtractUniqueDsts(pairs []IAPair) []snet.Addr {
uniqueDsts := make(map[snet.Addr]bool)
var res []snet.Addr
func ExtractUniqueDsts(pairs []IAPair) []*snet.UDPAddr {
uniqueDsts := make(map[*snet.UDPAddr]bool)
var res []*snet.UDPAddr
for _, pair := range pairs {
if !uniqueDsts[pair.Dst] {
res = append(res, pair.Dst)
Expand Down

0 comments on commit a4d6258

Please sign in to comment.