Esempio n. 1
0
// Gossip sends a message to other peers to the network
func (g *gossipServiceImpl) Gossip(msg *proto.GossipMessage) {
	g.logger.Info(msg)
	if dataMsg := msg.GetDataMsg(); dataMsg != nil {
		g.msgStore.add(msg)
		g.blocksPuller.Add(msg)
	}
	g.emitter.Add(msg)
}
Esempio n. 2
0
// New message notification/handler
func (s *GossipStateProviderImpl) queueNewMessage(msg *proto.GossipMessage) {
	dataMsg := msg.GetDataMsg()
	if dataMsg != nil {
		// Add new payload to ordered set
		s.logger.Debugf("Received new payload with sequence number = [%d]", dataMsg.Payload.SeqNum)
		s.payloads.Push(dataMsg.GetPayload())
	} else {
		s.logger.Debug("Gossip message received is not of data message type, usually this should not happen.")
	}
}
Esempio n. 3
0
func (g *gossipServiceImpl) validateIdentityMsg(msg *proto.GossipMessage) error {
	if msg.GetPeerIdentity() == nil {
		return fmt.Errorf("Identity empty")
	}
	idMsg := msg.GetPeerIdentity()
	pkiID := idMsg.PkiID
	cert := idMsg.Cert
	sig := idMsg.Sig
	if bytes.Equal(g.idMapper.GetPKIidOfCert(api.PeerIdentityType(cert)), common.PKIidType(pkiID)) {
		return fmt.Errorf("Calculated pkiID doesn't match identity")
	}
	idMsg.Sig = nil
	b, err := prot.Marshal(idMsg)
	if err != nil {
		return fmt.Errorf("Failed marshalling: %v", err)
	}
	err = g.mcs.Verify(api.PeerIdentityType(cert), sig, b)
	if err != nil {
		return fmt.Errorf("Failed verifying message: %v", err)
	}
	idMsg.Sig = sig
	return nil
}
Esempio n. 4
0
func (g *gossipInstance) tryForwardMessage(msg *proto.GossipMessage) {
	g.comm.lock.Lock()

	aliveMsg := msg.GetAliveMsg()

	forward := false
	id := string(aliveMsg.Membership.PkiID)
	seqNum := aliveMsg.Timestamp.SeqNum
	if last, exists := g.comm.lastSeqs[id]; exists {
		if last < seqNum {
			g.comm.lastSeqs[id] = seqNum
			forward = true
		}
	} else {
		g.comm.lastSeqs[id] = seqNum
		forward = true
	}

	g.comm.lock.Unlock()

	if forward {
		g.comm.Gossip(msg)
	}
}
Esempio n. 5
0
func (d *gossipDiscoveryImpl) handleMsgFromComm(m *proto.GossipMessage) {
	if m == nil {
		return
	}
	if m.GetAliveMsg() == nil && m.GetMemRes() == nil && m.GetMemReq() == nil {
		d.logger.Warning("Got message with wrong type (expected Alive or MembershipResponse or MembershipRequest message):", m.Content) // TODO: write only message type
		d.logger.Warning(m)
		return
	}

	d.logger.Debug("Got message:", m)
	defer d.logger.Debug("Exiting")

	// TODO: make sure somehow that the membership request is "fresh"
	if memReq := m.GetMemReq(); memReq != nil {
		d.handleAliveMessage(memReq.SelfInformation)
		// Sending a membership response to a peer may block this routine
		// in case the sending is deliberately slow (i.e attack).
		// will keep this async until I'll write a timeout detector in the comm layer
		go d.sendMemResponse(memReq.SelfInformation.Membership, memReq.Known)
		return
	}

	if alive := m.GetAliveMsg(); alive != nil {
		d.handleAliveMessage(alive)
		return
	}

	if memResp := m.GetMemRes(); memResp != nil {
		for _, am := range memResp.Alive {
			d.handleAliveMessage(am)
		}

		for _, dm := range memResp.Dead {
			if !d.crpypt.ValidateAliveMsg(dm) {
				d.logger.Warningf("Alive message isn't authentic, someone spoofed %s's identity", dm.Membership.Endpoint)
				continue
			}

			newDeadMembers := []*proto.AliveMessage{}
			d.lock.RLock()
			if _, known := d.id2Member[string(dm.Membership.PkiID)]; !known {
				newDeadMembers = append(newDeadMembers, dm)
			}
			d.lock.RUnlock()
			d.learnNewMembers([]*proto.AliveMessage{}, newDeadMembers)
		}
	}
}
Esempio n. 6
0
func (da *discoveryAdapter) Gossip(msg *proto.GossipMessage) {
	if msg.IsAliveMsg() && time.Now().Before(da.includeIdentityPeriod) {
		msg.GetAliveMsg().Identity = da.identity
	}
	da.gossipFunc(msg)
}