func HandelSignatureRequest(data []byte, c net.Conn) { var r msgs.SignatureRequest err := proto.Unmarshal(data, &r) if err != nil { fmt.Println("server error reading SignatureRequest:", err) server.ConnectionError(c) return } err = msg.ValidateSignatureRequest(&r) if err != nil { fmt.Println(err) return } keyString := keys.StringKey(r.VoterPublicKey) if !sign.CheckSig(voterListKey, []byte(keyString), r.KeySignature) { fmt.Println("SignatureRequest's KeySignature Signature is invalid") server.ConnectionError(c) return } responseData := getResponse(keyString, &r) server.SendBlock(msg.SignatureResponse, responseData, c) }
func HandelSignatureRequest(data []byte, c net.Conn) { keyString := string(data) responseData, ok := voterKeys[keyString] if !ok { fmt.Println("SignatureRequest with unknown key:", keyString) server.ConnectionError(c) return } server.SendBlock(msg.KeySignatureResponse, responseData, c) }
func HandelSignatureRequest(data []byte, c net.Conn) { var v msgs.Vote err := proto.Unmarshal(data, &v) if err != nil { fmt.Println("server error reading Vote:", err) server.ConnectionError(c) return } err = msg.ValidateVote(ballotKey, &v) if err != nil { fmt.Println(err) return } keyString := stringKey(&v) // TODO: needs a lock id, ok := ballotSet[keyString] if !ok { id = len(votes) votes = append(votes, v) ballotSet[keyString] = id fmt.Printf("Got Vote %d: %s\n", id, v.Ballot) } var response msgs.VoteResponse var ballotEntry msgs.BallotEntry tmp := uint64(id) ballotEntry.Id = &tmp ballotEntry.Ballot = votes[id].Ballot ballotBytes, err := proto.Marshal(&ballotEntry) response.BallotEntry = ballotBytes response.BallotEntrySignature, err = sign.Sign(votePrivateKey, ballotBytes) responseData, err := proto.Marshal(&response) server.SendBlock(msg.VoteResponse, responseData, c) }