Exemple #1
0
func (p *Peer) handleHello(m *Manager, hello *protocol.Hello) {
	cookie, err := p.getSessionCookie()
	if err != nil {
		glog.Errorf("%s:Bad cookie: %s", p.String(), err.Error())
		p.UpdateStatus(HelloFailed)
		return
	}
	pubKey, err := crypto.ParsePublicKeyFromHash(hello.GetNodePublic())
	if err != nil {
		glog.Errorf("Bad public key: %X", hello.GetNodePublic())
		p.UpdateStatus(HelloFailed)
		return
	}
	ok, err := crypto.Verify(pubKey.SerializeUncompressed(), hello.GetNodeProof(), cookie)
	if !ok {
		glog.Errorf("%s:Bad signature: %X public key: %X hash: %X", p.String(), hello.GetNodeProof(), hello.GetNodePublic(), cookie)
		p.UpdateStatus(HelloFailed)
		return
	}
	if err != nil {
		glog.Errorf("%s:Bad signature verification: %s", p.String(), err.Error())
		p.UpdateStatus(HelloFailed)
		return
	}
	proof, err := m.Key.Sign(cookie)
	if err != nil {
		glog.Errorf("%s:Bad signature creation: %X", p.String(), cookie)
		p.UpdateStatus(HelloFailed)
		return
	}
	if err := p.ProcessHello(hello); err != nil {
		glog.Errorf("%s:%s", p.String(), err.Error())
		return
	}
	port, _ := strconv.ParseUint(m.Port, 10, 32)
	p.Outgoing <- &protocol.TMHello{
		FullVersion:     proto.String(m.Name),
		ProtoVersion:    proto.Uint32(uint32(maxVersion)),
		ProtoVersionMin: proto.Uint32(uint32(minVersion)),
		NodePublic:      []byte(m.PublicKey.String()),
		NodeProof:       proof,
		Ipv4Port:        proto.Uint32(uint32(port)),
		NetTime:         proto.Uint64(uint64(data.Now().Uint32())),
		NodePrivate:     proto.Bool(true),
		TestNet:         proto.Bool(false),
	}
	if hello.ProofOfWork != nil {
		go p.handleProofOfWork(hello.ProofOfWork)
	}
}
Exemple #2
0
func (s *PeerState) ProcessHello(hello *protocol.Hello) error {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.CurrentLedger = hello.GetLedgerIndex()
	s.Name = hello.GetFullVersion()
	s.MajorVersion = hello.GetProtoVersion()
	s.MinorVersion = hello.GetProtoVersionMin()
	var err error
	s.PublicKey, err = crypto.NewRippleHash(string(hello.NodePublic))
	if err != nil {
		s.Status = HelloFailed
		return fmt.Errorf("Bad node public key: %s", hello.NodePublic)
	}
	s.Status = Verified
	return nil
}