func (s *shuffler) Handle(bc *ByteConn) error { defer bc.Close() var state stateVector err := protobuf.Read(bc, &state, s.cons) if err != nil { return err } if len(state.States) <= s.N { fmt.Println("Got shuffle request.") if err := s.HandleShuffle(&state); err != nil { panic(err.Error()) } return err } else if s.id == 0 { fmt.Println("Got final vector.") return s.getSignOffs(&state) } else { fmt.Println("Got signature request.") sig, err := s.signStateVector(&state) if err != nil { panic(err.Error()) return err } return protobuf.Write(bc, &signature{s.id, sig}) } return nil }
func (s *shuffler) getSignOffs(state *stateVector) error { replies := make(chan *signature) for i := 1; i < s.N; i++ { go func(id int) { port := 8080 + (id % s.N) addr := fmt.Sprintf("localhost:%d", port) rwc, err := net.Dial("tcp", addr) if err != nil { replies <- nil return } defer rwc.Close() bc := &ByteConn{rwc, make([]byte, 1)} if err = protobuf.Write(bc, state); err != nil { replies <- nil return } rwc.(*net.TCPConn).CloseWrite() var sig signature if err = protobuf.Read(bc, &sig); err != nil { replies <- nil return } replies <- &sig }(i) } sigs := make([][]byte, s.N) sig, err := s.signStateVector(state) if err != nil { return err } sigs[0] = sig for i := 0; i < s.N-1; i++ { reply := <-replies if reply != nil { X := s.HH[reply.Id] bytes, _ := protobuf.Encode(state) _, err := anon.Verify(s.suite, bytes, anon.Set{X}, nil, reply.S) if err != nil { return err } sigs[reply.Id] = reply.S } } fmt.Println("Got all signatures.") return s.checkKeys(state.States[len(state.States)-1]) }