示例#1
0
文件: srunner.go 项目: nunu0129/p1
func runServer(srv lsp.Server) {
	for {
		// Read message from client.
		if id, payload, err := srv.Read(); err != nil {
			fmt.Printf("Client %d has died: %s\n", id, err)
		} else {
			log.Printf("Server received '%s' from client %d\n", string(payload), id)
			// Echo message back to client.
			if err := srv.Write(id, payload); err != nil {
				// Print an error message and continue...
				fmt.Printf("Server failed to write to connection %d: %s\n", id, err)
			} else {
				log.Printf("Server wrote '%s' to client %d\n", string(payload), id)
			}
		}
	}
}
示例#2
0
文件: server.go 项目: wdbaruni/dbm
func (yy *Scheduler) assign(mlx *log.Logger, s lsp.Server) {

	yy.jobgiveup = false
	hold := yy.pendjobs[yy.currid]
	yy.curclient = yy.pendclients[yy.currid]
	mlx.Println("begin assign job: ", yy.currid, hold.String(), " for client: ", yy.curclient, " with ", len(yy.miner), " miners")
	delete(yy.pendjobs, yy.currid)
	delete(yy.pendclients, yy.currid)
	var block uint64
	block = (hold.Upper) / uint64(len(yy.miner))
	if hold.Upper%uint64(len(yy.miner)) != 0 {
		//mlx.Println("left ", hold.Upper%uint64(len(yy.miner)))
		block += 1
	}
	yy.ans1 = 1<<64 - 1
	yy.ans2 = hold.Upper
	yy.block = len(yy.miner)
	// 41 5
	var ct uint64
	ct = 0
	fk := block + 1
	//mlx.Println("block size: ", fk)
	limit := hold.Upper
	for i, _ := range yy.miner {

		hold.Lower = ct * fk
		hold.Upper = hold.Lower + block
		if hold.Upper > limit {
			hold.Upper = limit
		}
		temp := bitcoin.NewRequest(hold.Data, hold.Lower, hold.Upper)
		mlx.Println("assign miner", i, hold.Lower, hold.Upper)
		ct += 1
		buf, _ := json.Marshal(hold)
		errr := s.Write(i, buf)
		yy.miner[i] = temp
		if errr != nil {
			mlx.Println("miner: ", i, " fail in the middle")
			yy.minerfail += 1
			yy.pendrange[i] = temp
			delete(yy.miner, i)
		}
	}
	yy.run = true
}
示例#3
0
文件: server.go 项目: wdbaruni/dbm
func (yy *Scheduler) reassign(mlx *log.Logger, s lsp.Server) {
	if len(yy.pendrange) != 0 {

		mlx.Println("begin ressign job", yy.currid)
		for j, k := range yy.pendrange {
			for i, v := range yy.miner {
				if v == nil {
					//mlx.Println("try to reallocate lost jobs to miner", i)
					yy.miner[i] = k
					buf, _ := json.Marshal(yy.miner[i])
					errr := s.Write(i, buf)
					if errr != nil {
						delete(yy.miner, i)
					} else {
						yy.minerfail -= 1
						delete(yy.pendrange, j)
						break
					}
				}
			}
		}
	}
}