Repository: scionproto/scion
Pull request #3578 (2020-01-06 15:57:41)

Remove AppAddr from SIG code


<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/scionproto/scion/3578)
<!-- Reviewable:end -->



Patch:
diff --git a/go/sig/egress/session/sessmon.go b/go/sig/egress/session/sessmon.go
index 9659f53e5..8b81a0892 100644
--- a/go/sig/egress/session/sessmon.go
+++ b/go/sig/egress/session/sessmon.go
@@ -277,13 +277,14 @@ func (sm *sessMonitor) sendReq() {
 		sm.Error("sessMonitor: Error packing signed Ctrl payload", "err", err)
 		return
 	}
-	raddr := sm.smRemote.Sig.CtrlSnetAddr()
-	raddr.Path = sm.smRemote.SessPath.Path().Path()
-	raddr.NextHop = sm.smRemote.SessPath.Path().OverlayNextHop()
+	raddr := sm.smRemote.Sig.CtrlSnetAddr(
+		sm.smRemote.SessPath.Path().Path(),
+		sm.smRemote.SessPath.Path().OverlayNextHop(),
+	)
 	// XXX(kormat): if this blocks, both the sessMon and egress worker
 	// goroutines will block. Can't just use SetWriteDeadline, as both
 	// goroutines write to it.
-	_, err = sm.sess.conn.WriteToSCION(raw, raddr)
+	_, err = sm.sess.conn.WriteTo(raw, raddr)
 	if err != nil {
 		sm.Error("sessMonitor: Error sending signed Ctrl payload", "err", err)
 	}
diff --git a/go/sig/egress/siginfo/BUILD.bazel b/go/sig/egress/siginfo/BUILD.bazel
index 19f9af66c..46809b113 100644
--- a/go/sig/egress/siginfo/BUILD.bazel
+++ b/go/sig/egress/siginfo/BUILD.bazel
@@ -8,5 +8,6 @@ go_library(
     deps = [
         "//go/lib/addr:go_default_library",
         "//go/lib/snet:go_default_library",
+        "//go/lib/spath:go_default_library",
     ],
 )
diff --git a/go/sig/egress/siginfo/sig.go b/go/sig/egress/siginfo/sig.go
index 38bc75afd..ad8256307 100644
--- a/go/sig/egress/siginfo/sig.go
+++ b/go/sig/egress/siginfo/sig.go
@@ -17,9 +17,11 @@ package siginfo
 
 import (
 	"fmt"
+	"net"
 
 	"github.com/scionproto/scion/go/lib/addr"
 	"github.com/scionproto/scion/go/lib/snet"
+	"github.com/scionproto/scion/go/lib/spath"
 )
 
 type Sig struct {
@@ -29,12 +31,38 @@ type Sig struct {
 	EncapL4Port int
 }
 
-func (s *Sig) CtrlSnetAddr() *snet.Addr {
-	return &snet.Addr{IA: s.IA, Host: &addr.AppAddr{L3: s.Host, L4: uint16(s.CtrlL4Port)}}
+func (s *Sig) CtrlSnetAddr(path *spath.Path, nextHop *net.UDPAddr) net.Addr {
+	switch s.Host.(type) {
+	case addr.HostSVC:
+		return snet.NewSVCAddr(
+			s.IA,
+			path,
+			nextHop,
+			addr.SvcSIG,
+		)
+	default:
+		return snet.NewUDPAddr(
+			s.IA,
+			path,
+			nextHop,
+			&net.UDPAddr{
+				IP:   s.Host.IP(),
+				Port: s.CtrlL4Port,
+			},
+		)
+	}
 }
 
-func (s *Sig) EncapSnetAddr() *snet.Addr {
-	return &snet.Addr{IA: s.IA, Host: &addr.AppAddr{L3: s.Host, L4: uint16(s.EncapL4Port)}}
+func (s *Sig) EncapSnetAddr() *snet.UDPAddr {
+	return snet.NewUDPAddr(
+		s.IA,
+		nil,
+		nil,
+		&net.UDPAddr{
+			IP:   s.Host.IP(),
+			Port: s.EncapL4Port,
+		},
+	)
 }
 
 func (s *Sig) Equal(x *Sig) bool {
diff --git a/go/sig/egress/worker/mock_worker/BUILD.bazel b/go/sig/egress/worker/mock_worker/BUILD.bazel
index fe9e5c7ea..004cab5f8 100644
--- a/go/sig/egress/worker/mock_worker/BUILD.bazel
+++ b/go/sig/egress/worker/mock_worker/BUILD.bazel
@@ -5,8 +5,5 @@ go_library(
     srcs = ["worker.go"],
     importpath = "github.com/scionproto/scion/go/sig/egress/worker/mock_worker",
     visibility = ["//visibility:public"],
-    deps = [
-        "//go/lib/snet:go_default_library",
-        "@com_github_golang_mock//gomock:go_default_library",
-    ],
+    deps = ["@com_github_golang_mock//gomock:go_default_library"],
 )
diff --git a/go/sig/egress/worker/mock_worker/worker.go b/go/sig/egress/worker/mock_worker/worker.go
index a4a8feb2f..d0d5b8cec 100644
--- a/go/sig/egress/worker/mock_worker/worker.go
+++ b/go/sig/egress/worker/mock_worker/worker.go
@@ -6,7 +6,7 @@ package mock_worker
 
 import (
 	gomock "github.com/golang/mock/gomock"
-	snet "github.com/scionproto/scion/go/lib/snet"
+	net "net"
 	reflect "reflect"
 )
 
@@ -33,17 +33,17 @@ func (m *MockSCIONWriter) EXPECT() *MockSCIONWriterMockRecorder {
 	return m.recorder
 }
 
-// WriteToSCION mocks base method
-func (m *MockSCIONWriter) WriteToSCION(arg0 []byte, arg1 *snet.Addr) (int, error) {
+// WriteTo mocks base method
+func (m *MockSCIONWriter) WriteTo(arg0 []byte, arg1 net.Addr) (int, error) {
 	m.ctrl.T.Helper()
-	ret := m.ctrl.Call(m, "WriteToSCION", arg0, arg1)
+	ret := m.ctrl.Call(m, "WriteTo", arg0, arg1)
 	ret0, _ := ret[0].(int)
 	ret1, _ := ret[1].(error)
 	return ret0, ret1
 }
 
-// WriteToSCION indicates an expected call of WriteToSCION
-func (mr *MockSCIONWriterMockRecorder) WriteToSCION(arg0, arg1 interface{}) *gomock.Call {
+// WriteTo indicates an expected call of WriteTo
+func (mr *MockSCIONWriterMockRecorder) WriteTo(arg0, arg1 interface{}) *gomock.Call {
 	mr.mock.ctrl.T.Helper()
-	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteToSCION", reflect.TypeOf((*MockSCIONWriter)(nil).WriteToSCION), arg0, arg1)
+	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteTo", reflect.TypeOf((*MockSCIONWriter)(nil).WriteTo), arg0, arg1)
 }
diff --git a/go/sig/egress/worker/worker.go b/go/sig/egress/worker/worker.go
index 4fbd99a1c..2077c565a 100644
--- a/go/sig/egress/worker/worker.go
+++ b/go/sig/egress/worker/worker.go
@@ -17,6 +17,7 @@
 package worker
 
 import (
+	"net"
 	"time"
 
 	"github.com/scionproto/scion/go/lib/common"
@@ -56,7 +57,7 @@ const (
 )
 
 type SCIONWriter interface {
-	WriteToSCION(b []byte, address *snet.Addr) (int, error)
+	WriteTo(b []byte, address net.Addr) (int, error)
 }
 
 type worker struct {
@@ -187,7 +188,7 @@ func (w *worker) write(f *frame) error {
 		w.seq = 0
 	}
 
-	var snetAddr *snet.Addr
+	var snetAddr *snet.UDPAddr
 	if !w.ignoreAddress {
 		if w.currPathEntry == nil {
 			// FIXME(kormat): add some metrics to track this.
@@ -203,7 +204,7 @@ func (w *worker) write(f *frame) error {
 	}
 
 	f.writeHdr(w.sess.ID(), w.epoch, seq)
-	bytesWritten, err := w.writer.WriteToSCION(f.raw(), snetAddr)
+	bytesWritten, err := w.writer.WriteTo(f.raw(), snetAddr)
 	if err != nil {
 		return common.NewBasicError("Egress write error", err)
 	}
diff --git a/go/sig/internal/base/pollhdlr.go b/go/sig/internal/base/pollhdlr.go
index 82cbc5006..59cc44d4e 100644
--- a/go/sig/internal/base/pollhdlr.go
+++ b/go/sig/internal/base/pollhdlr.go
@@ -16,7 +16,6 @@
 package base
 
 import (
-	"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"
@@ -58,13 +57,13 @@ func PollReqHdlr() {
 			log.Error("PollReqHdlr: Error packing signed Ctrl payload", "err", err)
 			break
 		}
-		sigCtrlAddr := &snet.Addr{
-			IA:      rpld.Addr.IA,
-			Host:    addr.AppAddrFromUDP(req.Addr.Ctrl.UDP()),
-			Path:    rpld.Addr.Path,
-			NextHop: snet.CopyUDPAddr(rpld.Addr.NextHop),
-		}
-		_, err = sigcmn.CtrlConn.WriteToSCION(raw, sigCtrlAddr)
+		sigCtrlAddr := snet.NewUDPAddr(
+			rpld.Addr.IA,
+			rpld.Addr.Path,
+			snet.CopyUDPAddr(rpld.Addr.NextHop),
+			req.Addr.Ctrl.UDP(),
+		)
+		_, err = sigcmn.CtrlConn.WriteTo(raw, sigCtrlAddr)
 		if err != nil {
 			log.Error("PollReqHdlr: Error sending Ctrl payload", "dest", rpld.Addr, "err", err)
 		}
diff --git a/go/sig/internal/ingress/dispatcher.go b/go/sig/internal/ingress/dispatcher.go
index 2c93d2dc5..a41af3796 100644
--- a/go/sig/internal/ingress/dispatcher.go
+++ b/go/sig/internal/ingress/dispatcher.go
@@ -43,7 +43,7 @@ const (
 // source ISD-AS -> source host Addr -> Sess Id and hands it off to the
 // appropriate Worker, starting a new one if none currently exists.
 type Dispatcher struct {
-	laddr              *snet.Addr
+	laddr              *snet.UDPAddr
 	workers            map[string]*Worker
 	extConn            snet.Conn
 	tunIO              io.ReadWriteCloser
@@ -61,8 +61,7 @@ func NewDispatcher(tio io.ReadWriteCloser) *Dispatcher {
 
 func (d *Dispatcher) Run() error {
 	var err error
-	d.extConn, err = sigcmn.Network.Listen(context.Background(), "udp",
-		d.laddr.ToNetUDPAddr(), addr.SvcNone)
+	d.extConn, err = sigcmn.Network.Listen(context.Background(), "udp", d.laddr.Host, addr.SvcNone)
 	if err != nil {
 		return common.NewBasicError("Unable to initialize extConn", err)
 	}
diff --git a/go/sig/internal/sigcmn/common.go b/go/sig/internal/sigcmn/common.go
index 3782f5520..7425df412 100644
--- a/go/sig/internal/sigcmn/common.go
+++ b/go/sig/internal/sigcmn/common.go
@@ -125,8 +125,8 @@ func initNetworkWithRealSCIOND(cfg sigconfig.SigConf,
 	return nil, nil, retErr
 }
 
-func EncapSnetAddr() *snet.Addr {
-	return &snet.Addr{IA: IA, Host: &addr.AppAddr{L3: Host, L4: uint16(encapPort)}}
+func EncapSnetAddr() *snet.UDPAddr {
+	return snet.NewUDPAddr(IA, nil, nil, &net.UDPAddr{IP: Host.IP(), Port: int(encapPort)})
 }
 
 func ValidatePort(desc string, port int) error {


Test patch:
diff --git a/go/sig/egress/worker/worker_test.go b/go/sig/egress/worker/worker_test.go
index eddba3217..70b3416c4 100644
--- a/go/sig/egress/worker/worker_test.go
+++ b/go/sig/egress/worker/worker_test.go
@@ -83,12 +83,12 @@ func NewWorkerTester(t *testing.T) *WorkerTester {
 }
 
 func (wt *WorkerTester) ExpectFrame(frame []byte) {
-	wt.writer.EXPECT().WriteToSCION(MatchFrame(frame), gomock.Any()).Return(len(frame), nil)
+	wt.writer.EXPECT().WriteTo(MatchFrame(frame), gomock.Any()).Return(len(frame), nil)
 }
 
 func (wt *WorkerTester) ExpectLastFrame(frame []byte) {
-	wt.writer.EXPECT().WriteToSCION(MatchFrame(frame), gomock.Any()).DoAndReturn(
-		func(frame []byte, address *snet.Addr) (int, error) {
+	wt.writer.EXPECT().WriteTo(MatchFrame(frame), gomock.Any()).DoAndReturn(
+		func(frame []byte, address *snet.UDPAddr) (int, error) {
 			wt.ring.Close()
 			return len(frame), nil
 		})