本文整理匯總了Golang中github.com/mdlayher/goat/goat/data.UserRecord.Seeding方法的典型用法代碼示例。如果您正苦於以下問題:Golang UserRecord.Seeding方法的具體用法?Golang UserRecord.Seeding怎麽用?Golang UserRecord.Seeding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mdlayher/goat/goat/data.UserRecord
的用法示例。
在下文中一共展示了UserRecord.Seeding方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseHTTP
//.........這裏部分代碼省略.........
// If no IP set, detect and store it in query map
query.Set("ip", strings.Split(r.RemoteAddr, ":")[0])
}
// Put client in query map
query.Set("client", client)
// Check if server is configured for passkey announce
if common.Static.Config.Passkey && passkey == "" {
if _, err := w.Write(httpTracker.Error("No passkey found in announce URL")); err != nil {
log.Println(err.Error())
}
return
}
// Validate passkey if needed
user := new(data.UserRecord).Load(passkey, "passkey")
if common.Static.Config.Passkey && user == (data.UserRecord{}) {
if _, err := w.Write(httpTracker.Error("Invalid passkey")); err != nil {
log.Println(err.Error())
}
return
}
// Put passkey in query map
query.Set("passkey", user.Passkey)
// Mark client as HTTP
query.Set("udp", "0")
// Get user's total number of active torrents
seeding := user.Seeding()
leeching := user.Leeching()
if seeding == -1 || leeching == -1 {
if _, err := w.Write(httpTracker.Error("Failed to calculate active torrents")); err != nil {
log.Println(err.Error())
}
return
}
// Verify that client has not exceeded this user's torrent limit
activeSum := seeding + leeching
if user.TorrentLimit < activeSum {
msg := fmt.Sprintf("Exceeded active torrent limit: %d > %d", activeSum, user.TorrentLimit)
if _, err := w.Write(httpTracker.Error(msg)); err != nil {
log.Println(err.Error())
}
return
}
// Tracker announce
if url == "announce" {
// Validate required parameter input
required := []string{"info_hash", "ip", "port", "uploaded", "downloaded", "left"}
// Validate required integer input
reqInt := []string{"port", "uploaded", "downloaded", "left"}
// Check for required parameters
for _, r := range required {
if query.Get(r) == "" {
if _, err := w.Write(httpTracker.Error("Missing required parameter: " + r)); err != nil {
log.Println(err.Error())