Exemple #1
0
func loadHost(hostname string, m map[string]*sign.Node, testSuite abstract.Suite, testRand cipher.Stream, hc *HostConfig) *sign.Node {
	if h, ok := m[hostname]; ok {
		return h
	}
	host := coconet.NewGoHost(hostname, coconet.NewGoDirectory())
	h := sign.NewNode(host, testSuite, testRand)
	hc.Hosts[hostname] = h
	m[hostname] = h
	return h
}
Exemple #2
0
// NewHostConfig creates a new host configuration that can be populated with
// hosts.
func NewHostConfig() *HostConfig {
	return &HostConfig{SNodes: make([]*sign.Node, 0), Hosts: make(map[string]*sign.Node), Dir: coconet.NewGoDirectory()}
}
func runStaticTest(signType sign.Type, RoundsPerView int, faultyNodes ...int) error {
	// Crypto setup
	suite := nist.NewAES128SHA256P256()
	rand := suite.Cipher([]byte("example"))

	// number of nodes for the test
	nNodes := 4
	// create new directory for communication between peers
	dir := coconet.NewGoDirectory()
	// Create Hosts and Peers
	h := make([]coconet.Host, nNodes)

	for i := 0; i < nNodes; i++ {
		hostName := "host" + strconv.Itoa(i)

		if len(faultyNodes) > 0 {
			h[i] = &coconet.FaultyHost{}
			gohost := coconet.NewGoHost(hostName, dir)
			h[i] = coconet.NewFaultyHost(gohost)
		} else {
			h[i] = coconet.NewGoHost(hostName, dir)
		}

	}

	for _, fh := range faultyNodes {
		h[fh].(*coconet.FaultyHost).SetDeadFor("response", true)
	}

	// Create Signing Nodes out of the hosts
	nodes := make([]*sign.Node, nNodes)
	for i := 0; i < nNodes; i++ {
		nodes[i] = sign.NewNode(h[i], suite, rand)
		nodes[i].Type = signType
		nodes[i].GenSetPool()
		nodes[i].RoundsPerView = RoundsPerView
		defer nodes[i].Close()

		h[i].SetPubKey(nodes[i].PubKey)
		// To test the already keyed signing node, uncomment
		// PrivKey := suite.Secret().Pick(rand)
		// nodes[i] = NewKeyedNode(h[i], suite, PrivKey)
	}
	nodes[0].Height = 2
	nodes[1].Height = 1
	nodes[2].Height = 0
	nodes[3].Height = 0
	// Add edges to parents
	h[1].AddParent(DefaultView, h[0].Name())
	h[2].AddParent(DefaultView, h[1].Name())
	h[3].AddParent(DefaultView, h[1].Name())
	// Add edges to children, listen to children
	h[0].AddChildren(DefaultView, h[1].Name())
	h[1].AddChildren(DefaultView, h[2].Name(), h[3].Name())

	for _, host := range h {
		host.Listen()
		host.Connect(0)
	}

	for i := 0; i < nNodes; i++ {
		if len(faultyNodes) > 0 {
			nodes[i].FailureRate = 1
		}

		go func(i int) {
			// start listening for messages from within the tree
			nodes[i].Listen()
		}(i)
	}

	// Have root node initiate the signing protocol
	// via a simple annoucement
	nodes[0].LogTest = []byte("Hello World")
	// return nodes[0].Announce(DefaultView, &sign.AnnouncementMessage{LogTest: nodes[0].LogTest, Round: 1})
	return nodes[0].StartAnnouncement(&sign.AnnouncementMessage{LogTest: nodes[0].LogTest, Round: 1})
}