@@ -94,11 +94,14 @@ type Context interface {
94
94
type sshContext struct {
95
95
context.Context
96
96
* sync.Mutex
97
+
98
+ values map [interface {}]interface {}
99
+ valuesMu sync.Mutex
97
100
}
98
101
99
102
func newContext (srv * Server ) (* sshContext , context.CancelFunc ) {
100
103
innerCtx , cancel := context .WithCancel (context .Background ())
101
- ctx := & sshContext {innerCtx , & sync.Mutex {}}
104
+ ctx := & sshContext {Context : innerCtx , Mutex : & sync.Mutex {}, values : make ( map [ interface {}] interface {}) }
102
105
ctx .SetValue (ContextKeyServer , srv )
103
106
perms := & Permissions {& gossh.Permissions {}}
104
107
ctx .SetValue (ContextKeyPermissions , perms )
@@ -119,8 +122,19 @@ func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) {
119
122
ctx .SetValue (ContextKeyRemoteAddr , conn .RemoteAddr ())
120
123
}
121
124
125
+ func (ctx * sshContext ) Value (key interface {}) interface {} {
126
+ ctx .valuesMu .Lock ()
127
+ defer ctx .valuesMu .Unlock ()
128
+ if v , ok := ctx .values [key ]; ok {
129
+ return v
130
+ }
131
+ return ctx .Context .Value (key )
132
+ }
133
+
122
134
func (ctx * sshContext ) SetValue (key , value interface {}) {
123
- ctx .Context = context .WithValue (ctx .Context , key , value )
135
+ ctx .valuesMu .Lock ()
136
+ defer ctx .valuesMu .Unlock ()
137
+ ctx .values [key ] = value
124
138
}
125
139
126
140
func (ctx * sshContext ) User () string {
0 commit comments