Initial work on implementing postgresql storage

Generated placeholders to use raw sql queries with `pgx` driver
and implemented put/del peer and announce functions

* inline GCAware and StatisticsAware to PeerStorage
* fix redis doc configuration sample
* update dependencies
This commit is contained in:
Lawrence, Rendall
2022-06-15 21:42:43 +03:00
parent 615bcb2050
commit 8430e1f31f
8 changed files with 580 additions and 62 deletions
+23 -6
View File
@@ -12,6 +12,7 @@ package keydb
import (
"context"
"errors"
"time"
"github.com/go-redis/redis/v8"
"github.com/rs/zerolog"
@@ -32,9 +33,9 @@ const (
var (
logger = log.NewLogger(Name)
// ErrNotKeyDB returned from initializer if connected does not support KeyDB
// errNotKeyDB returned from initializer if connected does not support KeyDB
// specific command (EXPIREMEMBER)
ErrNotKeyDB = errors.New("provided instance seems not KeyDB")
errNotKeyDB = errors.New("provided instance seems not KeyDB")
)
func init() {
@@ -69,7 +70,7 @@ func newStore(cfg r.Config) (*store, error) {
_ = rs.Process(context.Background(), cmd)
err = r.AsNil(cmd.Err())
if err == nil && len(cmd.Val()) == 0 {
err = ErrNotKeyDB
err = errNotKeyDB
}
var st *store
@@ -158,15 +159,15 @@ func (s store) GraduateLeecher(ih bittorrent.InfoHash, peer bittorrent.Peer) (er
}
// AnnouncePeers is the same function as redis.AnnouncePeers
func (s store) AnnouncePeers(ih bittorrent.InfoHash, seeder bool, numWant int, v6 bool) ([]bittorrent.Peer, error) {
func (s store) AnnouncePeers(ih bittorrent.InfoHash, forSeeder bool, numWant int, v6 bool) ([]bittorrent.Peer, error) {
logger.Trace().
Stringer("infoHash", ih).
Bool("seeder", seeder).
Bool("forSeeder", forSeeder).
Int("numWant", numWant).
Bool("v6", v6).
Msg("announce peers")
return s.GetPeers(ih, seeder, numWant, v6, func(ctx context.Context, infoHashKey string, maxCount int) *redis.StringSliceCmd {
return s.GetPeers(ih, forSeeder, numWant, v6, func(ctx context.Context, infoHashKey string, maxCount int) *redis.StringSliceCmd {
return s.SRandMemberN(context.TODO(), infoHashKey, int64(maxCount))
})
}
@@ -180,6 +181,22 @@ func (s store) ScrapeSwarm(ih bittorrent.InfoHash) (leechers uint32, seeders uin
return
}
func (store) GCAware() bool {
return false
}
func (store) ScheduleGC(_, _ time.Duration) {
}
func (store) StatisticsAware() bool {
return false
}
func (store) ScheduleStatisticsCollection(_ time.Duration) {
}
func (s *store) Stop() stop.Result {
c := make(stop.Channel)
if s.UniversalClient != nil {