From 09513f023be0e2f9560f3df7c464fd49c4dc64de Mon Sep 17 00:00:00 2001 From: David Florness Date: Mon, 18 Jan 2021 22:06:50 -0500 Subject: [PATCH] Remove commented functions from libp2p implementation --- election/voter.go | 174 ---------------------------------------------- 1 file changed, 174 deletions(-) diff --git a/election/voter.go b/election/voter.go index 93114f1..d2a38cc 100644 --- a/election/voter.go +++ b/election/voter.go @@ -257,180 +257,6 @@ func (el *Election) GetSums(client *mautrix.Client) { printResults(result, el.Candidates) } -// func handleCmd(cmd string, rw *bufio.ReadWriter, stream network.Stream, election *Election) { -// localVoter := election.localVoter -// switch cmd { -// case "info": -// rw.WriteString(fmt.Sprintf("%s\n", election.rendezvousNonce)) -// for _, option := range election.Candidates { -// rw.WriteString(fmt.Sprintf("%s\n", option)) -// } -// rw.Flush() -// case "close": -// election.Lock() -// defer election.Unlock() -// if peer := stream.Conn().RemotePeer(); peer != election.masterID { -// log.Warning("received close command from non-master:", peer) -// return -// } -// if election.closed { -// log.Warning("election already closed") -// return -// } -// str, err := rw.ReadString('\n') -// if err != nil && err != io.EOF { -// panic(err) -// } -// str = stripNewline(str) -// numPeers, err := strconv.Atoi(str) -// if err != nil { -// panic(err) -// } -// election.close <- numPeers -// election.closed = true -// case "shake": -// election.Lock() -// defer election.Unlock() -// peerID := stream.Conn().RemotePeer() -// if election.closed { -// log.Warning("peer attempted to shake after "+ -// "election was closed:", peerID) -// return -// } -// if _, exists := election.RemoteVoters[peerID]; exists { -// log.Warning("peer attempted to shake after having already done so", peerID) -// return -// } -// fmt.Printf("found voter: %s\n", peerID) -// election.RemoteVoters[peerID] = &Voter{ -// addrInfo: peer.AddrInfo{ -// ID: peerID, -// Addrs: []multiaddr.Multiaddr{stream.Conn().RemoteMultiaddr()}, -// }, -// } -// case "eval": // peer is giving their input and requesting output from our poly -// localVoter.polyMu.RLock() -// defer localVoter.polyMu.RUnlock() -// if localVoter.poly == nil { -// log.Warning("peer attempted to eval before we had our poly:", -// stream.Conn().RemotePeer()) -// return -// } -// inputb58, err := rw.ReadString('\n') -// if err != nil && err != io.EOF { -// log.Warning("unable to read input from peer during eval:", -// stream.Conn().RemotePeer()) -// return -// } -// inputb58 = stripNewline(inputb58) -// inputBytes, err := base58.Decode(inputb58) -// if err != nil { -// log.Warning("unable to base58 decode input from peer during eval:", -// stream.Conn().RemotePeer()) -// return -// } -// peer, exists := election.RemoteVoters[stream.Conn().RemotePeer()] -// if !exists { -// log.Warning("received eval command from unrecognized peer") -// return -// } -// peer.inputMu.Lock() -// defer peer.inputMu.Unlock() -// peer.input = new(big.Int).SetBytes(inputBytes) -// log.Infof("%s input: %s", peer.addrInfo.ID, peer.input) -// output := localVoter.poly.Eval(peer.input) -// rw.WriteString(base58.Encode(output.Bytes())) -// rw.Flush() -// case "sum": -// localVoter.sumMu.RLock() -// defer localVoter.sumMu.RUnlock() -// if localVoter.sum == nil { -// log.Info("peer attempted to fetch sum "+ -// "before we computed it:", stream.Conn().RemotePeer()) -// return -// } -// rw.WriteString(base58.Encode(localVoter.sum.Bytes())) -// rw.Flush() -// default: -// log.Warningf("uknown command %s", cmd) -// } -// } - -// func (election *Election) StartVoting() { -// localVoter := election.localVoter - -// var err error -// localVoter.inputMu.Lock() -// localVoter.input, err = math.RandomBigInt(128, false) -// localVoter.inputMu.Unlock() -// if err != nil { -// panic(err) -// } -// log.Infof("our input: %s", localVoter.input) - -// localVoter.ballot = vote(election.Candidates) -// log.Infof("our ballot: %v", localVoter.ballot) - -// // no +1 since we want degree k-1 where k is total number of voters -// localVoter.polyMu.Lock() -// localVoter.poly = math.NewRandomPoly(uint(len(election.RemoteVoters)), -// 1024, localVoter.ballot) -// localVoter.polyMu.Unlock() -// log.Infof("our constant: %s", localVoter.poly.constant) - -// // get outputs -// var wg sync.WaitGroup -// for _, voter := range election.RemoteVoters { -// wg.Add(1) -// go func(voter *Voter) { -// voter.output = voter.fetchNumber(election, "eval", base58.Encode(localVoter.input.Bytes())) -// logger.Infof("voter %s output: %s", voter.addrInfo.ID, voter.output) -// wg.Done() -// }(voter) -// } -// wg.Wait() - -// // calculate sum -// localVoter.sumMu.Lock() -// localVoter.sum = localVoter.poly.Eval(localVoter.input) -// for _, voter := range election.RemoteVoters { -// localVoter.sum.Add(localVoter.sum, voter.output) -// } -// localVoter.sumMu.Unlock() -// logger.Infof("our sum: %s", localVoter.sum) - -// // get sums -// for _, voter := range election.RemoteVoters { -// wg.Add(1) -// go func(voter *Voter) { -// voter.sum = voter.fetchNumber(election, "sum") -// logger.Infof("voter %s sum: %s", -// voter.addrInfo.ID, voter.sum) -// wg.Done() -// }(voter) -// } -// wg.Wait() - -// mat := constructPolyMatrix(election) -// mat.RREF() - -// constant := mat[0][len(mat[0])-1] -// if !constant.IsInt() { -// panic("constant term is not an integer") -// } - -// result := constant.Num().Bytes() - -// // number of bytes we need to insert at the front since they're zero -// diff := (len(election.Candidates)*len(election.Candidates)) - len(result) -// result = append(make([]byte, diff), result...) - -// printResults(result, election.Candidates) - -// // temporary -// select {} -// } - func constructPolyMatrix(el *Election) math.Matrix { mat := make(math.Matrix, len(el.Joins)) -- 2.38.4