Пример #1
0
func main() {
	lsplog.SetVerbose(3)
	lsplog.Vlogf(3, "[Request] Request has started")
	lsplog.Vlogf(3, "[Request] Args: %s", os.Args)
	hostport := os.Args[1]
	var e error
	client, e = lsp12.NewLspClient(hostport, &lsp12.LspParams{5, 2000})
	if e != nil {
		lsplog.Vlogf(3, "[Worker] Connection to server failed.")
	}
	joinRequest := "J"
	lsplog.Vlogf(3, "[worker] Sending: %s", joinRequest)
	client.Write([]byte(joinRequest))
	for {
		response, err := client.Read()
		if err != nil {
			return
		}

		lsplog.Vlogf(3, "[Worker] Recieved: %s", string(response))
		responseParts := strings.Split(string(response), " ")
		if len(responseParts) == 4 {
			hash := responseParts[1]
			lsplog.Vlogf(3, "[Worker] Hash: %s", hash)
			lower, _ := strconv.Atoi(responseParts[2])
			upper, _ := strconv.Atoi(responseParts[3])
			go getPassword(hash, lower, upper)
		} else {
			suspended = true
		}
	}
}
func main() {
	var ihelp *bool = flag.Bool("h", false, "Print help information")
	var iport *int = flag.Int("p", 6666, "Port number")
	var iverb *int = flag.Int("v", 1, "Verbosity (0-6)")
	var idrop *int = flag.Int("r", 0, "Network packet drop percentage")
	var elim *int = flag.Int("k", 5, "Epoch limit")
	var ems *int = flag.Int("d", 2000, "Epoch duration (millisecconds)")
	flag.Parse()
	if *ihelp {
		flag.Usage()
		os.Exit(0)
	}
	var port int = *iport
	if flag.NArg() > 0 {
		nread, _ := fmt.Sscanf(flag.Arg(0), "%d", &port)
		if nread != 1 {
			flag.Usage()
			os.Exit(0)
		}
	}
	params := &lsp12.LspParams{*elim, *ems}

	lsplog.SetVerbose(*iverb)
	lspnet.SetWriteDropPercent(*idrop)
	fmt.Printf("Establishing server on port %d\n", port)
	srv, err := lsp12.NewLspServer(port, params)
	if err != nil {
		fmt.Printf("... failed.  Error message %s\n", err.Error())
	} else {
		runserver(srv)
	}
}
Пример #3
0
func main() {
	lsplog.SetVerbose(3)
	lsplog.Vlogf(3, "[Request] Request has started")
	lsplog.Vlogf(3, "[Request] Args: %s", os.Args)
	port, _ := strconv.Atoi(os.Args[1])
	srv, _ = lsp12.NewLspServer(port, &lsp12.LspParams{5, 2000})
	clients = make(map[uint16]*client)
	workers = make(map[uint16]*worker)
	requestBuffer = abuf.NewBuf()
	workersAvailable = abuf.NewBuf()
	go networkHandler()

	//Scheduler
	for {
		workerConnId := workersAvailable.Remove().(uint16)
		req := requestBuffer.Remove().(*request)
		for clients[req.connId] == nil {
			req = requestBuffer.Remove().(*request)
		}
		freeWorker := workers[workerConnId]
		freeWorker.worksForClient = req.connId
		freeWorker.command = req.crackRequest
		srv.Write(workerConnId, []byte(req.crackRequest))
	}
}
Пример #4
0
func (ts *TestSystem) runtest(timeoutms int) {
	lspnet.SetWriteDropPercent(ts.DropPercent)
	if ts.Description != "" {
		fmt.Printf("Testing: %s\n", ts.Description)
	}
	go ts.runserver()
	for i := 0; i < ts.NClients; i++ {
		go ts.runclient(i)
	}
	go ts.runtimeout(timeoutms)
	for i := 0; i < ts.NClients; i++ {
		v := <-ts.CChan
		if v < 0 {
			ts.RunFlag = false
			ts.Tester.Logf("Test timed out after %f secs\n",
				float64(timeoutms)/1000.0)
			ts.Tester.FailNow()
		}
	}
	ts.RunFlag = false
	lsplog.Vlogf(0, "Passed: %d clients, %d messages/client, %.2f maxsleep, %.2f drop rate\n",
		ts.NClients, ts.NMessages,
		float64(ts.MaxSleepMilliseconds)/1000.0,
		float64(ts.DropPercent)/100.0)
	lsplog.SetVerbose(DefaultVerbosity)
	lspnet.SetWriteDropPercent(0)
}
Пример #5
0
func TestBasic2(t *testing.T) {
	lsplog.SetVerbose(2)
	ts := NewTestSystem(t, 1, params(5, 2000))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("Long client/server interaction")
	ts.SetNMessages(50)
	ts.runtest(1000)
}
Пример #6
0
func TestBasic4(t *testing.T) {
	lsplog.SetVerbose(DefaultVerbosity)
	ts := NewTestSystem(t, 10, params(5, 2000))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("10 clients, long interaction")
	ts.SetNMessages(50)
	ts.runtest(2000)
}
Пример #7
0
func TestBasic3(t *testing.T) {
	lsplog.SetVerbose(DefaultVerbosity)
	ts := NewTestSystem(t, 2, params(5, 2000))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("Two client/one server interaction")
	ts.SetNMessages(50)
	ts.runtest(1000)
}
Пример #8
0
func TestBasic6(t *testing.T) {
	lsplog.SetVerbose(DefaultVerbosity)
	ts := NewTestSystem(t, 2, params(5, 2000))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("2 clients, test wraparound of sequence numnbers")
	ts.SetNMessages(550)
	ts.runtest(2000)
}
Пример #9
0
func TestSendReceive2(t *testing.T) {
	lsplog.SetVerbose(DefaultVerbosity)
	ts := NewTestSystem(t, 4, params(5, 5000))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("No epochs.  Multiple clients")
	ts.SetNMessages(6)
	ts.runtest(5000)
}
Пример #10
0
func TestBasic5(t *testing.T) {
	lsplog.SetVerbose(DefaultVerbosity)
	ts := NewTestSystem(t, 4, params(5, 2000))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("Random delays by clients & server")
	ts.SetNMessages(10)
	ts.SetMaxSleepMilliseconds(100)
	ts.runtest(15000)
}
Пример #11
0
func TestRobust3(t *testing.T) {
	lsplog.SetVerbose(DefaultVerbosity)
	ts := NewTestSystem(t, 4, params(20, 50))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("Four clients.  Some packet dropping")
	ts.SetDropPercent(20)
	ts.SetNMessages(8)
	ts.runtest(15000)
}
Пример #12
0
func TestSendReceive3(t *testing.T) {
	lsplog.SetVerbose(DefaultVerbosity)
	ts := NewTestSystem(t, 4, params(5, 10000))
	if ts == nil {
		t.FailNow()
	}
	ts.SetDescription("No epochs.  Random delays inserted")
	ts.SetNMessages(6)
	ts.SetMaxSleepMilliseconds(100)
	ts.runtest(10000)
}
func main() {
	var ihelp *bool = flag.Bool("h", false, "Show help information")
	var iport *int = flag.Int("p", 6666, "Port number")
	var ihost *string = flag.String("H", "localhost", "Host address")
	var iverb *int = flag.Int("v", 1, "Verbosity (0-6)")
	var irdrop *int = flag.Int("r", 0, "Network read packet drop percentage")
	var iwdrop *int = flag.Int("w", 0, "Network write packet drop percentage")
	var elim *int = flag.Int("k", 5, "Epoch limit")
	var ems *int = flag.Int("d", 2000, "Epoch duration (millisecconds)")
	flag.Parse()
	if *ihelp {
		flag.Usage()
		os.Exit(0)
	}
	if flag.NArg() > 0 {
		// Look for host:port on command line
		ok := true
		fields := strings.Split(flag.Arg(0), ":")
		ok = ok && len(fields) == 2
		if ok {
			*ihost = fields[0]
			n, err := fmt.Sscanf(fields[1], "%d", iport)
			ok = ok && n == 1 && err == nil
		}
		if !ok {
			flag.Usage()
			os.Exit(0)
		}
	}
	params := &lsp12.LspParams{*elim, *ems}

	lsplog.SetVerbose(*iverb)
	lspnet.SetReadDropPercent(*irdrop)
	lspnet.SetWriteDropPercent(*iwdrop)
	hostport := fmt.Sprintf("%s:%v", *ihost, *iport)
	fmt.Printf("Connecting to server at %s\n", hostport)
	cli, err := lsp12.NewLspClient(hostport, params)
	if err != nil {
		fmt.Printf("... failed.  Error message %s\n", err.Error())
	}
	if lsplog.CheckReport(1, err) {
		return
	}
	runclient(cli)
}
Пример #14
0
func main() {
	lsplog.SetVerbose(3)
	lsplog.Vlogf(3, "[Request] Request has started")
	lsplog.Vlogf(3, "[Request] Args: %s", os.Args)
	if len(os.Args) != 4 {
		lsplog.Vlogf(3, "[Request] Please give arguments \"host:port hash len\"")
		return
	}

	hostport := os.Args[1]
	hash := os.Args[2]
	length, _ := strconv.Atoi(os.Args[3])
	lower := "0"
	upper := strings.Repeat("9", length)
	client, e := lsp12.NewLspClient(hostport, &lsp12.LspParams{5, 2000})
	if e != nil {
		lsplog.Vlogf(3, "[Request] Connection to server failed.")
	}
	crackRequest := fmt.Sprintf("C %s %s %s", hash, lower, upper)
	lsplog.Vlogf(3, "[Request] Sending: %s", crackRequest)
	client.Write([]byte(crackRequest))
	response, err := client.Read()
	lsplog.Vlogf(3, string(response))
	if err != nil {
		lsplog.Vlogf(3, "Disconnected")
		return
	}
	responseString := string(response)

	if responseString == "X" {
		lsplog.Vlogf(3, "Not Found")
		return
	} else {
		response := strings.Split(responseString, " ")
		lsplog.Vlogf(3, "Found: %s", response[1])
	}
}
Пример #15
0
// Test components
func NewSynchTestSystem(t *testing.T, nclients int, nmessages int, mode int, maxepochs int, params *LspParams) {
	fmt.Printf("Testing: Mode %s, %d clients\n", SynchModeName[mode], nclients)
	ts := new(SynchTestSystem)
	ts.Mode = mode
	ts.Params = params
	ts.C2MChan = make(chan bool)
	ts.S2MChan = make(chan bool)
	ts.N2MChan = make(chan bool)
	ts.TChan = make(chan int)
	ts.M2CChan = make(chan bool)
	ts.M2SChan = make(chan bool)
	ts.M2NChan = make(chan bool)
	ts.Nclients = nclients
	ts.Nmessages = nmessages
	ts.Clients = make([]*LspClient, nclients)
	ts.ClientMap = make(map[uint16]int, nclients)
	ts.Data = make([][]int, nclients)
	ts.Rgen = *rand.New(rand.NewSource(time.Now().Unix()))
	for i := 0; i < nclients; i++ {
		ts.Data[i] = genData(nmessages, ts.Rgen)
	}
	ts.Nclients = nclients
	ts.Port = synchrandport(ts.Rgen)
	ts.RunFlag = true
	ts.Tester = t
	go ts.RunNetwork()
	go ts.RunServer()
	// Set up clients
	for i := 0; i < nclients; i++ {
		go ts.RunClient(i)
	}
	go ts.RunTimeout(float64(maxepochs))
	ts.Master()
	ts.RunFlag = false
	lsplog.SetVerbose(SynchDefaultVerbosity)
	lspnet.SetWriteDropPercent(0)
}
Пример #16
0
func TestStopServerConns1(t *testing.T) {
	lsplog.SetVerbose(1)
	NewAuxTestSystem(t, 1, doserverstopconns, 10, auxparams(5, 500))
}
Пример #17
0
func NewAuxTestSystem(t *testing.T, nclients int, mode int, maxepochs int,
	params *LspParams) {
	fmt.Printf("Testing: Mode %s, %d clients\n", ModeName[mode], nclients)
	ts := new(AuxTestSystem)
	ts.Mode = mode
	ts.Params = params
	ts.ClientChan = make(chan bool)
	ts.ServerChan = make(chan bool)
	ts.TimeChan = make(chan bool)
	ts.Clients = make([]*LspClient, nclients)
	ts.Nclients = nclients
	ts.Nmessages = 10
	ts.Rgen = *rand.New(rand.NewSource(time.Now().Unix()))
	ts.Port = randport(ts.Rgen)
	ts.RunFlag = true
	ts.Tester = t
	go ts.BuildServer()
	for i := 0; i < nclients; i++ {
		go ts.BuildClient(i)
	}
	go ts.runtimeout(float64(maxepochs))

	switch ts.Mode {
	case doclientstop:
		// Wait for server or timer to complete
		select {
		case sok := <-ts.ServerChan:
			if !sok {
				ts.Tester.Logf("Server error\n")
				ts.Tester.FailNow()
			}
		case <-ts.TimeChan:
			ts.Tester.Logf("Test timed out waiting for server\n")
			ts.Tester.FailNow()
		}
		lsplog.Vlogf(0, "Server completed\n")
		// Wait for the clients
		for i := 0; i < nclients; i++ {
			select {
			case c*k := <-ts.ClientChan:
				if !c*k {
					ts.Tester.Logf("Client error\n")
					ts.Tester.FailNow()
				}
			case <-ts.TimeChan:
				ts.Tester.Logf("Test timed out waiting for client\n")
				ts.Tester.FailNow()
			}
		}
		lsplog.Vlogf(0, "Clients completed\n")
	default: // Includes stopserver
		// Wait for the clients
		for i := 0; i < nclients; i++ {
			select {
			case c*k := <-ts.ClientChan:
				if !c*k {
					ts.Tester.Logf("Client error\n")
					ts.Tester.FailNow()
				}
			case <-ts.TimeChan:
				ts.Tester.Logf("Test timed out waiting for client\n")
				ts.Tester.FailNow()
			}
		}
		// Wait for server or timer to complete
		select {
		case sok := <-ts.ServerChan:
			if !sok {
				ts.Tester.Logf("Server error\n")
				ts.Tester.FailNow()
			}
		case <-ts.TimeChan:
			ts.Tester.Logf("Test timed out waiting for server\n")
			ts.Tester.FailNow()
		}
	}
	lsplog.SetVerbose(AuxDefaultVerbosity)
}
Пример #18
0
func TestRoundTrip2(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 3, 10, doroundtrip, 12, synchparams(5, 500))
}
Пример #19
0
func TestRoundTrip3(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 5, 500, doroundtrip, 20, synchparams(5, 2000))
}
Пример #20
0
func TestServerFastClose2(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 3, 10, doserverfastclose, 12, synchparams(5, 500))
}
Пример #21
0
func TestServerFastClose3(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 5, 500, doserverfastclose, 20, synchparams(5, 2000))
}
Пример #22
0
func TestServerToClient2(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 3, 10, doservertoclient, 12, synchparams(5, 500))
}
Пример #23
0
func TestServerToClient3(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 5, 500, doservertoclient, 20, synchparams(5, 2000))
}
Пример #24
0
func TestClientToServer2(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 3, 10, doclienttoserver, 12, synchparams(5, 500))
}
Пример #25
0
func TestStopClient2(t *testing.T) {
	lsplog.SetVerbose(1)
	NewAuxTestSystem(t, 3, doclientstop, 15, auxparams(5, 500))
}
Пример #26
0
func TestClientToServer3(t *testing.T) {
	lsplog.SetVerbose(3)
	NewSynchTestSystem(t, 5, 500, doclienttoserver, 20, synchparams(5, 2000))
}
Пример #27
0
func TestSlowStart2(t *testing.T) {
	lsplog.SetVerbose(1)
	NewAuxTestSystem(t, 3, doslowstart, 5, auxparams(5, 500))
}
Пример #28
0
func TestStopServerConns2(t *testing.T) {
	lsplog.SetVerbose(1)
	NewAuxTestSystem(t, 3, doserverstopconns, 5, auxparams(2, 500))
}