当前位置: 首页>>代码示例>>Golang>>正文


Golang UserRecord.Leeching方法代码示例

本文整理汇总了Golang中github.com/mdlayher/goat/goat/data.UserRecord.Leeching方法的典型用法代码示例。如果您正苦于以下问题:Golang UserRecord.Leeching方法的具体用法?Golang UserRecord.Leeching怎么用?Golang UserRecord.Leeching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/mdlayher/goat/goat/data.UserRecord的用法示例。


在下文中一共展示了UserRecord.Leeching方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: parseHTTP


//.........这里部分代码省略.........
		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())
				}
开发者ID:sdgoij,项目名称:goat,代码行数:67,代码来源:httpRouter.go


注:本文中的github.com/mdlayher/goat/goat/data.UserRecord.Leeching方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。