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() }
func TestReadRunfile(t *testing.T) { dbg.TestOutput(testing.Verbose(), 2) tplat := &TPlat{} tmpfile := "/tmp/testrun.toml" err := ioutil.WriteFile(tmpfile, []byte(testfile), 0666) if err != nil { dbg.Fatal("Couldn't create file:", err) } tests := platform.ReadRunFile(tplat, tmpfile) dbg.Lvl2(tplat) dbg.Lvlf2("%+v\n", tests[0]) if tplat.App != "sign" { dbg.Fatal("App should be 'sign'") } if len(tests) != 2 { dbg.Fatal("There should be 2 tests") } if tests[0].Get("machines") != "8" { dbg.Fatal("Machines = 8 has not been copied into RunConfig") } }
// listen for clients connections func (s *StampListener) ListenRequests() error { dbg.Lvl3("Setup StampListener on", s.NameL) global, _ := cliutils.GlobalBind(s.NameL) var err error s.Port, err = net.Listen("tcp4", global) if err != nil { panic(err) } go func() { for { dbg.Lvlf2("Listening to sign-requests: %p", s) conn, err := s.Port.Accept() if err != nil { // handle error dbg.Lvl3("failed to accept connection") select { case w := <-s.waitClose: dbg.Lvl3("Closing stamplistener:", w) return default: continue } } dbg.Lvl3("Waiting for connection") c := coconet.NewTCPConnFromNet(conn) if _, ok := s.Clients[c.Name()]; !ok { s.Clients[c.Name()] = c go func(co coconet.Conn) { for { tsm := TimeStampMessage{} err := co.GetData(&tsm) dbg.Lvlf2("Got data to sign %+v - %+v", tsm, tsm.Sreq) if err != nil { dbg.Lvlf1("%p Failed to get from child: %s", s.NameL, err) co.Close() return } switch tsm.Type { default: dbg.Lvlf1("Message of unknown type: %v\n", tsm.Type) case StampRequestType: s.Mux.Lock() s.Queue[READING] = append(s.Queue[READING], MustReplyMessage{Tsm: tsm, To: co.Name()}) s.Mux.Unlock() case StampClose: dbg.Lvl2("Closing connection") co.Close() return case StampExit: dbg.Lvl2("Exiting server upon request") os.Exit(-1) } } }(c) } } }() return nil }