當前位置: 首頁>>代碼示例>>Golang>>正文


Golang SubscriptionReply.Status方法代碼示例

本文整理匯總了Golang中github.com/cmu440/tribbler/rpc/tribrpc.SubscriptionReply.Status方法的典型用法代碼示例。如果您正苦於以下問題:Golang SubscriptionReply.Status方法的具體用法?Golang SubscriptionReply.Status怎麽用?Golang SubscriptionReply.Status使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cmu440/tribbler/rpc/tribrpc.SubscriptionReply的用法示例。


在下文中一共展示了SubscriptionReply.Status方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: AddSubscription

// AddSubscription adds TargerUserID to UserID's list of subscriptions.
// Replies with status NoSuchUser if the specified UserID does not exist, and NoSuchTargerUser
// if the specified TargerUserID does not exist.
func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {

	userId := args.UserID
	targetId := args.TargetUserID

	userIdKey := util.FormatUserKey(userId)
	targetIdKey := util.FormatUserKey(targetId)

	_, ok_user := ts.libstore.Get(userIdKey)
	_, ok_target := ts.libstore.Get(targetIdKey)
	if ok_user != nil {
		reply.Status = tribrpc.NoSuchUser
	} else if ok_target != nil {
		reply.Status = tribrpc.NoSuchTargetUser
	} else {
		subKey := util.FormatSubListKey(userId)

		err := ts.libstore.AppendToList(subKey, targetId)
		if err != nil {
			reply.Status = tribrpc.Exists
		} else {
			reply.Status = tribrpc.OK
		}
	}
	return nil
}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:29,代碼來源:tribserver_impl.go

示例2: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	UserKey := GenerateUserKey(args.UserID)
	TargetUserKey := GenerateUserKey(args.TargetUserID)

	_, err := ts.lib.Get(UserKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	_, err = ts.lib.Get(TargetUserKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}

	SubsKey := GenerateSubsKey(args.UserID)
	err = ts.lib.AppendToList(SubsKey, args.TargetUserID)
	if err != nil {
		reply.Status = tribrpc.Exists
		return nil
	}

	reply.Status = tribrpc.OK
	return nil
}
開發者ID:oldady,項目名稱:Tribbler,代碼行數:26,代碼來源:tribserver_impl.go

示例3: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	LOGE.Printf("AddSubscription:: args=%s\n", string(marshal(*args)))
	userIDKey := GetUserKey(args.UserID)
	targetUserIDKey := GetUserKey(args.TargetUserID)

	_, err := ts.lib.Get(userIDKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	_, err = ts.lib.Get(targetUserIDKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}

	userSubsKey := GetsSubsKey(args.UserID)
	err = ts.lib.AppendToList(userSubsKey, args.TargetUserID)
	if err != nil {
		reply.Status = tribrpc.Exists
		return nil
	}

	reply.Status = tribrpc.OK
	LOGE.Printf("AddSubscription:: reply=%s\n", string(marshal(reply)))
	return nil
}
開發者ID:201101050424,項目名稱:Tribbler,代碼行數:28,代碼來源:tribserver_impl.go

示例4: RemoveSubscription

func (ts *tribServer) RemoveSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	userkey := util.FormatUserKey(args.UserID)
	targetkey := util.FormatUserKey(args.TargetUserID)

	usersubs := util.FormatSubListKey(args.UserID)
	target := args.TargetUserID

	// Make sure user exists
	if _, eu := ts.ls.Get(userkey); eu != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	// Make sure target exists
	if _, et := ts.ls.Get(targetkey); et != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}
	// Make sure user is subscribed to target
	if err := ts.ls.RemoveFromList(usersubs, target); err != nil {
		reply.Status = tribrpc.NoSuchTargetUser
	} else {
		reply.Status = tribrpc.OK
	}
	return nil
}
開發者ID:pyurky,項目名稱:p2,代碼行數:25,代碼來源:tribserver_impl.go

示例5: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	userkey := util.FormatUserKey(args.UserID)
	targetkey := util.FormatUserKey(args.TargetUserID)

	usersubs := util.FormatSubListKey(args.UserID)
	target := args.TargetUserID

	// Make sure user exists
	if _, eu := ts.ls.Get(userkey); eu != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	// Make sure targetUser exists
	if _, et := ts.ls.Get(targetkey); et != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}
	// Make sure user isn't already subscribed to target
	err := ts.ls.AppendToList(usersubs, target)
	if err == nil {
		reply.Status = tribrpc.OK
	} else {
		reply.Status = tribrpc.Exists
	}
	return nil
}
開發者ID:pyurky,項目名稱:p2,代碼行數:26,代碼來源:tribserver_impl.go

示例6: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	userid := args.UserID
	targetid := args.TargetUserID
	useridkey := util.FormatUserKey(userid)
	targetidkey := util.FormatUserKey(targetid)

	_, userExists := ts.ls.Get(useridkey)

	if userExists != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	_, targetExists := ts.ls.Get(targetidkey)

	if targetExists != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}

	userSubListKey := util.FormatSubListKey(userid)
	appendErr := ts.ls.AppendToList(userSubListKey, targetid)

	if appendErr != nil {
		reply.Status = tribrpc.Exists
		return nil
	}

	reply.Status = tribrpc.OK
	return nil
}
開發者ID:iedwardwangi,項目名稱:Tribbler,代碼行數:31,代碼來源:tribserver_impl.go

示例7: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	user_id := util.FormatUserKey(args.UserID)
	target_user_id := util.FormatUserKey(args.TargetUserID)

	// If the user_id doesn't exist
	// Return error
	_, err := ts.lib_store.Get(user_id)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	// If the target_user_id doesn't exist
	// Return error
	_, err = ts.lib_store.Get(target_user_id)
	if err != nil {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}

	user_sub := util.FormatSubListKey(args.UserID)
	err = ts.lib_store.AppendToList(user_sub, args.TargetUserID)
	if err != nil {
		reply.Status = tribrpc.Exists
		return nil
	}
	reply.Status = tribrpc.OK
	return nil
}
開發者ID:mallocanswer,項目名稱:Tribbler,代碼行數:29,代碼來源:tribserver_impl.go

示例8: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	if ts.userExist(args.UserID) == false {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	if ts.userExist(args.TargetUserID) == false {
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}
	err := ts.ls.AppendToList(util.FormatSubListKey(args.UserID), args.TargetUserID)
	if err == nil {
		reply.Status = tribrpc.OK
	} else {
		reply.Status = tribrpc.Exists
	}
	return nil
}
開發者ID:thuhujin,項目名稱:Tribbler,代碼行數:17,代碼來源:tribserver_impl.go

示例9: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	user_key := util.FormatUserKey(args.UserID)
	target_key := util.FormatUserKey(args.TargetUserID)
	if !ts.checkIfKnown(user_key) {
		reply.Status = tribrpc.NoSuchUser
	} else if !ts.checkIfKnown(target_key) {
		reply.Status = tribrpc.NoSuchTargetUser
	} else {
		sublist_key := util.FormatSubListKey(args.UserID)
		err := ts.storage.AppendToList(sublist_key, args.TargetUserID)
		if err != nil {
			reply.Status = tribrpc.Exists
		} else {
			reply.Status = tribrpc.OK
		}
	}
	return nil
}
開發者ID:jbuckman,項目名稱:p2-440,代碼行數:18,代碼來源:tribserver_impl.go

示例10: doSub

func (ts *tribServer) doSub(user, target string, reply *tribrpc.SubscriptionReply, mode uint8) error {
	_, err := ts.Libstore.Get(user)
	switch err {
	case nil: // expected case, do nothing
	case libstore.ErrorKeyNotFound:
		reply.Status = tribrpc.NoSuchUser
		return nil
	default:
		return err
	}

	_, err = ts.Libstore.Get(target)
	switch err {
	case nil: // expected case, do nothing
	case libstore.ErrorKeyNotFound:
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	default:
		return err
	}

	subscListKey := makeSubscListKey(user)
	subscribes, err := ts.Libstore.GetList(subscListKey)
	switch err {
	case nil:
		// we have successfully retrieved the list of subscribes
		switch mode {
		case doSubAppend:
			// check duplicate subscribes
			for _, subscribe := range subscribes {
				if subscribe == target {
					reply.Status = tribrpc.Exists
					return nil
				}
			}
		case doSubRemove:
			// check whether exist
			existTarget := false
			for _, subscribe := range subscribes {
				if subscribe == target {
					existTarget = true
					break
				}
			}
			if !existTarget {
				reply.Status = tribrpc.NoSuchTargetUser
				return nil
			}
		default:
			panic("")
		}
	case libstore.ErrorKeyNotFound:
		// This user hasn't done subscribe before. do thing
	default:
		return err
	}

	switch mode {
	case doSubAppend:
		err = ts.Libstore.AppendToList(subscListKey, target)
	case doSubRemove:
		err = ts.Libstore.RemoveFromList(subscListKey, target)
	}
	if err == nil { // ignore errors
	}

	reply.Status = tribrpc.OK
	return nil
}
開發者ID:oldady,項目名稱:ds_p2,代碼行數:69,代碼來源:tribserver_impl.go

示例11: AddSubscription

func (ts *tribServer) AddSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	if DBG {
		fmt.Println("-----> AddSubscription")
	}
	/*
		-Check if user present
		-Check if user being subscribed to is present
		-append to list: sublist key formatter,
	*/

	var thisUsrId string = args.UserID
	var subscrId string = args.TargetUserID

	//check if this user present in server
	_, err := ts.libStore.Get(util.FormatUserKey(thisUsrId))

	if err != nil {

		switch err.Error() {
		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchUser
			return nil

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
			return nil
		}
	}

	//check if subscribe user is present
	_, err = ts.libStore.Get(util.FormatUserKey(subscrId))

	if err != nil {
		switch err.Error() {
		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchTargetUser
			return nil

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
		}
	}

	//add to list of subscribers
	err = ts.libStore.AppendToList(util.FormatSubListKey(thisUsrId), subscrId)

	if err != nil {
		//TODO after checkpoint, case on err
		reply.Status = tribrpc.Exists
		return nil
	}

	/* no error */
	reply.Status = tribrpc.OK
	return nil
}
開發者ID:aditij1,項目名稱:p2aditijakkamat,代碼行數:64,代碼來源:tribserver_impl.go

示例12: RemoveSubscription

/*
check if both values exist, then delete the sub
*/
func (ts *tribServer) RemoveSubscription(args *tribrpc.SubscriptionArgs, reply *tribrpc.SubscriptionReply) error {
	if DBG {
		fmt.Println("-----> RemoveSubscription")
	}
	var thisUsrId string = args.UserID
	var subscrId string = args.TargetUserID

	//check if this user present in server
	_, err := ts.libStore.Get(util.FormatUserKey(thisUsrId))

	if err != nil {

		switch err.Error() {
		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchUser
			return nil

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
		}
	}

	//check if subscribe user is present
	_, err = ts.libStore.Get(util.FormatUserKey(subscrId))

	if err != nil {
		switch err.Error() {
		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchTargetUser
			return nil

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
			return nil
		}
	}

	//retrieve list of subsriber user IDs
	err = ts.libStore.RemoveFromList(util.FormatSubListKey(thisUsrId), subscrId)

	if err == nil {
		reply.Status = tribrpc.OK
		return nil
	}

	switch err.Error() {
	case ITEM_NOT_FOUND:
		//User present, no subscriptions
		reply.Status = tribrpc.NoSuchTargetUser
		//Empty list of user IDs
		return nil

	case WRONG_SERVER:
		fmt.Println("ERROR: WRONG SERVER in tribserver")
		return errors.New("Wrong server contacted!")

	case KEY_NOT_FOUND:
		fmt.Println("TribServ: Key was not found!")
		reply.Status = tribrpc.NoSuchTargetUser
		return nil

	default:
		fmt.Println("ERROR in tribserver: wrong error message received")
	}

	if err != nil {
		//TODO after checkpoint, case on err
		reply.Status = tribrpc.NoSuchTargetUser
		return nil
	}

	return nil
}
開發者ID:aditij1,項目名稱:p2aditijakkamat,代碼行數:84,代碼來源:tribserver_impl.go


注:本文中的github.com/cmu440/tribbler/rpc/tribrpc.SubscriptionReply.Status方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。