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


Golang BaseConn.SendProto方法代码示例

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


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

示例1: processAccept

// Must be called from the processing goroutine.
func processAccept(node uint16, conn *connect.BaseConn, content []byte) {
	var msg coproto.Accept
	if err := proto.Unmarshal(content, &msg); err != nil {
		conn.Close()
		return
	}

	store.StartTransaction()
	defer store.EndTransaction()

	proposal, leader := store.Proposal()
	msgProposal, msgLeader := *msg.Proposal, node
	if proposal != msgProposal || leader != msgLeader {
		// Send a nack message and return,
		// if this accept relates to an earlier proposal.
		if store.CompareProposals(proposal, leader, msgProposal,
			msgLeader) {

			var nack coproto.Nack
			nack.Proposal = new(uint64)
			nack.Leader = new(uint32)
			*nack.Proposal = proposal
			*nack.Leader = uint32(leader)
			conn.SendProto(6, &nack)

			return
		}

		store.SetProposal(msgProposal, msgLeader)
	}

	addAccept(node, &msg)
}
开发者ID:jbeshir,项目名称:unanimity,代码行数:34,代码来源:process.go

示例2: handleMsg

func handleMsg(node uint16, conn *connect.BaseConn, msg *baseproto.Message) {
	if *msg.MsgType == 2 {
		// Change Forward message.
		forward := new(chproto.ChangeForward)
		err := proto.Unmarshal(msg.Content, forward)
		if err != nil {
			conn.Close()
		}

		// If this is not a core node,
		// and the requesting node is not this node,
		// discard the message.
		if uint16(*forward.Request.RequestNode) != config.Id() &&
			!config.IsCore() {
			return
		}

		// Send a Change Forward Ack message to the sender.
		ack := new(chproto.ChangeForwardAck)
		ack.RequestNode = forward.Request.RequestNode
		ack.RequestId = forward.Request.RequestId
		conn.SendProto(3, ack)

		// Send the forward message to our processing goroutine.
		receivedForwardCh <- receivedForward{forward: forward,
			node: node}

	} else if *msg.MsgType == 3 {
		// Change Forward Ack message.
		ack := new(chproto.ChangeForwardAck)
		err := proto.Unmarshal(msg.Content, ack)
		if err != nil {
			conn.Close()
		}

		// Send the ack message to our processing goroutine.
		receivedAckCh <- receivedAck{ack: ack, node: node}

	} else {
		// Unknown message.
		conn.Close()
	}
}
开发者ID:jbeshir,项目名称:unanimity,代码行数:43,代码来源:handle.go

示例3: sendMessages

func sendMessages(conn *connect.BaseConn) {

	var sessionId uint64
	for key := range sinkUserData {
		if strings.HasPrefix(key, "attach ") {
			idStr := key[7:]
			sessionId, _ = strconv.ParseUint(idStr, 10, 64)
		}
	}

	var msg cliproto_up.Send
	msg.Recipient = new(uint64)
	msg.Tag = new(string)
	msg.Content = new(string)
	*msg.Recipient = sessionId
	*msg.Tag = "benchmark"

	i := uint64(0)
	prevSec := time.Now().Unix()
	count := uint(0)
	for {
		sec := time.Now().Unix()
		if sec != prevSec {
			prevSec = sec
			count = 0
		}

		// If we've hit our cap, busyloop until we can send again.
		if *rate != 0 && count >= *rate {
			continue
		}

		i++
		count++

		timeStr := strconv.FormatInt(time.Now().UnixNano(), 10)
		numberStr := strconv.FormatUint(i, 10)
		*msg.Content = timeStr + " " + numberStr

		conn.SendProto(6, &msg)
	}
}
开发者ID:jbeshir,项目名称:unanimity,代码行数:42,代码来源:main.go

示例4: processPrepare

// Must be called from the processing goroutine.
func processPrepare(node uint16, conn *connect.BaseConn, content []byte) {
	var msg coproto.Prepare
	if err := proto.Unmarshal(content, &msg); err != nil {
		conn.Close()
		return
	}

	store.StartTransaction()
	defer store.EndTransaction()

	newProposal, newLeader := *msg.Proposal, node
	proposal, leader := store.Proposal()
	if store.CompareProposals(newProposal, newLeader, proposal, leader) {

		log.Print("core/consensus: sending promise to ", newLeader)

		// Create a promise message to send back.
		var promise coproto.Promise
		promise.Proposal = new(uint64)
		promise.Leader = new(uint32)
		promise.PrevProposal = new(uint64)
		promise.PrevLeader = new(uint32)
		*promise.Proposal = newProposal
		*promise.Leader = uint32(newLeader)
		*promise.PrevProposal = proposal
		*promise.PrevLeader = uint32(leader)

		// Add all the instructions we've previously accepted or chosen.
		slots := store.InstructionSlots()
		theirFirstUnapplied := *msg.FirstUnapplied
		ourStart := store.InstructionStart()
		relativeSlot := int(theirFirstUnapplied - ourStart)
		if relativeSlot < 0 {
			relativeSlot = 0
		}
		var accepted []*coproto.Instruction
		for ; relativeSlot < len(slots); relativeSlot++ {
			slot := slots[relativeSlot]
			slotNum := ourStart + uint64(relativeSlot)
			for i, _ := range slot {
				if slot[i].IsChosen() {
					appendInst(&accepted, slotNum, slot[i])
					break
				}

				weAccepted := false
				for _, node := range slot[i].Accepted() {
					if node == config.Id() {
						weAccepted = true
						break
					}
				}

				if weAccepted {
					appendInst(&accepted, slotNum, slot[i])
					break
				}
			}
		}

		// Send promise message.
		conn.SendProto(3, &promise)

		// Accept the other node as our new leader.
		store.SetProposal(newProposal, newLeader)
	} else {
		var nack coproto.Nack
		nack.Proposal = new(uint64)
		nack.Leader = new(uint32)
		*nack.Proposal = proposal
		*nack.Leader = uint32(leader)
		conn.SendProto(6, &nack)
	}
}
开发者ID:jbeshir,项目名称:unanimity,代码行数:75,代码来源:process.go


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