mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-23 08:18:11 -07:00
Add man to exported functions/fields
This commit is contained in:
committed by
Lawrence, Rendall
parent
0a5ac35c4d
commit
360ac9d08d
@@ -47,11 +47,11 @@ func TestClientID(t *testing.T) {
|
||||
t.Run(tt.peerID, func(t *testing.T) {
|
||||
var clientID ClientID
|
||||
copy(clientID[:], tt.clientID)
|
||||
peerId, err := bittorrent.NewPeerID([]byte(tt.peerID))
|
||||
peerID, err := bittorrent.NewPeerID([]byte(tt.peerID))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
parsedID := NewClientID(peerId)
|
||||
parsedID := NewClientID(peerID)
|
||||
if parsedID != clientID {
|
||||
t.Error("Incorrectly parsed peer ID", tt.peerID, "as", parsedID)
|
||||
}
|
||||
|
||||
@@ -7,17 +7,21 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// DefaultStorageCtxName default ctx name if value from configuration is not set
|
||||
const DefaultStorageCtxName = "MW_APPROVAL"
|
||||
|
||||
// Builder function that creates and configures specific container
|
||||
type Builder func([]byte, storage.Storage) (Container, error)
|
||||
|
||||
var (
|
||||
buildersMU sync.Mutex
|
||||
builders = make(map[string]Builder)
|
||||
|
||||
// ErrContainerDoesNotExist holds error about nonexistent container
|
||||
ErrContainerDoesNotExist = errors.New("torrent hash container with that name does not exist")
|
||||
)
|
||||
|
||||
// Register used to register specific Builder in registry
|
||||
func Register(n string, c Builder) {
|
||||
if len(n) == 0 {
|
||||
panic("middleware: could not register a Container with an empty name")
|
||||
@@ -31,12 +35,13 @@ func Register(n string, c Builder) {
|
||||
builders[n] = c
|
||||
}
|
||||
|
||||
// Container holds InfoHash and checks if value approved or not
|
||||
type Container interface {
|
||||
Approved(bittorrent.InfoHash) bool
|
||||
}
|
||||
|
||||
// GetContainer creates Container by its name and provided confBytes
|
||||
func GetContainer(name string, confBytes []byte, storage storage.Storage) (Container, error) {
|
||||
|
||||
buildersMU.Lock()
|
||||
defer buildersMU.Unlock()
|
||||
var err error
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package directory implements container which
|
||||
// checks if hash present in any of torrent file
|
||||
// placed in some directory
|
||||
// placed in some directory.
|
||||
// Note: Unlike List, this container also stores torrent name as value
|
||||
package directory
|
||||
|
||||
import (
|
||||
@@ -17,14 +18,18 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Name of this container for registry
|
||||
const Name = "directory"
|
||||
|
||||
func init() {
|
||||
container.Register(Name, build)
|
||||
}
|
||||
|
||||
// Config - implementation of directory container configuration.
|
||||
// Extends list.Config because uses the same storage and Approved function.
|
||||
type Config struct {
|
||||
list.Config
|
||||
// Path in filesystem where torrent files stored and should be watched
|
||||
Path string `yaml:"path"`
|
||||
}
|
||||
|
||||
@@ -100,6 +105,7 @@ type directory struct {
|
||||
watcher *dirwatch.Instance
|
||||
}
|
||||
|
||||
// Stop closes watching of torrent directory
|
||||
func (d *directory) Stop() stop.Result {
|
||||
d.watcher.Close()
|
||||
return stop.AlreadyStopped
|
||||
|
||||
@@ -11,18 +11,25 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Name of this container for registry.
|
||||
const Name = "list"
|
||||
|
||||
func init() {
|
||||
container.Register(Name, build)
|
||||
}
|
||||
|
||||
// Config - implementation of list container configuration.
|
||||
type Config struct {
|
||||
// HashList static list of HEX-encoded InfoHashes.
|
||||
HashList []string `yaml:"hash_list"`
|
||||
// If Invert set to true, all InfoHashes stored in HashList should be blacklisted.
|
||||
Invert bool `yaml:"invert"`
|
||||
// StorageCtx is the name of storage context where to store hash list.
|
||||
// It might be table name, REDIS record key or something else, depending on storage.
|
||||
StorageCtx string `yaml:"storage_ctx"`
|
||||
}
|
||||
|
||||
// DUMMY used as value placeholder if storage needs some value with
|
||||
const DUMMY = "_"
|
||||
|
||||
func build(confBytes []byte, st storage.Storage) (container.Container, error) {
|
||||
@@ -58,12 +65,19 @@ func build(confBytes []byte, st storage.Storage) (container.Container, error) {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// List work structure of hash list. Might be reused in another containers.
|
||||
type List struct {
|
||||
// Invert see Config.Invert description.
|
||||
Invert bool
|
||||
// Storage implementation where hashes are stored for approval checks.
|
||||
Storage storage.Storage
|
||||
// StorageCtx see Config.StorageCtx description.
|
||||
StorageCtx string
|
||||
}
|
||||
|
||||
// Approved checks if specified hash is approved or not.
|
||||
// If List.Invert set to true and hash found in storage, function will return false,
|
||||
// that means that hash is blacklisted.
|
||||
func (l *List) Approved(hash bittorrent.InfoHash) bool {
|
||||
b := l.Storage.Contains(l.StorageCtx, hash.RawString())
|
||||
if len(hash) == bittorrent.InfoHashV2Len {
|
||||
|
||||
@@ -8,7 +8,9 @@ import (
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
"github.com/chihaya/chihaya/middleware/torrentapproval/container"
|
||||
// import directory watcher to enable appropriate support
|
||||
_ "github.com/chihaya/chihaya/middleware/torrentapproval/container/directory"
|
||||
// import static list to enable appropriate support
|
||||
_ "github.com/chihaya/chihaya/middleware/torrentapproval/container/list"
|
||||
"github.com/chihaya/chihaya/pkg/stop"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
|
||||
Reference in New Issue
Block a user