Beispiel #1
0
// Collect all bribbles from all users followed
func (ts *Tribserver) GetTribblesBySubscription(
	args *tp.GetTribblesArgs, reply *tp.GetTribblesReply) error {

	user_key := fmt.Sprintf("%s:U", args.Userid)
	foll_key := fmt.Sprintf("%s:F", args.Userid)

	if _, err := ts.store.Get(user_key); lsplog.CheckReport(2, err) {
		reply.Status = tp.ENOSUCHUSER
		return nil
	}

	follows, err := ts.store.GetList(foll_key)
	if lsplog.CheckReport(3, err) {
		reply.Status = tp.ENOSUCHUSER
		return nil
	}

	for i := 0; i < len(follows); i++ {
		var getargs tp.GetTribblesArgs
		var getreply tp.GetTribblesReply

		getargs.Userid = follows[i]
		err = ts.GetTribbles(&getargs, &getreply)
		if lsplog.CheckReport(1, err) {
			reply.Status = tp.ENOSUCHUSER
			return err
		}
		reply.Tribbles = append(reply.Tribbles, getreply.Tribbles...)
	}

	var tribs Tribs = reply.Tribbles
	sort.Sort(tribs)
	if len(tribs) > 100 {
		reply.Tribbles = tribs[:100]
	}
	reply.Status = tp.OK
	return nil
}
Beispiel #2
0
func NewTribserver(master, myhostport string) *Tribserver {
	lsplog.SetVerbose(3)
	lsplog.Vlogf(1, "[Tribserver] new server, master:%s, local:%s\n", master, myhostport)

	srv := new(Tribserver)
	store, err := libstore.NewLibstore(master, myhostport, libstore.NONE)
	if lsplog.CheckReport(1, err) {
		return nil
	}

	atomic.StoreInt32(&srv.id, 0)
	srv.store = store
	srv.hostport = myhostport

	return srv
}