mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-26 01:18:10 -07:00
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:
@@ -67,8 +67,8 @@ const (
|
||||
|
||||
var (
|
||||
logger = log.NewLogger(Name)
|
||||
// ErrSentinelAndClusterChecked returned from initializer if both Config.Sentinel and Config.Cluster provided
|
||||
ErrSentinelAndClusterChecked = errors.New("unable to use both cluster and sentinel mode")
|
||||
// errSentinelAndClusterChecked returned from initializer if both Config.Sentinel and Config.Cluster provided
|
||||
errSentinelAndClusterChecked = errors.New("unable to use both cluster and sentinel mode")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -141,7 +141,7 @@ func (cfg Config) MarshalZerologObject(e *zerolog.Event) {
|
||||
// This function warns to the logger when a value is changed.
|
||||
func (cfg Config) Validate() (Config, error) {
|
||||
if cfg.Sentinel && cfg.Cluster {
|
||||
return cfg, ErrSentinelAndClusterChecked
|
||||
return cfg, errSentinelAndClusterChecked
|
||||
}
|
||||
|
||||
validCfg := cfg
|
||||
@@ -513,15 +513,15 @@ func (ps *Connection) GetPeers(ih bittorrent.InfoHash, forSeeder bool, maxCount
|
||||
return
|
||||
}
|
||||
|
||||
func (ps *store) AnnouncePeers(ih bittorrent.InfoHash, seeder bool, numWant int, v6 bool) ([]bittorrent.Peer, error) {
|
||||
func (ps *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 ps.GetPeers(ih, seeder, numWant, v6, func(ctx context.Context, infoHashKey string, maxCount int) *redis.StringSliceCmd {
|
||||
return ps.GetPeers(ih, forSeeder, numWant, v6, func(ctx context.Context, infoHashKey string, maxCount int) *redis.StringSliceCmd {
|
||||
return ps.HRandField(ctx, infoHashKey, maxCount, false)
|
||||
})
|
||||
}
|
||||
@@ -625,6 +625,14 @@ func (Connection) Preservable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (*store) GCAware() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (*store) StatisticsAware() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Ping sends `PING` request to Redis server
|
||||
func (ps *Connection) Ping() error {
|
||||
return ps.UniversalClient.Ping(context.TODO()).Err()
|
||||
|
||||
Reference in New Issue
Block a user