4
4
"io"
5
5
"net"
6
6
"sync"
7
+ "sync/atomic"
7
8
8
9
"github.com/pion/logging"
9
10
"github.com/pion/transport/packetio"
@@ -17,7 +18,8 @@ type streamSession interface {
17
18
18
19
type session struct {
19
20
localContextMutex sync.Mutex
20
- localContext , remoteContext * Context
21
+ localContext * Context
22
+ remoteContext atomic.Value // *Context
21
23
localOptions , remoteOptions []ContextOption
22
24
23
25
newStream chan readStream
@@ -106,13 +108,15 @@ func (s *session) close() error {
106
108
}
107
109
108
110
func (s * session ) start (localMasterKey , localMasterSalt , remoteMasterKey , remoteMasterSalt []byte , profile ProtectionProfile , child streamSession ) error {
109
- var err error
110
- s .localContext , err = CreateContext (localMasterKey , localMasterSalt , profile , s .localOptions ... )
111
- if err != nil {
112
- return err
113
- }
114
-
115
- s .remoteContext , err = CreateContext (remoteMasterKey , remoteMasterSalt , profile , s .remoteOptions ... )
111
+ err := s .UpdateContext (& Config {
112
+ Keys : SessionKeys {
113
+ LocalMasterKey : localMasterKey ,
114
+ LocalMasterSalt : localMasterSalt ,
115
+ RemoteMasterKey : remoteMasterKey ,
116
+ RemoteMasterSalt : remoteMasterSalt ,
117
+ },
118
+ Profile : profile ,
119
+ })
116
120
if err != nil {
117
121
return err
118
122
}
@@ -148,3 +152,23 @@ func (s *session) start(localMasterKey, localMasterSalt, remoteMasterKey, remote
148
152
149
153
return nil
150
154
}
155
+
156
+ // UpdateContext updates the local and remote context of the session.
157
+ func (s * session ) UpdateContext (config * Config ) error {
158
+ localContext , err := CreateContext (config .Keys .LocalMasterKey , config .Keys .LocalMasterSalt , config .Profile , s .localOptions ... )
159
+ if err != nil {
160
+ return err
161
+ }
162
+ remoteContext , err := CreateContext (config .Keys .RemoteMasterKey , config .Keys .RemoteMasterSalt , config .Profile , s .remoteOptions ... )
163
+ if err != nil {
164
+ return err
165
+ }
166
+
167
+ s .localContextMutex .Lock ()
168
+ s .localContext = localContext
169
+ s .localContextMutex .Unlock ()
170
+
171
+ s .remoteContext .Store (remoteContext )
172
+
173
+ return nil
174
+ }
0 commit comments