Exemple #1
0
func (a *Announce) SendOutAnnounce(recipients []*Participant) error {
	//TODO Add code to actually send out to participants when it works.
	server, err := network.NewTCPServer(7777)
	if err != nil {
		log.Fatal("TCP Server not initialized")
	}
	for _, i := range recipients {
		s, err := json.Marshal(a)
		s = []byte(string(rune(0)) + string(s))
		if err != nil {
			log.Fatal(err)
		}
		c := new(common.Message)
		c.Payload = s
		c.Destination = i.Address
		err = server.SendMessage(c)
		if err != nil {
			log.Fatal(err)
		}
	}

	return nil
}
Exemple #2
0
func CreateFileAnnounce(file string) *Announce {
	A := new(Announce)
	f, err := os.Open(file)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	c, err := f.Stat()
	if err != nil {
	}
	A.Size = int(c.Size())
	//this should be enough.
	A.Chunks = A.Size / (1 << 20)
	//Chunk File
	d := make([]byte, A.Size/(1<<20))
	indexs := 0
	//generate ID and dump the chunks into files
	//A.ID=""
	for _ = 0; err != io.EOF; _, err = f.Read(d) {
		if err != nil {
		}
		redunt, _ := erasure.EncodeRing(A.Chunks, A.Size/A.Chunks, d)
		A.Chunks = len(redunt)
		indexs = indexs + 1
		for index, val := range redunt {
			k, e := os.Open(fmt.Sprintf("%s-%d%d", A.ID, indexs, index))
			if e != nil {
				log.Fatal(e)
			}
			if _, e = k.Write([]byte(val)); e != nil {
				log.Fatal(e)
			}
		}
	}

	return A
}
Exemple #3
0
// Removes all traces of a participant from the State
func (s *State) tossParticipant(pi participantIndex) {
	// remove from s.Participants
	s.participants[pi] = nil

	// remove from s.PreviousEntropyStage1
	var emptyEntropy common.Entropy
	zeroHash, err := crypto.CalculateTruncatedHash(emptyEntropy[:])
	if err != nil {
		log.Fatal(err)
	}
	s.previousEntropyStage1[pi] = zeroHash

	// nil map in s.Heartbeats
	s.heartbeats[pi] = nil
}