예제 #1
0
파일: textui.go 프로젝트: piotrnar/gocoin
func show_mem(p string) {
	al, sy := sys.MemUsed()

	fmt.Println("Allocated:", al>>20, "MB")
	fmt.Println("SystemMem:", sy>>20, "MB")

	if p == "" {
		return
	}
	if p == "free" {
		fmt.Println("Freeing the mem...")
		sys.FreeMem()
		show_mem("")
		return
	}
	if p == "gc" {
		fmt.Println("Running GC...")
		runtime.GC()
		fmt.Println("Done.")
		return
	}
	i, e := strconv.ParseInt(p, 10, 64)
	if e != nil {
		println(e.Error())
		return
	}
	debug.SetGCPercent(int(i))
	fmt.Println("GC treshold set to", i, "percent")
}
예제 #2
0
파일: config.go 프로젝트: liudch/gocoin
func p_cfg(w http.ResponseWriter, r *http.Request) {
	if !ipchecker(r) {
		return
	}

	common.LockCfg()
	defer common.UnlockCfg()

	if r.Method == "POST" {
		if len(r.Form["configjson"]) > 0 {
			e := json.Unmarshal([]byte(r.Form["configjson"][0]), &common.CFG)
			if e == nil {
				common.Reset()
			}
			if len(r.Form["save"]) > 0 {
				common.SaveConfig()
			}
			http.Redirect(w, r, "/", http.StatusFound)
			return
		}

		if len(r.Form["walletdata"]) > 0 && len(r.Form["walletfname"]) > 0 {
			fn := r.Form["walletfname"][0]
			if fn != "" {
				fn = common.CFG.Walletdir + string(os.PathSeparator) + fn
				ioutil.WriteFile(fn, []byte(r.Form["walletdata"][0]), 0660)
				wallet.LoadWallet(fn)
			}
			http.Redirect(w, r, "/wal", http.StatusFound)
			return
		}

		if len(r.Form["shutdown"]) > 0 {
			usif.Exit_now = true
			w.Write([]byte("Your node should shut down soon"))
			return
		}

		return
	}

	// for any other GET we need a matching session-id
	if !checksid(r) {
		new_session_id(w)
		return
	}

	if len(r.Form["txponoff"]) > 0 {
		common.CFG.TXPool.Enabled = !common.CFG.TXPool.Enabled
		http.Redirect(w, r, "txs", http.StatusFound)
		return
	}

	if len(r.Form["txronoff"]) > 0 {
		common.CFG.TXRoute.Enabled = !common.CFG.TXRoute.Enabled
		http.Redirect(w, r, "txs", http.StatusFound)
		return
	}

	if len(r.Form["lonoff"]) > 0 {
		common.SetListenTCP(!common.IsListenTCP(), true)
		http.Redirect(w, r, "net", http.StatusFound)
		return
	}

	if len(r.Form["drop"]) > 0 {
		network.DropPeer(r.Form["drop"][0])
		http.Redirect(w, r, "net", http.StatusFound)
		return
	}

	if len(r.Form["savecfg"]) > 0 {
		dat, _ := json.Marshal(&common.CFG)
		if dat != nil {
			ioutil.WriteFile(common.ConfigFile, dat, 0660)
		}
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	if len(r.Form["beepblock"]) > 0 {
		common.CFG.Beeps.NewBlock = !common.CFG.Beeps.NewBlock
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	if len(r.Form["freemem"]) > 0 {
		sys.FreeMem()
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	if len(r.Form["mid"]) > 0 {
		v, e := strconv.ParseUint(r.Form["mid"][0], 10, 32)
		if e == nil && v < uint64(len(common.MinerIds)) {
			common.CFG.Beeps.MinerID = string(common.MinerIds[v].Tag)
		} else {
			common.CFG.Beeps.MinerID = ""
		}
		http.Redirect(w, r, "miners", http.StatusFound)
		return
	}

}
예제 #3
0
파일: usif.go 프로젝트: vancsj/gocoin
func do_usif() {
	time.Sleep(1e9)
	usif_prompt()
	for {
		cmd := readline()
		go func(cmd string) {
			ll := strings.Split(cmd, " ")
			if len(ll) > 0 {
				switch ll[0] {
				case "g":
					if GetRunPings() {
						SetRunPings(false)
						fmt.Println("Goto download phase...")
						time.Sleep(3e8)
					} else {
						fmt.Println("Already in download phase?")
					}

				case "a":
					AddrMutex.Lock()
					fmt.Println(len(AddrDatbase), "addressess in the database")
					AddrMutex.Unlock()

				case "q":
					GlobalExit = true
					SetRunPings(false)
					SetDoBlocks(false)
					SetAllHeadersDone(true)
					return

				case "bm":
					fmt.Println("Trying BlocksMutex")
					BlocksMutex.Lock()
					fmt.Println("BlocksMutex locked")
					BlocksMutex.Unlock()
					fmt.Println("BlocksMutex unlocked")

				case "b":
					if TheBlockChain != nil {
						fmt.Println(TheBlockChain.Stats())
					}

				case "db":
					qdb_stats()

				case "n":
					show_connections()

				case "i":
					print_stats()

				case "c":
					print_counters()

				case "s":
					save_peers()

				case "pr":
					show_inprogress()

				case "pe":
					show_pending()

				case "d":
					if len(ll) > 1 {
						n, e := strconv.ParseUint(ll[1], 10, 32)
						if e == nil {
							open_connection_mutex.Lock()
							for _, v := range open_connection_list {
								if v.id == uint32(n) {
									fmt.Println("dropping peer id", n, "...")
									v.setbroken(true)
								}
							}
							open_connection_mutex.Unlock()
						}
					} else {
						if GetRunPings() {
							fmt.Println("dropping longest ping")
							drop_longest_ping()
						} else {
							fmt.Println("dropping slowest peers")
							drop_slowest_peers()
						}
					}

				case "f":
					show_free_mem()
					sys.FreeMem()
					show_free_mem()
					fmt.Println("To free more memory, quit (q command) and relaunch the downloader")

				case "m":
					show_free_mem()

				case "mc":
					if len(ll) > 1 {
						n, e := strconv.ParseUint(ll[1], 10, 32)
						if e == nil {
							MaxNetworkConns = uint(n)
							fmt.Println("MaxNetworkConns set to", n)
						}
					}

				case "h":
					fallthrough
				case "?":
					fmt.Println("Available commands:")
					fmt.Println(" g - go to next phase")
					fmt.Println(" a - show addressess of the peers")
					fmt.Println(" q - quite the downloader")
					fmt.Println(" b - show blockchin stats")
					fmt.Println(" db - show database stats")
					fmt.Println(" n - show network connections")
					fmt.Println(" i - show general info")
					fmt.Println(" c - show counters")
					fmt.Println(" s - save peers")
					fmt.Println(" pr - show blocks in progress")
					fmt.Println(" pe - show pending blocks ")
					fmt.Println(" d [conid] - drop one connection")
					fmt.Println(" f - free memory")
					fmt.Println(" m - show mem heap info")
					fmt.Println(" mc <CNT> - set maximum number of connections")

				default:
					fmt.Println("Unknown command:", ll[0], " (h or ? - to see help)")
				}
			}
			usif_prompt()
		}(cmd)
	}
	fmt.Println("do_usif terminated")
}