Пример #1
0
func (app *WendyApplication) OnDeliver(msg wendy.Message) {
	log.Printf("[DHT] Received message: %s", msg.String())
	Tribes_Interpreter(msg.String())

	// we forward with a lesser TTL
	if msg.Purpose > 30 {
		newpurpose := msg.Purpose - 1
		AnyCastSpread(newpurpose, msg, cluster)
	}

}
Пример #2
0
//We will use something similar to AnyCast from IPv6 to spread the messages around.
//Since Wendy says we can only use n > 16 as a "purpose", I will use the purpose as TTL
//So the purpose of 30 will be TTL = 0. 31 will be TTL=1 , 32 will be TTL =2 , and so on.
//the idea is "each node will advertise each other known nodes about a new message,
//until the TTL will expire. Given a separation layer 6 (globally), TTL=10 is overkill.
//Given the fact the table is feed with the whole cluster information I need to check
//if TTL is needed or not.
func AnyCastSpread(TTL uint8, mymessage wendy.Message, mycluster *wendy.Cluster) {

	for nID := range AllNodes {
		if nID != mynode.ID {
			msg := mycluster.NewMessage(TTL, nID, []byte(mymessage.String()))
			err := mycluster.Send(msg)
			if err != nil {
				log.Println("[DHT] Can't send a message to: ", nID)
			}
		}
	}

}