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)) } }
func iNewLspClient(hostport string, params *LspParams) (*LspClient, error) { cli := new(LspClient) cli.params = HandleParams(params) cli.sent = list.New() cli.sentLocker = make(chan int, 1) cli.sentLocker <- 1 // To make it unlocked at the beginning. cli.read = abuf.NewBuf() cli.udpAddr, _ = UDPResolve(hostport) cli.connectedSyncer = make(chan int, 1) cli.connectionLocker = make(chan int, 1) cli.connectionLocker <- 1 cli.epochLocker = make(chan int, 1) cli.epochLocker <- 1 cli.lspConnect() cli.serverSeqNum = 1 return cli, nil }
func iNewLspServer(port int, params *LspParams) (*LspServer, error) { srv := new(LspServer) srv.params = HandleParams(params) srv.clients = make(map[string]*clientRepresenter) srv.sent = list.New() srv.sentLocker = make(chan int, 1) srv.sentLocker <- 1 srv.read = abuf.NewBuf() addr, e := UDPResolve("127.0.0.1:" + strconv.Itoa(port)) if e != nil { lsplog.CheckFatal(e) return nil, e } srv.udpAddr = addr e = srv.lspListen() if e != nil { lsplog.CheckFatal(e) return nil, e } go srv.networkHandler() go srv.epochHandler() return srv, nil }