@@ -12,7 +12,6 @@ import (
12
12
transport_quic "github.com/aperturerobotics/bifrost/transport/common/quic"
13
13
"github.com/aperturerobotics/bifrost/util/rwc"
14
14
"github.com/aperturerobotics/util/broadcast"
15
- "github.com/aperturerobotics/util/ccontainer"
16
15
"github.com/aperturerobotics/util/keyed"
17
16
"github.com/aperturerobotics/util/routine"
18
17
"github.com/aperturerobotics/util/scrub"
@@ -49,8 +48,9 @@ type sessionTracker struct {
49
48
xmitRoutine * routine.StateRoutineContainer [* outgoingSignal ]
50
49
// linkRoutine is the routine that manages the Quic link when the session dcOpen.
51
50
linkRoutine * routine.StateRoutineContainer [datachannel.ReadWriteCloser ]
52
- // linkCtr contains the current link
53
- linkCtr * ccontainer.CContainer [* transport_quic.Link ]
51
+ // link contains the current link, if any
52
+ // w.bcast is broadcasted when this changes
53
+ link * transport_quic.Link
54
54
}
55
55
56
56
// newSessionTracker constructs a new sessionTracker.
@@ -71,7 +71,6 @@ func (w *WebRTC) newSessionTracker(peerIDStr string) (keyed.Routine, *sessionTra
71
71
}
72
72
73
73
sess .errCh = make (chan error , 1 )
74
- sess .linkCtr = ccontainer.NewCContainer [* transport_quic.Link ](nil )
75
74
76
75
sess .linkRoutine = routine .NewStateRoutineContainer [datachannel.ReadWriteCloser ](
77
76
func (t1 , t2 datachannel.ReadWriteCloser ) bool { return t1 == t2 },
@@ -192,11 +191,11 @@ func (s *sessionTracker) executeLink(ctx context.Context, dcRwc datachannel.Read
192
191
if wasClosed .Swap (true ) {
193
192
return
194
193
}
195
- s .linkCtr .SwapValue (func (v * transport_quic.Link ) * transport_quic.Link {
196
- if v == nextLink {
197
- return nil
194
+ s .w .bcast .HoldLock (func (broadcast func (), getWaitCh func () <- chan struct {}) {
195
+ if s .link == nextLink {
196
+ s .link = nil
197
+ broadcast ()
198
198
}
199
- return v
200
199
})
201
200
go s .w .handler .HandleLinkLost (nextLink )
202
201
_ = dcRwc .Close ()
@@ -218,7 +217,10 @@ func (s *sessionTracker) executeLink(ctx context.Context, dcRwc datachannel.Read
218
217
}
219
218
220
219
// Link established.
221
- s .linkCtr .SetValue (nextLink )
220
+ s .w .bcast .HoldLock (func (broadcast func (), getWaitCh func () <- chan struct {}) {
221
+ s .link = nextLink
222
+ broadcast ()
223
+ })
222
224
s .w .handler .HandleLinkEstablished (nextLink )
223
225
224
226
// Cleanup link on exit
0 commit comments