コード例 #1
0
ファイル: round_test.go プロジェクト: mlncn/cothority
// Tests if the rounds are deleted when done
func TestDeleteRounds(t *testing.T) {
	dbg.TestOutput(testing.Verbose(), 4)
	peer1, peer2 := createPeers()

	if len(peer1.Rounds) != 0 {
		t.Fatal("There should be 0 rounds to start with")
	}

	round, err := sign.NewRoundFromType(conode.RoundStamperListenerType, peer1.Node)
	if err != nil {
		t.Fatal("Couldn't create cosi-round")
	}

	peer1.StartAnnouncement(round)
	if len(peer1.Rounds) != 1 {
		t.Fatal("Created one round - should be there")
	}

	time.Sleep(time.Second)

	if len(peer1.Rounds) != 0 {
		t.Fatal("Doing one round shouldn't take more than 1 second")
	}

	peer1.Close()
	peer2.Close()
}
コード例 #2
0
ファイル: round_test.go プロジェクト: mlncn/cothority
// For testing the different round-types
// Every round-type is in his own Test*-method,
// so one can easily run just a given round-test
func testRound(t *testing.T, roundType string) {
	dbg.TestOutput(testing.Verbose(), 4)
	dbg.Lvl2("Testing", roundType)
	peer1, peer2 := createPeers()

	round, err := sign.NewRoundFromType(roundType, peer1.Node)
	if err != nil {
		t.Fatal("Couldn't create", roundType, "round:", err)
	}

	peer1.StartAnnouncement(round)
	time.Sleep(time.Second)

	var cosi *sign.CosiStruct
	switch roundType {
	case sign.RoundCosiType:
		cosi = round.(*sign.RoundCosi).Cosi
	case sign.RoundExceptionType:
		cosi = round.(*sign.RoundException).Cosi
	case conode.RoundStamperType:
		cosi = round.(*conode.RoundStamper).Cosi
	case conode.RoundStamperListenerType:
		cosi = round.(*conode.RoundStamperListener).Cosi
	}
	if cosi.R_hat == nil {
		t.Fatal("Didn't finish round - R_hat empty")
	}
	err = cosi.VerifyResponses()
	if err != nil {
		t.Fatal("Couldn't verify responses")
	}

	peer1.Close()
	peer2.Close()
}
コード例 #3
0
ファイル: peer.go プロジェクト: mlncn/cothority
// LoopRounds starts the system by sending a round of type
// 'roundType' every second for number of 'rounds'.
// If 'rounds' < 0, it loops forever, or until you call
// peer.Close().
func (peer *Peer) LoopRounds(roundType string, rounds int) {
	dbg.Lvl3("Stamp-server", peer.Node.Name(), "starting with IsRoot=", peer.IsRoot(peer.ViewNo))
	ticker := time.NewTicker(sign.ROUND_TIME)
	firstRound := peer.Node.LastRound()
	if !peer.IsRoot(peer.ViewNo) {
		// Children don't need to tick, only the root.
		ticker.Stop()
	}

	for {
		select {
		case nextRole := <-peer.ViewChangeCh():
			dbg.Lvl2(peer.Name(), "assuming next role is", nextRole)
		case <-peer.CloseChan:
			dbg.Lvl3("Server-peer", peer.Name(), "has closed the connection")
			return
		case <-ticker.C:
			dbg.Lvl3("Ticker is firing in", peer.Hostname)
			roundNbr := peer.LastRound() - firstRound
			if roundNbr >= rounds && rounds >= 0 {
				dbg.Lvl3(peer.Name(), "reached max round: closing",
					roundNbr, ">=", rounds)
				ticker.Stop()
				if peer.IsRoot(peer.ViewNo) {
					dbg.Lvl3("As I'm root, asking everybody to terminate")
					peer.SendCloseAll()
				}
			} else {
				if peer.IsRoot(peer.ViewNo) {
					dbg.Lvl2(peer.Name(), "Stamp server in round",
						roundNbr+1, "of", rounds)
					round, err := sign.NewRoundFromType(roundType, peer.Node)
					if err != nil {
						dbg.Fatal("Couldn't create", roundType, err)
					}
					err = peer.StartAnnouncement(round)
					if err != nil {
						dbg.Lvl3(err)
						time.Sleep(1 * time.Second)
						break
					}
				} else {
					dbg.Lvl3(peer.Name(), "running as regular")
				}
			}
		}
	}
}
コード例 #4
0
ファイル: peer_test.go プロジェクト: mlncn/cothority
// What happens if client closes before server does?
func TestClientBeforeServer(t *testing.T) {
	dbg.TestOutput(testing.Verbose(), 4)
	peer1, peer2 := createPeers()

	peer2.Close()
	time.Sleep(time.Second)

	round, err := sign.NewRoundFromType(sign.RoundCosiType, peer1.Node)
	if err != nil {
		t.Fatal("Error while creating round:", err)
	}

	peer1.StartAnnouncement(round)
	time.Sleep(time.Second)

	peer1.Close()
}
コード例 #5
0
ファイル: peer_test.go プロジェクト: mlncn/cothority
func TestStampListener(t *testing.T) {
	dbg.TestOutput(testing.Verbose(), 4)
	peer1, peer2 := createPeers()

	round1 := conode.NewRoundStamperListener(peer1.Node)
	round2, err := sign.NewRoundFromType(conode.RoundStamperListenerType, peer1.Node)

	if err != nil {
		dbg.Fatal("Error when creating round:", err)
	}

	dbg.Lvlf2("Round1: %+v", round1)
	dbg.Lvlf2("Round2: %+v", round2)
	name1, name2 := round1.Name, round2.(*conode.RoundStamperListener).Name
	if name1 != name2 {
		t.Fatal("Hostname of first round is", name1, "and should be equal to", name2)
	}
	peer1.Close()
	peer2.Close()
}
コード例 #6
0
ファイル: round_test.go プロジェクト: mlncn/cothority
func TestRoundSetup(t *testing.T) {
	dbg.TestOutput(testing.Verbose(), 4)
	roundType := "setup"
	dbg.Lvl2("Testing", roundType)
	peer1, peer2 := createPeers()

	round, err := sign.NewRoundFromType(roundType, peer1.Node)
	if err != nil {
		t.Fatal("Couldn't create", roundType, "round:", err)
	}

	peer1.StartAnnouncement(round)
	time.Sleep(time.Second)

	counted := <-round.(*sign.RoundSetup).Counted
	if counted != 2 {
		t.Fatal("Counted", counted, "nodes, but should be 2")
	}

	peer1.Close()
	peer2.Close()
}
コード例 #7
0
ファイル: round_test.go プロジェクト: mlncn/cothority
func TestRoundException(t *testing.T) {
	dbg.TestOutput(testing.Verbose(), 4)
	peer1, peer2 := createPeers()
	sign.ExceptionForceFailure = peer2.Name()

	round, err := sign.NewRoundFromType(sign.RoundExceptionType, peer1.Node)
	if err != nil {
		t.Fatal("Couldn't create Exception round:", err)
	}

	peer1.StartAnnouncement(round)
	time.Sleep(time.Second)

	cosi := round.(*sign.RoundException).Cosi
	if cosi.R_hat == nil {
		t.Fatal("Didn't finish round - R_hat empty")
	}
	err = cosi.VerifyResponses()
	if err != nil {
		t.Fatal("Couldn't verify responses")
	}
	peer1.Close()
	peer2.Close()
}