2013-08-26 20:38:45 +02:00
|
|
|
// Copyright 2013 The Chihaya Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by the BSD 2-Clause license,
|
|
|
|
// which can be found in the LICENSE file.
|
|
|
|
|
2013-11-04 08:41:30 +01:00
|
|
|
// Package storage implements the models for an abstraction over the
|
|
|
|
// multiple data stores used by a BitTorrent tracker.
|
2013-08-26 20:38:45 +02:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2013-10-04 10:19:43 +02:00
|
|
|
"strconv"
|
2013-08-26 20:38:45 +02:00
|
|
|
)
|
|
|
|
|
2013-11-04 08:41:30 +01:00
|
|
|
// Peer is the internal representation of a participant in a swarm.
|
2013-10-04 10:19:43 +02:00
|
|
|
type Peer struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
UserID uint64 `json:"user_id"`
|
|
|
|
TorrentID uint64 `json:"torrent_id"`
|
2013-08-26 20:38:45 +02:00
|
|
|
|
2013-10-04 10:19:43 +02:00
|
|
|
IP string `json:"ip"`
|
|
|
|
Port uint64 `json:"port"`
|
2013-08-26 20:38:45 +02:00
|
|
|
|
2013-10-04 10:19:43 +02:00
|
|
|
Uploaded uint64 `json:"uploaded"`
|
|
|
|
Downloaded uint64 `json:"downloaded`
|
|
|
|
Left uint64 `json:"left"`
|
|
|
|
LastAnnounce int64 `json:"last_announce"`
|
2013-08-26 20:38:45 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 08:41:30 +01:00
|
|
|
// PeerMapKey is a helper that returns the proper format for keys used for maps
|
|
|
|
// of peers (i.e. torrent.Seeders & torrent.Leechers).
|
2013-10-04 10:19:43 +02:00
|
|
|
func PeerMapKey(peer *Peer) string {
|
|
|
|
return peer.ID + ":" + strconv.FormatUint(peer.UserID, 36)
|
2013-08-26 20:38:45 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 08:41:30 +01:00
|
|
|
// Torrent is the internal representation of a swarm for a given torrent file.
|
2013-10-04 10:19:43 +02:00
|
|
|
type Torrent struct {
|
|
|
|
ID uint64 `json:"id"`
|
|
|
|
Infohash string `json:"infohash"`
|
|
|
|
Active bool `json:"active"`
|
2013-09-07 03:38:56 +02:00
|
|
|
|
2013-10-04 10:19:43 +02:00
|
|
|
Seeders map[string]Peer `json:"seeders"`
|
|
|
|
Leechers map[string]Peer `json:"leechers"`
|
2013-09-07 03:38:56 +02:00
|
|
|
|
2013-10-04 10:19:43 +02:00
|
|
|
Snatches uint64 `json:"snatches"`
|
|
|
|
UpMultiplier float64 `json:"up_multiplier"`
|
|
|
|
DownMultiplier float64 `json:"down_multiplier"`
|
|
|
|
LastAction int64 `json:"last_action"`
|
2013-09-07 03:38:56 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 08:41:30 +01:00
|
|
|
// User is the internal representation of registered user for private trackers.
|
2013-10-04 10:19:43 +02:00
|
|
|
type User struct {
|
|
|
|
ID uint64 `json:"id"`
|
|
|
|
Passkey string `json:"passkey"`
|
2013-09-07 03:38:56 +02:00
|
|
|
|
2013-10-04 10:19:43 +02:00
|
|
|
UpMultiplier float64 `json:"up_multiplier"`
|
|
|
|
DownMultiplier float64 `json:"down_multiplier"`
|
|
|
|
Snatches uint64 `json:"snatches"`
|
2013-08-26 20:38:45 +02:00
|
|
|
}
|