@@ -32,9 +32,6 @@ import (
32
32
const (
33
33
stopPendingRequestTimeout = 3 * time .Second // give pending requests stopPendingRequestTimeout the time to finish when the server is stopped
34
34
35
- // NotifierContextKey is the key where the notifier associated with the codec is stored in the context
36
- NotifierContextKey = 1
37
-
38
35
notificationBufferSize = 10000 // max buffered notifications before codec is closed
39
36
40
37
DefaultIPCApis = "admin,eth,debug,miner,net,shh,txpool,personal,web3"
@@ -171,7 +168,7 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
171
168
// to send notification to clients. It is thight to the codec/connection. If the
172
169
// connection is closed the notifier will stop and cancels all active subscriptions.
173
170
if options & OptionSubscriptions == OptionSubscriptions {
174
- ctx = context .WithValue (ctx , NotifierContextKey , newBufferedNotifier (codec , notificationBufferSize ))
171
+ ctx = context .WithValue (ctx , notifierKey {} , newBufferedNotifier (codec , notificationBufferSize ))
175
172
}
176
173
s .codecsMu .Lock ()
177
174
if atomic .LoadInt32 (& s .run ) != 1 { // server stopped
@@ -275,7 +272,7 @@ func (s *Server) handle(ctx context.Context, codec ServerCodec, req *serverReque
275
272
276
273
if req .isUnsubscribe { // cancel subscription, first param must be the subscription id
277
274
if len (req .args ) >= 1 && req .args [0 ].Kind () == reflect .String {
278
- notifier , supported := ctx . Value ( NotifierContextKey ).( * bufferedNotifier )
275
+ notifier , supported := NotifierFromContext ( ctx )
279
276
if ! supported { // interface doesn't support subscriptions (e.g. http)
280
277
return codec .CreateErrorResponse (& req .id , & callbackError {ErrNotificationsUnsupported .Error ()}), nil
281
278
}
@@ -298,8 +295,8 @@ func (s *Server) handle(ctx context.Context, codec ServerCodec, req *serverReque
298
295
299
296
// active the subscription after the sub id was successful sent to the client
300
297
activateSub := func () {
301
- notifier , _ := ctx . Value ( NotifierContextKey ).( * bufferedNotifier )
302
- notifier .activate (subid )
298
+ notifier , _ := NotifierFromContext ( ctx )
299
+ notifier .( * bufferedNotifier ). activate (subid )
303
300
}
304
301
305
302
return codec .CreateResponse (req .id , subid ), activateSub
0 commit comments