@@ -23,6 +23,8 @@ import (
23
23
"time"
24
24
25
25
"github.com/quic-go/quic-go"
26
+
27
+ "github.com/netsec-ethz/scion-apps/pkg/pan"
26
28
)
27
29
28
30
var (
@@ -54,48 +56,63 @@ type SingleStreamListener struct {
54
56
55
57
func (l SingleStreamListener ) Accept () (net.Conn , error ) {
56
58
ctx := context .Background ()
57
- session , err := l .Listener .Accept (ctx )
59
+ connection , err := l .Listener .Accept (ctx )
58
60
if err != nil {
59
61
return nil , err
60
62
}
61
- return NewSingleStream (session )
63
+ return NewSingleStream (connection )
62
64
}
63
65
64
66
// SingleStream implements an opaque, bi-directional data stream using QUIC,
65
67
// intending to be a drop-in replacement for TCP.
66
68
// A SingleStream is either created by
67
69
//
68
70
// - on the client side: quic.Dial and then immediately NewSingleStream(sess)
69
- // with the obtained session
71
+ // with the obtained connection
70
72
// - on the listener side: quic.Listener wrapped in SingleStreamListener, which
71
73
// returns SingleStream from Accept.
72
74
type SingleStream struct {
73
- Session quic.Connection
75
+ Connection quic.Connection
74
76
sendStream quic.SendStream
75
77
receiveStream quic.ReceiveStream
76
78
readDeadline time.Time
77
79
mutex sync.Mutex // mutex protects receiveStream for await
78
80
onceOK sync.Once
79
81
}
80
82
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 ()
83
85
if err != nil {
84
86
return nil , err
85
87
}
86
88
return & SingleStream {
87
- Session : session ,
89
+ Connection : connection ,
88
90
sendStream : sendStream ,
89
91
receiveStream : nil ,
90
92
}, nil
91
93
}
92
94
93
95
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 ()
95
112
}
96
113
97
114
func (s * SingleStream ) RemoteAddr () net.Addr {
98
- return s .Session .RemoteAddr ()
115
+ return s .Connection .RemoteAddr ()
99
116
}
100
117
101
118
func (s * SingleStream ) SetDeadline (t time.Time ) error {
@@ -148,7 +165,7 @@ func (s *SingleStream) awaitReceiveStream() error {
148
165
ctx , cancel = context .WithDeadline (ctx , s .readDeadline )
149
166
defer cancel ()
150
167
}
151
- stream , err := s .Session .AcceptUniStream (ctx )
168
+ stream , err := s .Connection .AcceptUniStream (ctx )
152
169
if err != nil {
153
170
return err
154
171
}
@@ -162,7 +179,7 @@ func (s *SingleStream) awaitReceiveStream() error {
162
179
163
180
func (s * SingleStream ) sendOKSignal () {
164
181
s .onceOK .Do (func () {
165
- okSignal , err := s .Session .OpenUniStream ()
182
+ okSignal , err := s .Connection .OpenUniStream ()
166
183
if err != nil {
167
184
return // otherwise ignore error here, what could we do?
168
185
}
@@ -175,14 +192,14 @@ func (s *SingleStream) awaitOKSignal(ctx context.Context) error {
175
192
defer s .mutex .Unlock ()
176
193
// ensure we've accepted the actual receive stream first.
177
194
if s .receiveStream == nil {
178
- stream , err := s .Session .AcceptUniStream (ctx )
195
+ stream , err := s .Connection .AcceptUniStream (ctx )
179
196
if err != nil {
180
197
return err
181
198
}
182
199
s .receiveStream = stream
183
200
}
184
201
185
- _ , err := s .Session .AcceptUniStream (ctx )
202
+ _ , err := s .Connection .AcceptUniStream (ctx )
186
203
// We can ignore data arriving in on this stream -- we expect
187
204
// a single FIN, so a readeading will immediately give EOF.
188
205
// If that's not what we get, guess we can ignore it.
@@ -220,9 +237,9 @@ func (s *SingleStream) CloseSync(ctx context.Context) error {
220
237
_ = s .CloseRead ()
221
238
// Await the OK-signal
222
239
if err := s .awaitOKSignal (ctx ); err != nil {
223
- return s .Session .CloseWithError (0x101 , "shutdown error" )
240
+ return s .Connection .CloseWithError (0x101 , "shutdown error" )
224
241
}
225
- return s .Session .CloseWithError (0x0 , "ok" )
242
+ return s .Connection .CloseWithError (0x0 , "ok" )
226
243
}
227
244
228
245
func (s * SingleStream ) Close () error {
0 commit comments