コード例 #1
0
ファイル: peer.go プロジェクト: cmars/conflux
func (rwc *reconWithClient) handleReply(p *Peer, msg ReconMsg, req *requestEntry) error {
	rwc.Peer.logFields(SERVE, log.Fields{"msg": msg}).Debug("handleReply")
	switch m := msg.(type) {
	case *SyncFail:
		if req.node.IsLeaf() {
			return errgo.New("Syncfail received at leaf node")
		}
		rwc.Peer.log(SERVE).Debug("SyncFail: pushing children")
		children, err := req.node.Children()
		if err != nil {
			return errgo.Mask(err)
		}
		for i, childNode := range children {
			rwc.Peer.logFields(SERVE, log.Fields{"childNode": childNode.Key()}).Debug("push")
			if i == 0 {
				rwc.pushRequest(&requestEntry{key: childNode.Key(), node: childNode})
			} else {
				rwc.prependRequests(&requestEntry{key: childNode.Key(), node: childNode})
			}
		}
	case *Elements:
		rwc.rcvrSet.AddAll(m.ZSet)
	case *FullElements:
		elements, err := req.node.Elements()
		if err != nil {
			return err
		}
		local := cf.NewZSet(elements...)
		localNeeds := cf.ZSetDiff(m.ZSet, local)
		remoteNeeds := cf.ZSetDiff(local, m.ZSet)
		elementsMsg := &Elements{ZSet: remoteNeeds}
		rwc.Peer.logFields(SERVE, log.Fields{
			"msg": elementsMsg,
		}).Debug("handleReply: sending")
		rwc.messages = append(rwc.messages, elementsMsg)
		rwc.rcvrSet.AddAll(localNeeds)
	default:
		return errgo.Newf("unexpected message: %v", m)
	}
	return nil
}
コード例 #2
0
ファイル: gossip.go プロジェクト: cmars/conflux
func (p *Peer) handleReconRqstFull(rf *ReconRqstFull) *msgProgress {
	var localset *cf.ZSet
	node, err := p.ptree.Node(rf.Prefix)
	if err == ErrNodeNotFound {
		localset = cf.NewZSet()
	} else if err != nil {
		return &msgProgress{err: err}
	} else {
		elements, err := node.Elements()
		if err != nil {
			return &msgProgress{err: err}
		}
		localset = cf.NewZSet(elements...)
	}
	localNeeds := cf.ZSetDiff(rf.Elements, localset)
	remoteNeeds := cf.ZSetDiff(localset, rf.Elements)
	p.logFields(GOSSIP, log.Fields{
		"localNeeds":  localNeeds.Len(),
		"remoteNeeds": remoteNeeds.Len(),
	}).Info("ReconRqstFull")
	return &msgProgress{elements: localNeeds, messages: []ReconMsg{&Elements{ZSet: remoteNeeds}}}
}