diff --git a/storage/storage.go b/storage/storage.go index 9e23676..bfca330 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -12,11 +12,12 @@ var ErrResourceDoesNotExist = bittorrent.ClientError("resource does not exist") // PeerStore is an interface that abstracts the interactions of storing and // manipulating Peers such that it can be implemented for various data stores. type PeerStore interface { - // PutSeeder adds a Seeder to the Swarm identified by the provided infoHash. + // PutSeeder adds a Seeder to the Swarm identified by the provided + // infoHash. PutSeeder(infoHash bittorrent.InfoHash, p bittorrent.Peer) error - // DeleteSeeder removes a Seeder from the Swarm identified by the provided - // infoHash. + // DeleteSeeder removes a Seeder from the Swarm identified by the + // provided infoHash. // // If the Swarm or Peer does not exist, this function should return // ErrResourceDoesNotExist. @@ -26,32 +27,44 @@ type PeerStore interface { // infoHash. PutLeecher(infoHash bittorrent.InfoHash, p bittorrent.Peer) error - // DeleteLeecher removes a Leecher from the Swarm identified by the provided - // infoHash. + // DeleteLeecher removes a Leecher from the Swarm identified by the + // provided infoHash. // // If the Swarm or Peer does not exist, this function should return // ErrResourceDoesNotExist. DeleteLeecher(infoHash bittorrent.InfoHash, p bittorrent.Peer) error - // GraduateLeecher promotes a Leecher to a Seeder in the Swarm identified by - // the provided infoHash. + // GraduateLeecher promotes a Leecher to a Seeder in the Swarm + // identified by the provided infoHash. // - // If the given Peer is not present as a Leecher, add the Peer as a Seeder - // and return no error. + // If the given Peer is not present as a Leecher, add the Peer as a + // Seeder and return no error. GraduateLeecher(infoHash bittorrent.InfoHash, p bittorrent.Peer) error // AnnouncePeers is a best effort attempt to return Peers from the Swarm - // identified by the provided infoHash. The returned Peers are required to be - // either all IPv4 or all IPv6. + // identified by the provided infoHash. The returned Peers are required + // to be either all IPv4 or all IPv6. // // The returned Peers should strive be: // - as close to length equal to numWant as possible without going over // - all IPv4 or all IPv6 depending on the provided peer // - if seeder is true, should ideally return more leechers than seeders - // - if seeder is false, should ideally return more seeders than leechers + // - if seeder is false, should ideally return more seeders than + // leechers AnnouncePeers(infoHash bittorrent.InfoHash, seeder bool, numWant int, p bittorrent.Peer) (peers []bittorrent.Peer, err error) - // Stopper is an interface that expects a Stop method to stops the PeerStore. + // ScrapeSwarm returns information required to answer a scrape request + // about a swarm identified by the given infohash. + // The v6 flag indicates whether or not the IPv6 swarm should be + // scraped. + // The Complete and Incomplete fields of the Scrape must be filled, + // filling the Snatches field is optional. + // If the infohash is unknown to the PeerStore, an empty Scrape is + // returned. + ScrapeSwarm(infoHash bittorrent.InfoHash, v6 bool) bittorrent.Scrape + + // Stopper is an interface that expects a Stop method to stop the + // PeerStore. // For more details see the documentation in the stopper package. stopper.Stopper }