nip46: tag the context when requests are coming from a bunker client (this is needed in nak so it can differentiate the key used for AUTH).
This commit is contained in:
+11
-2
@@ -17,6 +17,12 @@ import (
|
|||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var bunkerClientCtxKey = &struct{}{}
|
||||||
|
|
||||||
|
func IsBunkerClientOperation(ctx context.Context) bool {
|
||||||
|
return ctx.Value(bunkerClientCtxKey) == true
|
||||||
|
}
|
||||||
|
|
||||||
type BunkerClient struct {
|
type BunkerClient struct {
|
||||||
Relays []string
|
Relays []string
|
||||||
|
|
||||||
@@ -134,9 +140,10 @@ func NewBunker(
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancellableCtx, cancel := context.WithCancel(ctx)
|
cancellableCtx, cancel := context.WithCancel(ctx)
|
||||||
|
bunkerClientCtx := context.WithValue(cancellableCtx, bunkerClientCtxKey, true)
|
||||||
_ = cancel
|
_ = cancel
|
||||||
|
|
||||||
events, eosed := pool.SubscribeManyNotifyEOSE(cancellableCtx, relays, nostr.Filter{
|
events, eosed := pool.SubscribeManyNotifyEOSE(bunkerClientCtx, relays, nostr.Filter{
|
||||||
Tags: nostr.TagMap{"p": []string{clientPublicKey.Hex()}},
|
Tags: nostr.TagMap{"p": []string{clientPublicKey.Hex()}},
|
||||||
Kinds: []nostr.Kind{nostr.KindNostrConnect},
|
Kinds: []nostr.Kind{nostr.KindNostrConnect},
|
||||||
Since: now,
|
Since: now,
|
||||||
@@ -318,12 +325,14 @@ func (bunker *BunkerClient) RPC(ctx context.Context, method string, params []str
|
|||||||
close(bunkerConnectionWorked)
|
close(bunkerConnectionWorked)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
bunkerClientCtx := context.WithValue(ctx, bunkerClientCtxKey, true)
|
||||||
|
|
||||||
for _, url := range bunker.Relays {
|
for _, url := range bunker.Relays {
|
||||||
go func(url string) {
|
go func(url string) {
|
||||||
relay, err := bunker.pool.EnsureRelay(url)
|
relay, err := bunker.pool.EnsureRelay(url)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
relayConnectionWorkedO()
|
relayConnectionWorkedO()
|
||||||
if err := relay.Publish(ctx, evt); err == nil {
|
if err := relay.Publish(bunkerClientCtx, evt); err == nil {
|
||||||
bunkerConnectionWorkedO()
|
bunkerConnectionWorkedO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user