-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from GrappigPanda/issue-181
Fixes #181
- Loading branch information
Showing
6 changed files
with
87 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package sqlStoreImpl | ||
|
||
import ( | ||
"database/sql" | ||
"github.com/GrappigPanda/notorious/config" | ||
"github.com/GrappigPanda/notorious/database/schemas" | ||
"github.com/jinzhu/gorm" | ||
) | ||
|
||
// SQLStore is the base implementation for a database which will be used to | ||
// store stats and retrieve whitelisted torrents. | ||
type SQLStore interface { | ||
OpenConnection() (*gorm.DB, error) | ||
GetTorrent(string) (*schemas.Torrent, error) | ||
GetWhitelistedTorrent(string) (*schemas.WhiteTorrent, error) | ||
UpdateStats(uint64, uint64) | ||
UpdateTorrentStats(int64, int64) | ||
ScrapeTorrent(string) *schemas.Torrent | ||
GetWhitelistedTorrents() (*sql.Rows, error) | ||
UpdatePeerStats(uint64, uint64, string) | ||
HandlePeerUpdates() chan PeerTrackerDelta | ||
} | ||
|
||
func InitSQLStoreByDBChoice() SQLStore { | ||
cfg := config.LoadConfig() | ||
if cfg.DBChoice == "mysql" { | ||
return new(MySQLStore) | ||
} else if cfg.DBChoice == "postgres" { | ||
return new(PostgresStore) | ||
} else { | ||
panic("Invalid database choice found for `InitSQLStoreByDBChoice`.") | ||
} | ||
} | ||
|
||
// PeerTrackerDelta handles holding data to be updated by the `UpdateConsumer`. | ||
type PeerTrackerDelta struct { | ||
Uploaded uint64 | ||
Downloaded uint64 | ||
IP string | ||
Event PeerDeltaEvent | ||
} | ||
|
||
// PeerDeltaEvent allows us to set an event to handle how we're going to update | ||
// teh database. | ||
type PeerDeltaEvent int | ||
|
||
const ( | ||
// PEERUPDATE represents a change to a peer, so we'll update a tracker | ||
// user's ratio. | ||
PEERUPDATE PeerDeltaEvent = iota | ||
// TRACKERUPDATE handles updating total tracker stats | ||
TRACKERUPDATE | ||
// TORRENTUPDATE represents the changes to a specific torrent where we | ||
// update total upload/download for the torrent itself. | ||
TORRENTUPDATE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters