@@ -94,11 +94,14 @@ type Context interface {
9494type sshContext struct {
9595 context.Context
9696 * sync.Mutex
97+
98+ values map [interface {}]interface {}
99+ valuesMu sync.Mutex
97100}
98101
99102func newContext (srv * Server ) (* sshContext , context.CancelFunc ) {
100103 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 {}) }
102105 ctx .SetValue (ContextKeyServer , srv )
103106 perms := & Permissions {& gossh.Permissions {}}
104107 ctx .SetValue (ContextKeyPermissions , perms )
@@ -119,8 +122,19 @@ func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) {
119122 ctx .SetValue (ContextKeyRemoteAddr , conn .RemoteAddr ())
120123}
121124
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+
122134func (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
124138}
125139
126140func (ctx * sshContext ) User () string {
0 commit comments