Beispiel #1
0
func show_mem(p string) {
	al, sy := sys.MemUsed()

	fmt.Println("Allocated:", al>>20, "MB")
	fmt.Println("SystemMem:", sy>>20, "MB")
	fmt.Println("QDB Extra:", qdb.ExtraMemoryConsumed>>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")
}
Beispiel #2
0
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 "a":
					fmt.Println(peersdb.PeerDB.Count(), "addressess in the database")

				case "q":
					Exit()
					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 "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 {
						fmt.Println("dropping slowest peer")
						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(" a - show addressess of the peers")
					fmt.Println(" b - show blockchin stats")
					fmt.Println(" q - quit the downloader")
					fmt.Println(" c - show counters")
					fmt.Println(" d [conid] - drop one connection")
					fmt.Println(" db - show database stats")
					fmt.Println(" f - free memory")
					fmt.Println(" i - show general info")
					fmt.Println(" m - show mem heap info")
					fmt.Println(" mc <CNT> - set maximum number of connections")
					fmt.Println(" n - show network connections")
					fmt.Println(" pe - show pending blocks ")
					fmt.Println(" pr - show blocks in progress")

				default:
					fmt.Println("Unknown command:", ll[0], " (h or ? - to see help)")
				}
			}
			usif_prompt()
		}(cmd)
	}
	fmt.Println("do_usif terminated")
}
Beispiel #3
0
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
	}

}