peerstore

package
v0.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 12 Imported by: 6

Documentation

Overview

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2020 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Local LocalConfig `yaml:"local"`
	Redis RedisConfig `yaml:"redis"`
}

Config defines Store configuration.

NOTE: By default, the LocalStore implementation is used. Redis configuration is ignored unless RedisConfig.Enabled is true.

type LocalConfig added in v0.1.6

type LocalConfig struct {
	TTL time.Duration `yaml:"ttl"`
}

LocalConfig defines LocalStore configuration.

type LocalStore added in v0.1.6

type LocalStore struct {
	// contains filtered or unexported fields
}

LocalStore is an in-memory Store implementation.

func NewLocalStore added in v0.1.6

func NewLocalStore(config LocalConfig, clk clock.Clock) *LocalStore

NewLocalStore creates a new LocalStore.

func (*LocalStore) Close added in v0.1.6

func (s *LocalStore) Close()

Close implements Store.

func (*LocalStore) GetPeers added in v0.1.6

func (s *LocalStore) GetPeers(h core.InfoHash, n int) ([]*core.PeerInfo, error)

GetPeers implements Store.

func (*LocalStore) UpdatePeer added in v0.1.6

func (s *LocalStore) UpdatePeer(h core.InfoHash, p *core.PeerInfo) error

UpdatePeer implements Store.

type RedisConfig

type RedisConfig struct {
	Enabled           bool          `yaml:"enabled"`
	Addr              string        `yaml:"addr"`
	DialTimeout       time.Duration `yaml:"dial_timeout"`
	ReadTimeout       time.Duration `yaml:"read_timeout"`
	WriteTimeout      time.Duration `yaml:"write_timeout"`
	PeerSetWindowSize time.Duration `yaml:"peer_set_window_size"`
	MaxPeerSetWindows int           `yaml:"max_peer_set_windows"`
	MaxIdleConns      int           `yaml:"max_idle_conns"`
	MaxActiveConns    int           `yaml:"max_active_conns"`
	IdleConnTimeout   time.Duration `yaml:"idle_conn_timeout"`
}

RedisConfig defines RedisStore configuration. TODO(evelynl94): rename

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore is a Store backed by Redis.

func NewRedisStore

func NewRedisStore(config RedisConfig, clk clock.Clock) (*RedisStore, error)

NewRedisStore creates a new RedisStore.

func (*RedisStore) Close added in v0.1.6

func (s *RedisStore) Close()

Close implements Store.

func (*RedisStore) GetPeers

func (s *RedisStore) GetPeers(h core.InfoHash, n int) ([]*core.PeerInfo, error)

GetPeers returns at most n PeerInfos associated with h.

func (*RedisStore) UpdatePeer

func (s *RedisStore) UpdatePeer(h core.InfoHash, p *core.PeerInfo) error

UpdatePeer writes p to Redis with a TTL.

type Store

type Store interface {
	// Close cleans up any Store resources.
	Close()

	// GetPeers returns at most n random peers announcing for h.
	GetPeers(h core.InfoHash, n int) ([]*core.PeerInfo, error)

	// UpdatePeer updates peer fields.
	UpdatePeer(h core.InfoHash, peer *core.PeerInfo) error
}

Store provides storage for announcing peers.

func New added in v0.1.6

func New(config Config) (Store, error)

New creates a new Store implementation based on config.

func NewTestStore

func NewTestStore() Store

TestStore returns a thread-safe, in-memory peer store for testing purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL