@@ -93,12 +93,12 @@ type Context interface {
93
93
94
94
type sshContext struct {
95
95
context.Context
96
- * sync.Mutex
96
+ * sync.RWMutex
97
97
}
98
98
99
99
func newContext (srv * Server ) (* sshContext , context.CancelFunc ) {
100
100
innerCtx , cancel := context .WithCancel (context .Background ())
101
- ctx := & sshContext {innerCtx , & sync.Mutex {}}
101
+ ctx := & sshContext {innerCtx , & sync.RWMutex {}}
102
102
ctx .SetValue (ContextKeyServer , srv )
103
103
perms := & Permissions {& gossh.Permissions {}}
104
104
ctx .SetValue (ContextKeyPermissions , perms )
@@ -120,9 +120,23 @@ func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) {
120
120
}
121
121
122
122
func (ctx * sshContext ) SetValue (key , value interface {}) {
123
+ ctx .RWMutex .Lock ()
124
+ defer ctx .RWMutex .Unlock ()
123
125
ctx .Context = context .WithValue (ctx .Context , key , value )
124
126
}
125
127
128
+ func (ctx * sshContext ) Value (key interface {}) interface {} {
129
+ ctx .RWMutex .RLock ()
130
+ defer ctx .RWMutex .RUnlock ()
131
+ return ctx .Context .Value (key )
132
+ }
133
+
134
+ func (ctx * sshContext ) Done () <- chan struct {} {
135
+ ctx .RWMutex .RLock ()
136
+ defer ctx .RWMutex .RUnlock ()
137
+ return ctx .Context .Done ()
138
+ }
139
+
126
140
func (ctx * sshContext ) User () string {
127
141
return ctx .Value (ContextKeyUser ).(string )
128
142
}
0 commit comments