Beispiel #1
0
// matchFault does what it sounds like; given a particular ServerFault
// message, it will copy it, sign it, and send it out to the network
func (s *State) matchFault(sf *messages.ServerFault) {
	if sf != nil {
		sf.Sign(s.serverPrivKey)
		sf.SendOut(s, sf)
		s.InMsgQueue() <- sf
	}
}
Beispiel #2
0
// regularFaultExecution will create a FaultState in our FaultMap (if none exists already)
// and save the signature of this particular ServerFault to that FaultStat's VoteMap
func (s *State) regularFaultExecution(sf *messages.ServerFault, pl *ProcessList) {
	var issuerID [32]byte
	rawIssuerID := sf.GetSignature().GetKey()
	for i := 0; i < 32; i++ {
		if i < len(rawIssuerID) {
			issuerID[i] = rawIssuerID[i]
		}
	}

	coreHash := sf.GetCoreHash().Fixed()
	faultState := pl.GetFaultState(coreHash)
	if faultState.IsNil() {
		// We don't have a map entry yet; let's create one
		fcore := ExtractFaultCore(sf)
		faultState = FaultState{FaultCore: fcore, AmINegotiator: false, MyVoteTallied: false, VoteMap: make(map[[32]byte]interfaces.IFullSignature)}

		if isMyNegotiation(fcore, pl) {
			faultState.AmINegotiator = true
			pl.AmINegotiator = true
		}

		if faultState.VoteMap == nil {
			faultState.VoteMap = make(map[[32]byte]interfaces.IFullSignature)
		}
		pl.AddFaultState(coreHash, faultState)
	}

	lbytes, err := sf.MarshalForSignature()

	sfSig := sf.Signature.GetSignature()

	isPledge := false
	auth, _ := s.GetAuthority(sf.AuditServerID)
	if auth == nil {
		isPledge = false
	} else {
		valid, err := auth.VerifySignature(lbytes, sfSig)
		if err == nil && valid {
			isPledge = true
			faultState.PledgeDone = true
		}
	}

	sfSigned, err := s.FastVerifyAuthoritySignature(lbytes, sf.Signature, sf.DBHeight)

	if err == nil && (sfSigned > 0 || (sfSigned == 0 && isPledge)) {
		faultState.VoteMap[issuerID] = sf.GetSignature()
	}

	if s.Leader || s.IdentityChainID.IsSameAs(sf.AuditServerID) {
		if !faultState.MyVoteTallied {
			now := time.Now().Unix()
			if now-faultState.LastMatch > 3 {
				if int(now-s.LastTiebreak) > s.FaultTimeout/2 {
					if faultState.SigTally(s) >= len(pl.FedServers)-1 {
						s.LastTiebreak = now
					}
					s.matchFault(sf)
					faultState.LastMatch = now
				}
			}
		}
	}

	// Update the FaultState in our FaultMap with any updates that were applied
	// during execution of this function
	pl.AddFaultState(coreHash, faultState)
}