mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-26 08:41:30 +02:00
replace generic-sync-map with xsync.
This commit is contained in:
parent
ad0f73fa9c
commit
39f09e6bb9
2
go.mod
2
go.mod
@ -3,12 +3,12 @@ module github.com/nbd-wtf/go-nostr
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/SaveTheRbtz/generic-sync-map-go v0.0.0-20220414055132-a37292614db8
|
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.2.0
|
github.com/btcsuite/btcd/btcec/v2 v2.2.0
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.3
|
github.com/btcsuite/btcd/btcutil v1.1.3
|
||||||
github.com/gobwas/httphead v0.1.0
|
github.com/gobwas/httphead v0.1.0
|
||||||
github.com/gobwas/ws v1.2.0
|
github.com/gobwas/ws v1.2.0
|
||||||
github.com/mailru/easyjson v0.7.7
|
github.com/mailru/easyjson v0.7.7
|
||||||
|
github.com/puzpuzpuz/xsync v1.5.2
|
||||||
github.com/tidwall/gjson v1.14.4
|
github.com/tidwall/gjson v1.14.4
|
||||||
github.com/tyler-smith/go-bip32 v1.0.0
|
github.com/tyler-smith/go-bip32 v1.0.0
|
||||||
github.com/tyler-smith/go-bip39 v1.1.0
|
github.com/tyler-smith/go-bip39 v1.1.0
|
||||||
|
4
go.sum
4
go.sum
@ -2,8 +2,6 @@ github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25Yn
|
|||||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||||
github.com/SaveTheRbtz/generic-sync-map-go v0.0.0-20220414055132-a37292614db8 h1:Xa6tp8DPDhdV+k23uiTC/GrAYOe4IdyJVKtob4KW3GA=
|
|
||||||
github.com/SaveTheRbtz/generic-sync-map-go v0.0.0-20220414055132-a37292614db8/go.mod h1:ihkm1viTbO/LOsgdGoFPBSvzqvx7ibvkMzYp3CgtHik=
|
|
||||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||||
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
|
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
|
||||||
@ -78,6 +76,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
|
|||||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/puzpuzpuz/xsync v1.5.2 h1:yRAP4wqSOZG+/4pxJ08fPTwrfL0IzE/LKQ/cw509qGY=
|
||||||
|
github.com/puzpuzpuz/xsync v1.5.2/go.mod h1:K98BYhX3k1dQ2M63t1YNVDanbwUPmBCAhNmVrrxfiGg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
10
pool.go
10
pool.go
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
syncmap "github.com/SaveTheRbtz/generic-sync-map-go"
|
"github.com/puzpuzpuz/xsync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SimplePool struct {
|
type SimplePool struct {
|
||||||
@ -58,7 +58,7 @@ func (pool *SimplePool) SubMany(
|
|||||||
filters Filters,
|
filters Filters,
|
||||||
) chan *Event {
|
) chan *Event {
|
||||||
uniqueEvents := make(chan *Event)
|
uniqueEvents := make(chan *Event)
|
||||||
seenAlready := syncmap.MapOf[string, struct{}]{}
|
seenAlready := xsync.NewMapOf[bool]()
|
||||||
|
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
go func(nm string) {
|
go func(nm string) {
|
||||||
@ -74,7 +74,7 @@ func (pool *SimplePool) SubMany(
|
|||||||
|
|
||||||
for evt := range sub.Events {
|
for evt := range sub.Events {
|
||||||
// dispatch unique events to client
|
// dispatch unique events to client
|
||||||
if _, ok := seenAlready.LoadOrStore(evt.ID, struct{}{}); !ok {
|
if _, ok := seenAlready.LoadOrStore(evt.ID, true); !ok {
|
||||||
uniqueEvents <- evt
|
uniqueEvents <- evt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func (pool *SimplePool) SubManyEose(
|
|||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
uniqueEvents := make(chan *Event)
|
uniqueEvents := make(chan *Event)
|
||||||
seenAlready := syncmap.MapOf[string, struct{}]{}
|
seenAlready := xsync.NewMapOf[bool]()
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(len(urls))
|
wg.Add(len(urls))
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ func (pool *SimplePool) SubManyEose(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dispatch unique events to client
|
// dispatch unique events to client
|
||||||
if _, ok := seenAlready.LoadOrStore(evt.ID, struct{}{}); !ok {
|
if _, ok := seenAlready.LoadOrStore(evt.ID, true); !ok {
|
||||||
uniqueEvents <- evt
|
uniqueEvents <- evt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
relay.go
13
relay.go
@ -7,7 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
s "github.com/SaveTheRbtz/generic-sync-map-go"
|
"github.com/puzpuzpuz/xsync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Status int
|
type Status int
|
||||||
@ -38,7 +38,7 @@ type Relay struct {
|
|||||||
RequestHeader http.Header // e.g. for origin header
|
RequestHeader http.Header // e.g. for origin header
|
||||||
|
|
||||||
Connection *Connection
|
Connection *Connection
|
||||||
subscriptions s.MapOf[string, *Subscription]
|
subscriptions *xsync.MapOf[string, *Subscription]
|
||||||
|
|
||||||
Challenges chan string // NIP-42 Challenges
|
Challenges chan string // NIP-42 Challenges
|
||||||
Notices chan string
|
Notices chan string
|
||||||
@ -46,7 +46,7 @@ type Relay struct {
|
|||||||
connectionContext context.Context // will be canceled when the connection closes
|
connectionContext context.Context // will be canceled when the connection closes
|
||||||
connectionContextCancel context.CancelFunc
|
connectionContextCancel context.CancelFunc
|
||||||
|
|
||||||
okCallbacks s.MapOf[string, func(bool, string)]
|
okCallbacks *xsync.MapOf[string, func(bool, string)]
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
|
|
||||||
// custom things that aren't often used
|
// custom things that aren't often used
|
||||||
@ -56,7 +56,12 @@ type Relay struct {
|
|||||||
|
|
||||||
// NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
|
// NewRelay returns a new relay. The relay connection will be closed when the context is canceled.
|
||||||
func NewRelay(ctx context.Context, url string) *Relay {
|
func NewRelay(ctx context.Context, url string) *Relay {
|
||||||
return &Relay{URL: NormalizeURL(url), connectionContext: ctx}
|
return &Relay{
|
||||||
|
URL: NormalizeURL(url),
|
||||||
|
connectionContext: ctx,
|
||||||
|
subscriptions: xsync.NewMapOf[*Subscription](),
|
||||||
|
okCallbacks: xsync.NewMapOf[func(bool, string)](),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RelayConnect returns a relay object connected to url.
|
// RelayConnect returns a relay object connected to url.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user