Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snet: API function/type renaming #3690

Merged
merged 5 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/border/rctrl/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
)

var (
snetConn snet.Conn
snetConn *snet.Conn
ia addr.IA
logger log.Logger
)
Expand Down
4 changes: 2 additions & 2 deletions go/cs/beaconing/originator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestOriginatorRun(t *testing.T) {
msgsMtx.Lock()
defer msgsMtx.Unlock()
msgs = append(msgs, msg{
pkt: ipkt.(*snet.SCIONPacket),
pkt: ipkt.(*snet.Packet),
ov: iov.(*net.UDPAddr),
})
return nil
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestOriginatorRun(t *testing.T) {
}

type msg struct {
pkt *snet.SCIONPacket
pkt *snet.Packet
ov *net.UDPAddr
}

Expand Down
2 changes: 1 addition & 1 deletion go/cs/beaconing/propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestPropagatorRun(t *testing.T) {
msgsMtx.Lock()
defer msgsMtx.Unlock()
msgs = append(msgs, msg{
pkt: ipkt.(*snet.SCIONPacket),
pkt: ipkt.(*snet.Packet),
ov: iov.(*net.UDPAddr),
})
return nil
Expand Down
4 changes: 2 additions & 2 deletions go/cs/keepalive/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func TestSenderRun(t *testing.T) {
Signer: createTestSigner(t, priv),
TopoProvider: topoProvider,
}
pkts := make([]*snet.SCIONPacket, 0, len(topoProvider.Get().IFInfoMap()))
pkts := make([]*snet.Packet, 0, len(topoProvider.Get().IFInfoMap()))
conn.EXPECT().WriteTo(gomock.Any(), gomock.Any()).Times(cap(pkts)).DoAndReturn(
func(ipkts, _ interface{}) error {
pkts = append(pkts, ipkts.(*snet.SCIONPacket))
pkts = append(pkts, ipkts.(*snet.Packet))
return nil
},
)
Expand Down
6 changes: 3 additions & 3 deletions go/cs/onehop/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ type ohpPacketConn struct {
snet.PacketConn
}

func (c *ohpPacketConn) WriteTo(pkt *snet.SCIONPacket, ov *net.UDPAddr) error {
func (c *ohpPacketConn) WriteTo(pkt *snet.Packet, ov *net.UDPAddr) error {
return c.PacketConn.WriteTo(
&snet.SCIONPacket{
&snet.Packet{
Bytes: pkt.Bytes,
SCIONPacketInfo: snet.SCIONPacketInfo{
PacketInfo: snet.PacketInfo{
Destination: pkt.Destination,
Source: pkt.Source,
Path: pkt.Path,
Expand Down
6 changes: 3 additions & 3 deletions go/cs/onehop/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func (s *Sender) Send(msg *Msg, nextHop *net.UDPAddr) error {
}

// CreatePkt creates a scion packet with a one-hop path and the payload.
func (s *Sender) CreatePkt(msg *Msg) (*snet.SCIONPacket, error) {
func (s *Sender) CreatePkt(msg *Msg) (*snet.Packet, error) {
path, err := s.CreatePath(msg.Ifid, msg.InfoTime)
if err != nil {
return nil, err
}
pkt := &snet.SCIONPacket{
SCIONPacketInfo: snet.SCIONPacketInfo{
pkt := &snet.Packet{
PacketInfo: snet.PacketInfo{
Destination: msg.Dst,
Source: snet.SCIONAddress{
IA: s.IA,
Expand Down
6 changes: 3 additions & 3 deletions go/cs/onehop/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ func TestSenderSend(t *testing.T) {
}
// Read from connection to unblock sender.
ov := &net.UDPAddr{IP: net.IP{127, 0, 0, 42}, Port: 1337}
var pkt *snet.SCIONPacket
var pkt *snet.Packet
conn.EXPECT().WriteTo(gomock.Any(), ov).DoAndReturn(
func(ipkt, _ interface{}) error {
pkt = ipkt.(*snet.SCIONPacket)
pkt = ipkt.(*snet.Packet)
return nil
},
)
Expand All @@ -136,7 +136,7 @@ func testPacket() *Msg {
}
}

func checkTestPkt(t *testing.T, s *Sender, msg *Msg, pkt *snet.SCIONPacket) {
func checkTestPkt(t *testing.T, s *Sender, msg *Msg, pkt *snet.Packet) {

SoMsg("dst", pkt.Destination, ShouldResemble, msg.Dst)
SoMsg("src", pkt.Source, ShouldResemble, snet.SCIONAddress{
Expand Down
2 changes: 1 addition & 1 deletion go/integration/cert_req/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func addFlags() {
}

type client struct {
conn snet.Conn
conn *snet.Conn
msgr infra.Messenger
}

Expand Down
8 changes: 4 additions & 4 deletions go/integration/end2end/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s server) run() {
log.Debug("Listening", "local", fmt.Sprintf("%v:%d", integration.Local.Host, port))
// Receive ping message
for {
var p snet.SCIONPacket
var p snet.Packet
var ov net.UDPAddr
if err := conn.ReadFrom(&p, &ov); err != nil {
log.Error("Error reading packet", "err", err)
Expand Down Expand Up @@ -210,8 +210,8 @@ func (c client) ping(ctx context.Context, n int) error {
// API guarantees return values are ok
_, _ = rand.Read(debugID[:])
return c.conn.WriteTo(
&snet.SCIONPacket{
SCIONPacketInfo: snet.SCIONPacketInfo{
&snet.Packet{
PacketInfo: snet.PacketInfo{
Destination: snet.SCIONAddress{
IA: remote.IA,
Host: addr.HostFromIP(remote.Host.IP),
Expand Down Expand Up @@ -261,7 +261,7 @@ func (c client) getRemote(ctx context.Context, n int) error {

func (c client) pong(ctx context.Context) error {
c.conn.SetReadDeadline(getDeadline(ctx))
var p snet.SCIONPacket
var p snet.Packet
var ov net.UDPAddr
if err := c.conn.ReadFrom(&p, &ov); err != nil {
return common.NewBasicError("Error reading packet", err)
Expand Down
2 changes: 1 addition & 1 deletion go/lib/infra/infraenv/infraenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func InitInfraEnvironmentFunc(topologyPath string, f func()) {
// inform local SCION state (CS informing the local SD).
type ignoreSCMP struct{}

func (ignoreSCMP) Handle(pkt *snet.SCIONPacket) error {
func (ignoreSCMP) Handle(pkt *snet.Packet) error {
// Always reattempt reads from the socket.
return nil
}
2 changes: 1 addition & 1 deletion go/lib/pktdisp/disp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type DispatchFunc func(*DispPkt)
// PktDispatcher listens on c, and calls f for every packet read.
// N.B. the DispPkt passed to f is reused, so applications should make a copy if
// this is a problem.
func PktDispatcher(c snet.Conn, f DispatchFunc, pktDispStop chan struct{}) {
func PktDispatcher(c *snet.Conn, f DispatchFunc, pktDispStop chan struct{}) {
fatal.Check()
var err error
var n int
Expand Down
8 changes: 4 additions & 4 deletions go/lib/sciond/pathprobe/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (p Prober) GetStatuses(ctx context.Context,
return scmpH.statuses, nil
}

func (p Prober) send(scionConn snet.Conn, path snet.Path) error {
func (p Prober) send(scionConn *snet.Conn, path snet.Path) error {
addr := &snet.SVCAddr{
IA: p.DstIA,
Path: path.Path(),
Expand All @@ -157,7 +157,7 @@ func (p Prober) send(scionConn snet.Conn, path snet.Path) error {
return nil
}

func (p Prober) receive(scionConn snet.Conn) error {
func (p Prober) receive(scionConn *snet.Conn) error {
b := make([]byte, 1500, 1500)
_, _, err := scionConn.ReadFrom(b)
if err == nil {
Expand All @@ -182,7 +182,7 @@ type scmpHandler struct {
statuses map[string]Status
}

func (h *scmpHandler) Handle(pkt *snet.SCIONPacket) error {
func (h *scmpHandler) Handle(pkt *snet.Packet) error {
hdr, ok := pkt.L4Header.(*scmp.Hdr)
if ok {
path, err := h.path(pkt)
Expand All @@ -199,7 +199,7 @@ func (h *scmpHandler) Handle(pkt *snet.SCIONPacket) error {
return nil
}

func (h *scmpHandler) path(pkt *snet.SCIONPacket) (string, error) {
func (h *scmpHandler) path(pkt *snet.Packet) (string, error) {
path := pkt.Path.Copy()
if err := path.Reverse(); err != nil {
return "", common.NewBasicError("unable to reverse path on received packet", err)
Expand Down
2 changes: 1 addition & 1 deletion go/lib/sigdisp/disp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/scionproto/scion/go/lib/snet"
)

func Init(conn snet.Conn, useid bool) {
func Init(conn *snet.Conn, useid bool) {
useID = useid
go func() {
defer log.HandlePanic()
Expand Down
15 changes: 7 additions & 8 deletions go/lib/snet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@ func (e *OpError) Error() string {
return e.scmp.String()
}

var _ net.Conn = (*SCIONConn)(nil)
var _ net.PacketConn = (*SCIONConn)(nil)
var _ Conn = (*SCIONConn)(nil)
var _ net.Conn = (*Conn)(nil)
var _ net.PacketConn = (*Conn)(nil)

type SCIONConn struct {
type Conn struct {
conn PacketConn
scionConnBase
scionConnWriter
scionConnReader
}

func newSCIONConn(base *scionConnBase, querier PathQuerier, conn PacketConn) *SCIONConn {
c := &SCIONConn{
func newConn(base *scionConnBase, querier PathQuerier, conn PacketConn) *Conn {
c := &Conn{
conn: conn,
scionConnBase: *base,
}
Expand All @@ -73,7 +72,7 @@ func newSCIONConn(base *scionConnBase, querier PathQuerier, conn PacketConn) *SC
return c
}

func (c *SCIONConn) SetDeadline(t time.Time) error {
func (c *Conn) SetDeadline(t time.Time) error {
if err := c.scionConnReader.SetReadDeadline(t); err != nil {
return err
}
Expand All @@ -83,6 +82,6 @@ func (c *SCIONConn) SetDeadline(t time.Time) error {
return nil
}

func (c *SCIONConn) Close() error {
func (c *Conn) Close() error {
return c.conn.Close()
}
6 changes: 3 additions & 3 deletions go/lib/snet/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type SCMPHandler interface {
//
// If the handler mutates the packet, the changes are seen by snet
// connection method callers.
Handle(pkt *SCIONPacket) error
Handle(pkt *Packet) error
}

// NewSCMPHandler creates a default SCMP handler that forwards revocations to the revocation
Expand All @@ -98,7 +98,7 @@ type scmpHandler struct {
revocationHandler RevocationHandler
}

func (h *scmpHandler) Handle(pkt *SCIONPacket) error {
func (h *scmpHandler) Handle(pkt *Packet) error {
hdr, ok := pkt.L4Header.(*scmp.Hdr)
if !ok {
return common.NewBasicError("scmp handler invoked with non-scmp packet", nil, "pkt", pkt)
Expand All @@ -119,7 +119,7 @@ func (h *scmpHandler) Handle(pkt *SCIONPacket) error {
return nil
}

func (h *scmpHandler) handleSCMPRev(hdr *scmp.Hdr, pkt *SCIONPacket) error {
func (h *scmpHandler) handleSCMPRev(hdr *scmp.Hdr, pkt *Packet) error {
scmpPayload, ok := pkt.Payload.(*scmp.Payload)
if !ok {
return common.NewBasicError("Unable to type assert payload to SCMP payload", nil,
Expand Down
24 changes: 3 additions & 21 deletions go/lib/snet/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,13 @@ package snet
import (
"context"
"net"
"time"

"github.com/scionproto/scion/go/lib/addr"
)

type Network interface {
Listen(ctx context.Context, network string, listen *net.UDPAddr, svc addr.HostSVC) (Conn, error)
Listen(ctx context.Context, network string, listen *net.UDPAddr,
svc addr.HostSVC) (*Conn, error)
Dial(ctx context.Context, network string, listen *net.UDPAddr, remote *UDPAddr,
svc addr.HostSVC) (Conn, error)
}

// Conn represents a SCION connection.
type Conn interface {
Read(b []byte) (int, error)
ReadFrom(b []byte) (int, net.Addr, error)
Write(b []byte) (int, error)
WriteTo(b []byte, address net.Addr) (int, error)
Close() error
LocalAddr() net.Addr
SVC() addr.HostSVC
// RemoteAddr returns the remote network address.
RemoteAddr() net.Addr
// SetDeadline sets read and write deadlines. Implements the net.Conn
// SetDeadline method.
SetDeadline(deadline time.Time) error
SetReadDeadline(deadline time.Time) error
SetWriteDeadline(deadline time.Time) error
svc addr.HostSVC) (*Conn, error)
}
12 changes: 6 additions & 6 deletions go/lib/snet/mock_snet/snet.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading