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


Golang Node.Talk方法代码示例

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


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

示例1: get

func get(begin int64, wg *sync.WaitGroup, n *node.Node) {
	defer wg.Done()
	var res []string
	var err error
	res, err = n.Talk("/recent/"+strconv.FormatInt(begin, 10)+"-", nil)
	if err != nil {
		manager.RemoveFromAllTable(n)
		log.Println(err)
		return
	}
	err = db.DB.Update(func(tx *bolt.Tx) error {
		for _, line := range res {
			rec, errr := record.Make(line)
			if errr != nil {
				continue
			}
			appendHead(tx, rec.Head)
			tags := strings.Fields(strings.TrimSpace(rec.GetBodyValue("tag", "")))
			if len(tags) > 0 {
				suggest.AddString(tx, rec.Datfile, tags)
				manager.AppendToTableTX(tx, rec.Datfile, n)
			}
		}
		return nil
	})
	if err != nil {
		log.Println(err)
	}
	log.Println("added", len(res), "recent records from", n.Nodestr)
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:30,代码来源:recentlist.go

示例2: getWithRange

//getWithRange gets records with range using node n and adds to cache after checking them.
//if no records exist in cache, uses head
//return true if gotten records>0
func getWithRange(n *node.Node, c *thread.Cache, dm *Manager) bool {
	got := false
	for {
		from, to := dm.Get(n)
		if from <= 0 {
			return got
		}

		var okcount int
		ress, err := n.Talk(fmt.Sprintf("/get/%s/%d-%d", c.Datfile, from, to), nil)
		if err != nil {
			dm.Finished(n, false)
			return false
		}
		err = db.DB.Update(func(tx *bolt.Tx) error {
			for _, res := range ress {
				errf := c.CheckData(tx, res, -1, "", from, to)
				if errf == nil {
					okcount++
				}
			}
			return nil
		})
		if err != nil {
			log.Println(err)
		}
		dm.Finished(n, true)
		log.Println(c.Datfile, okcount, "records were saved from", n.Nodestr)
		got = okcount > 0
	}
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:34,代码来源:download.go

示例3: headWithRange

//headWithRange checks node n has records with range and adds records which should be downloaded to downloadmanager.
func headWithRange(n *node.Node, c *thread.Cache, dm *Manager) bool {
	begin := time.Now().Unix() - cfg.GetRange
	if rec, err := recentlist.Newest(c.Datfile); err == nil {
		begin = rec.Stamp - cfg.GetRange
	}
	if cfg.GetRange == 0 || begin < 0 {
		begin = 0
	}
	res, err := n.Talk(fmt.Sprintf("/head/%s/%d-", c.Datfile, begin), nil)
	if err != nil {
		return false
	}
	if len(res) == 0 {
		ress, errr := n.Talk(fmt.Sprintf("/have/%s", c.Datfile), nil)
		if errr != nil || len(ress) == 0 || ress[0] != "YES" {
			manager.RemoveFromTable(c.Datfile, n)
		} else {
			manager.AppendToTable(c.Datfile, n)
		}
		return false
	}
	manager.AppendToTable(c.Datfile, n)
	dm.Set(res, n)
	return true
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:26,代码来源:download.go

示例4: GetData

//GetData gets records from node n and checks its is same as stamp and id in args.
//save recs if success. returns errSpam or errGet.
func (r *Record) GetData(n *node.Node) error {
	res, err := n.Talk(fmt.Sprintf("/get/%s/%d/%s", r.Datfile, r.Stamp, r.ID), nil)
	if len(res) == 0 {
		err = errors.New("no response")
	}
	if err != nil {
		log.Println(err)
		return cfg.ErrGet
	}
	if err = r.Parse(res[0]); err != nil {
		return cfg.ErrGet
	}
	r.Sync()
	return r.CheckData(-1, -1)
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:17,代码来源:record.go

示例5: TellUpdate

//TellUpdate makes mynode info from node or dnsname or ip addr,
//and broadcast the updates of record id=id in cache c.datfile with stamp.
func TellUpdate(datfile string, stamp int64, id string, n *node.Node) {
	const updateNodes = 10

	tellstr := node.Me(true).Toxstring()
	if n != nil {
		tellstr = n.Toxstring()
	}
	msg := strings.Join([]string{"/update", datfile, strconv.FormatInt(stamp, 10), id, tellstr}, "/")

	ns := Get(datfile, nil)
	ns = ns.Extend(Get(list, nil))
	ns = ns.Extend(Random(ns, updateNodes))
	log.Println("telling #", len(ns))
	for _, n := range ns {
		_, err := n.Talk(msg, nil)
		if err != nil {
			log.Println(err)
		}
	}
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:22,代码来源:manager.go


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