mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-13 16:23:33 -07:00
Clean up Tx API
This commit is contained in:
@@ -8,7 +8,7 @@ just yet, but these are the features it targets:
|
||||
- *Fast* request processing
|
||||
- A generic storage interface that is easily adapted to use any data store
|
||||
- Scaling properties that directly correlate with those of the chosen data store
|
||||
- IPv6 support
|
||||
- Correct IPv6 support
|
||||
- Maximum compatibility with what exists of the BitTorrent spec
|
||||
|
||||
|
||||
|
||||
+11
-11
@@ -89,13 +89,13 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
// Guarantee that no user is in both pools
|
||||
case seeder && leecher:
|
||||
if left == 0 {
|
||||
err := tx.RmLeecher(torrent, peer)
|
||||
err := tx.RemoveLeecher(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
leecher = false
|
||||
} else {
|
||||
err := tx.RmSeeder(torrent, peer)
|
||||
err := tx.RemoveSeeder(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if left == 0 {
|
||||
// Save the peer as a new seeder
|
||||
err := tx.NewSeeder(torrent, peer)
|
||||
err := tx.AddSeeder(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
err = tx.NewLeecher(torrent, peer)
|
||||
err = tx.AddLeecher(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
@@ -148,13 +148,13 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case event == "stopped" || event == "paused":
|
||||
if seeder {
|
||||
err := tx.RmSeeder(torrent, peer)
|
||||
err := tx.RemoveSeeder(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
}
|
||||
if leecher {
|
||||
err := tx.RmLeecher(torrent, peer)
|
||||
err := tx.RemoveLeecher(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
@@ -165,16 +165,16 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
case event == "completed":
|
||||
err := tx.Snatch(user, torrent)
|
||||
err := tx.RecordSnatch(user, torrent)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
if leecher {
|
||||
err := tx.RmLeecher(torrent, peer)
|
||||
err := tx.RemoveLeecher(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
err = tx.NewSeeder(torrent, peer)
|
||||
err = tx.AddSeeder(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
@@ -182,11 +182,11 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
case leecher && left == 0:
|
||||
// A leecher completed but the event was never received
|
||||
err := tx.RmLeecher(torrent, peer)
|
||||
err := tx.RemoveLeecher(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
err = tx.NewSeeder(torrent, peer)
|
||||
err = tx.AddSeeder(torrent, peer)
|
||||
if err != nil {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func (tx *Tx) ClientWhitelisted(peerID string) (exists bool, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Tx) Snatch(user *storage.User, torrent *storage.Torrent) error {
|
||||
func (tx *Tx) RecordSnatch(user *storage.User, torrent *storage.Torrent) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
@@ -242,7 +242,7 @@ func (tx *Tx) MarkActive(t *storage.Torrent) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) NewLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
func (tx *Tx) AddLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
@@ -272,7 +272,7 @@ func (tx *Tx) SetLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) RmLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
func (tx *Tx) RemoveLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
@@ -287,7 +287,7 @@ func (tx *Tx) RmLeecher(t *storage.Torrent, p *storage.Peer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) NewSeeder(t *storage.Torrent, p *storage.Peer) error {
|
||||
func (tx *Tx) AddSeeder(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
@@ -317,7 +317,7 @@ func (tx *Tx) SetSeeder(t *storage.Torrent, p *storage.Peer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx *Tx) RmSeeder(t *storage.Torrent, p *storage.Peer) error {
|
||||
func (tx *Tx) RemoveSeeder(t *storage.Torrent, p *storage.Peer) error {
|
||||
if tx.done {
|
||||
return storage.ErrTxDone
|
||||
}
|
||||
|
||||
+5
-5
@@ -70,12 +70,12 @@ type Tx interface {
|
||||
ClientWhitelisted(peerID string) (bool, error)
|
||||
|
||||
// Writes
|
||||
Snatch(u *User, t *Torrent) error
|
||||
RecordSnatch(u *User, t *Torrent) error
|
||||
MarkActive(t *Torrent) error
|
||||
NewLeecher(t *Torrent, p *Peer) error
|
||||
NewSeeder(t *Torrent, p *Peer) error
|
||||
RmLeecher(t *Torrent, p *Peer) error
|
||||
RmSeeder(t *Torrent, p *Peer) error
|
||||
AddLeecher(t *Torrent, p *Peer) error
|
||||
AddSeeder(t *Torrent, p *Peer) error
|
||||
RemoveLeecher(t *Torrent, p *Peer) error
|
||||
RemoveSeeder(t *Torrent, p *Peer) error
|
||||
SetLeecher(t *Torrent, p *Peer) error
|
||||
SetSeeder(t *Torrent, p *Peer) error
|
||||
IncrementSlots(u *User) error
|
||||
|
||||
Reference in New Issue
Block a user