Esempio n. 1
0
func newSkipchainService(c *onet.Context, path string) onet.Service {
	s := &Service{
		ServiceProcessor: onet.NewServiceProcessor(c),
		path:             path,
		SkipBlockMap:     &SkipBlockMap{make(map[string]*SkipBlock)},
		verifiers:        map[VerifierID]SkipBlockVerifier{},
	}
	var err error
	s.Propagate, err = manage.NewPropagationFunc(c, "SkipchainPropagate", s.PropagateSkipBlock)
	log.ErrFatal(err)
	c.ProtocolRegister(skipchainBFT, func(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error) {
		return bftcosi.NewBFTCoSiProtocol(n, s.bftVerify)
	})
	if err := s.tryLoad(); err != nil {
		log.Error(err)
	}
	log.ErrFatal(s.RegisterHandlers(s.ProposeSkipBlock, s.SetChildrenSkipBlock,
		s.GetUpdateChain))
	if err := s.RegisterVerification(VerifyShard, s.VerifyShardFunc); err != nil {
		log.Panic(err)
	}
	if err := s.RegisterVerification(VerifyNone, s.VerifyNoneFunc); err != nil {
		log.Panic(err)
	}
	return s
}
Esempio n. 2
0
// addSliceToHash hashes the whole SkipBlockFix plus a slice of bytes.
// This is used
func (sbf *SkipBlockFix) calculateHash() SkipBlockID {
	b, err := network.MarshalRegisteredType(sbf)
	if err != nil {
		log.Panic("Couldn't marshal SkipBlockFix:", err)
	}
	h, err := crypto.HashBytes(network.Suite.Hash(), b)
	if err != nil {
		log.Panic("Couldn't hash SkipBlockFix:", err)
	}
	return h
}