Skip to content

Commit

Permalink
SIG: Make the snet connection in ingress.Dispatcher mockable (#3659)
Browse files Browse the repository at this point in the history
  • Loading branch information
sustrik authored Feb 7, 2020
1 parent 08481a3 commit f80a268
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 10 additions & 1 deletion go/sig/internal/ingress/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@
package ingress

import (
"context"
"io"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/fatal"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/sig/internal/sigcmn"
)

func Init(tunIO io.ReadWriteCloser) {
fatal.Check()
d := NewDispatcher(tunIO)
conn, err := sigcmn.Network.Listen(context.Background(), "udp",
sigcmn.EncapSnetAddr().Host, addr.SvcNone)
if err != nil {
log.Crit("Unable to initialize ingress connection", err)
fatal.Fatal(err)
}
d := NewDispatcher(tunIO, conn)
go func() {
defer log.LogPanicAndExit()
if err := d.Run(); err != nil {
Expand Down
12 changes: 2 additions & 10 deletions go/sig/internal/ingress/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package ingress

import (
"context"
"fmt"
"io"
"time"
Expand All @@ -28,7 +27,6 @@ import (
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/sock/reliable"
"github.com/scionproto/scion/go/sig/internal/metrics"
"github.com/scionproto/scion/go/sig/internal/sigcmn"
"github.com/scionproto/scion/go/sig/mgmt"
)

Expand All @@ -43,28 +41,22 @@ 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.UDPAddr
workers map[string]*Worker
extConn snet.Conn
tunIO io.ReadWriteCloser
framesRecvCounters map[metrics.CtrPairKey]metrics.CtrPair
}

func NewDispatcher(tio io.ReadWriteCloser) *Dispatcher {
func NewDispatcher(tio io.ReadWriteCloser, conn snet.Conn) *Dispatcher {
return &Dispatcher{
tunIO: tio,
extConn: conn,
framesRecvCounters: make(map[metrics.CtrPairKey]metrics.CtrPair),
laddr: sigcmn.EncapSnetAddr(),
workers: make(map[string]*Worker),
}
}

func (d *Dispatcher) Run() error {
var err error
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)
}
return d.read()
}

Expand Down

0 comments on commit f80a268

Please sign in to comment.