Skip to content

Commit 4e358c4

Browse files
skip: update proxy to the last version of the extension (#242)
* Add first tries to collect path statistics in skip * fix bug broken SingleStream: - We cast quic.session to *pan.QUICSession on the dialing side so that applications as the scion-skip can extract path information from the quic stream. This is not needed or intended, at the moment, for the listening side, which breaks down if do not pass a *pan.QUICSession object. * updating path usage info * treat nil * lint * pass * lint * lint * pass --------- Co-authored-by: Marten Gartner <[email protected]>
1 parent a14810b commit 4e358c4

File tree

4 files changed

+280
-25
lines changed

4 files changed

+280
-25
lines changed

pkg/pan/policy.go

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func (s Sequence) Filter(paths []*Path) []*Path {
118118
return ps
119119
}
120120

121+
func (s Sequence) String() string {
122+
return s.sequence.String()
123+
}
124+
121125
// ACL is a policy filtering paths matching an ACL pattern. The ACL pattern is
122126
// an ordered list of allow/deny actions over hop predicates.
123127
// See https://scion.docs.anapaya.net/en/latest/PathPolicy.html#acl.

pkg/pan/udp_dial.go

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type Conn interface {
3333
// ReadVia reads a message and returns the (return-)path via which the
3434
// message was received.
3535
ReadVia(b []byte) (int, *Path, error)
36+
37+
GetPath() *Path
3638
}
3739

3840
// DialUDP opens a SCION/UDP socket, connected to the remote address.
@@ -96,6 +98,10 @@ func (c *dialedConn) LocalAddr() net.Addr {
9698
return c.local
9799
}
98100

101+
func (c *dialedConn) GetPath() *Path {
102+
return c.selector.Path()
103+
}
104+
99105
func (c *dialedConn) RemoteAddr() net.Addr {
100106
return c.remote
101107
}

pkg/quicutil/single.go

+32-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"time"
2424

2525
"github.com/quic-go/quic-go"
26+
27+
"github.com/netsec-ethz/scion-apps/pkg/pan"
2628
)
2729

2830
var (
@@ -54,48 +56,63 @@ type SingleStreamListener struct {
5456

5557
func (l SingleStreamListener) Accept() (net.Conn, error) {
5658
ctx := context.Background()
57-
session, err := l.Listener.Accept(ctx)
59+
connection, err := l.Listener.Accept(ctx)
5860
if err != nil {
5961
return nil, err
6062
}
61-
return NewSingleStream(session)
63+
return NewSingleStream(connection)
6264
}
6365

6466
// SingleStream implements an opaque, bi-directional data stream using QUIC,
6567
// intending to be a drop-in replacement for TCP.
6668
// A SingleStream is either created by
6769
//
6870
// - on the client side: quic.Dial and then immediately NewSingleStream(sess)
69-
// with the obtained session
71+
// with the obtained connection
7072
// - on the listener side: quic.Listener wrapped in SingleStreamListener, which
7173
// returns SingleStream from Accept.
7274
type SingleStream struct {
73-
Session quic.Connection
75+
Connection quic.Connection
7476
sendStream quic.SendStream
7577
receiveStream quic.ReceiveStream
7678
readDeadline time.Time
7779
mutex sync.Mutex // mutex protects receiveStream for await
7880
onceOK sync.Once
7981
}
8082

81-
func NewSingleStream(session quic.Connection) (*SingleStream, error) {
82-
sendStream, err := session.OpenUniStream()
83+
func NewSingleStream(connection quic.Connection) (*SingleStream, error) {
84+
sendStream, err := connection.OpenUniStream()
8385
if err != nil {
8486
return nil, err
8587
}
8688
return &SingleStream{
87-
Session: session,
89+
Connection: connection,
8890
sendStream: sendStream,
8991
receiveStream: nil,
9092
}, nil
9193
}
9294

9395
func (s *SingleStream) LocalAddr() net.Addr {
94-
return s.Session.LocalAddr()
96+
return s.Connection.LocalAddr()
97+
}
98+
99+
func (s *SingleStream) GetPath() *pan.Path {
100+
if s.Connection == nil {
101+
// XXX(JordiSubira): To be refactored when proper support
102+
// for retrieving path information.
103+
return nil
104+
}
105+
quicSession, ok := s.Connection.(*pan.QUICSession)
106+
if !ok {
107+
// XXX(JordiSubira): To be refactored when proper support
108+
// for retrieving path information.
109+
return nil
110+
}
111+
return quicSession.Conn.GetPath()
95112
}
96113

97114
func (s *SingleStream) RemoteAddr() net.Addr {
98-
return s.Session.RemoteAddr()
115+
return s.Connection.RemoteAddr()
99116
}
100117

101118
func (s *SingleStream) SetDeadline(t time.Time) error {
@@ -148,7 +165,7 @@ func (s *SingleStream) awaitReceiveStream() error {
148165
ctx, cancel = context.WithDeadline(ctx, s.readDeadline)
149166
defer cancel()
150167
}
151-
stream, err := s.Session.AcceptUniStream(ctx)
168+
stream, err := s.Connection.AcceptUniStream(ctx)
152169
if err != nil {
153170
return err
154171
}
@@ -162,7 +179,7 @@ func (s *SingleStream) awaitReceiveStream() error {
162179

163180
func (s *SingleStream) sendOKSignal() {
164181
s.onceOK.Do(func() {
165-
okSignal, err := s.Session.OpenUniStream()
182+
okSignal, err := s.Connection.OpenUniStream()
166183
if err != nil {
167184
return // otherwise ignore error here, what could we do?
168185
}
@@ -175,14 +192,14 @@ func (s *SingleStream) awaitOKSignal(ctx context.Context) error {
175192
defer s.mutex.Unlock()
176193
// ensure we've accepted the actual receive stream first.
177194
if s.receiveStream == nil {
178-
stream, err := s.Session.AcceptUniStream(ctx)
195+
stream, err := s.Connection.AcceptUniStream(ctx)
179196
if err != nil {
180197
return err
181198
}
182199
s.receiveStream = stream
183200
}
184201

185-
_, err := s.Session.AcceptUniStream(ctx)
202+
_, err := s.Connection.AcceptUniStream(ctx)
186203
// We can ignore data arriving in on this stream -- we expect
187204
// a single FIN, so a readeading will immediately give EOF.
188205
// If that's not what we get, guess we can ignore it.
@@ -220,9 +237,9 @@ func (s *SingleStream) CloseSync(ctx context.Context) error {
220237
_ = s.CloseRead()
221238
// Await the OK-signal
222239
if err := s.awaitOKSignal(ctx); err != nil {
223-
return s.Session.CloseWithError(0x101, "shutdown error")
240+
return s.Connection.CloseWithError(0x101, "shutdown error")
224241
}
225-
return s.Session.CloseWithError(0x0, "ok")
242+
return s.Connection.CloseWithError(0x0, "ok")
226243
}
227244

228245
func (s *SingleStream) Close() error {

0 commit comments

Comments
 (0)