Skip to content

Commit 7e1d867

Browse files
committed
fix: upstream context implementation
1 parent e11ae27 commit 7e1d867

File tree

1 file changed

+6
-37
lines changed

1 file changed

+6
-37
lines changed

context.go

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/hex"
66
"net"
77
"sync"
8-
"time"
98

109
gossh "golang.org/x/crypto/ssh"
1110
)
@@ -93,8 +92,8 @@ type Context interface {
9392
}
9493

9594
type sshContext struct {
96-
ctx context.Context
97-
mtx *sync.RWMutex
95+
context.Context
96+
*sync.Mutex
9897

9998
values map[interface{}]interface{}
10099
valuesMu sync.Mutex
@@ -107,9 +106,9 @@ var _ sync.Locker = &sshContext{}
107106
func newContext(srv *Server) (*sshContext, context.CancelFunc) {
108107
innerCtx, cancel := context.WithCancel(context.Background())
109108
ctx := &sshContext{
110-
ctx: innerCtx,
111-
mtx: &sync.RWMutex{},
112-
values: make(map[interface{}]interface{}),
109+
Context: innerCtx,
110+
Mutex: &sync.Mutex{},
111+
values: make(map[interface{}]interface{}),
113112
}
114113
ctx.SetValue(ContextKeyServer, srv)
115114
perms := &Permissions{&gossh.Permissions{}}
@@ -137,7 +136,7 @@ func (ctx *sshContext) Value(key interface{}) interface{} {
137136
if v, ok := ctx.values[key]; ok {
138137
return v
139138
}
140-
return ctx.ctx.Value(key)
139+
return ctx.Context.Value(key)
141140
}
142141

143142
func (ctx *sshContext) SetValue(key, value interface{}) {
@@ -146,36 +145,6 @@ func (ctx *sshContext) SetValue(key, value interface{}) {
146145
ctx.values[key] = value
147146
}
148147

149-
func (ctx *sshContext) Done() <-chan struct{} {
150-
ctx.mtx.RLock()
151-
defer ctx.mtx.RUnlock()
152-
return ctx.ctx.Done()
153-
}
154-
155-
// Deadline implements context.Context.
156-
func (ctx *sshContext) Deadline() (deadline time.Time, ok bool) {
157-
ctx.mtx.RLock()
158-
defer ctx.mtx.RUnlock()
159-
return ctx.ctx.Deadline()
160-
}
161-
162-
// Err implements context.Context.
163-
func (ctx *sshContext) Err() error {
164-
ctx.mtx.RLock()
165-
defer ctx.mtx.RUnlock()
166-
return ctx.ctx.Err()
167-
}
168-
169-
// Lock implements sync.Locker.
170-
func (ctx *sshContext) Lock() {
171-
ctx.mtx.Lock()
172-
}
173-
174-
// Unlock implements sync.Locker.
175-
func (ctx *sshContext) Unlock() {
176-
ctx.mtx.Unlock()
177-
}
178-
179148
func (ctx *sshContext) User() string {
180149
return ctx.Value(ContextKeyUser).(string)
181150
}

0 commit comments

Comments
 (0)