区块链初学教程open-ethereum-pool矿池源码领会

  伯仲连区块链教程open-ethereum-pool矿池源码领会policy模块,2021年下星期,区块链行业正渐渐褪去兴盛之初的烦躁...

区块链初学教程open-ethereum-pool矿池源码领会

  伯仲连区块链教程open-ethereum-pool矿池源码领会policy模块,2021年 下星期,区块链行业正渐渐褪去兴盛之初的烦躁、回归理性,外表上看关系人才需要与身价犹如正在回落区块链伯仲。但究竟上,恰是前期泡沫的渐退,让人们更多的关心点放在了区块链真实的本领之上。

  open-ethereum-pooleth矿池-policy模块

  policyserver设置

  type policyserver struct {

  sync.rwmutex

  statsmu sync.mutex

  config *config

  stats map[string]*stats

  banchannel chan string

  startedat int64

  grace int64

  timeout int64

  blacklist []string

  whitelist []string

  storage *storage.redisclient

  getblacklist和getwhitelist

  // always returns list of addresses. if redis fails it will return empty list.

  func (r *redisclient) getblacklist() ([]string, error) {

  //smembers eth:blacklist

  //smembers 吩咐归来汇合中的一切的分子

  cmd := r.client.smembers(r.formatkey("blacklist"))

  if cmd.err() != nil {

  return []string{}, cmd.err()

  return cmd.val(), nil

  // always returns list of ips. if redis fails it will return empty list.

  func (r *redisclient) getwhitelist() ([]string, error) {

  //smembers eth:whitelist

  //smembers 吩咐归来汇合中的一切的分子

  cmd := r.client.smembers(r.formatkey("whitelist"))

  if cmd.err() != nil {

  return []string{}, cmd.err()

  return cmd.val(), nil

  isbanned

  func (s *policyserver) isbanned(ip string) bool {

  x := s.get(ip)

  return atomic.loadint32(&x.banned) > 0

  func (s *policyserver) get(ip string) *stats {

  s.statsmu.lock()

  defer s.statsmu.unlock()

  if x, ok := s.stats[ip]; !ok {

  x = s.newstats()

  s.stats[ip] = x

  return x

  } else {

  x.heartbeat()

  return x

  func (s *policyserver) newstats() *stats {

  x := &stats{

  connlimit: s.config.limits.limit,

  x.heartbeat()

  return x

  处置applymalformedpolicy

  //运用方法缺点的战略

  //malformedlimit为5次

  func (s *policyserver) applymalformedpolicy(ip string) bool {

  x := s.get(ip)

  n := x.incrmalformed()

  if n >= s.config.banning.malformedlimit {

  s.forceban(x, ip)

  return false

  return true

  func (x *stats) incrmalformed() int32 {

  return atomic.addint32(&x.malformed, 1)

  func (s *policyserver) forceban(x *stats, ip string) {

  //没起用banning或在白名单

  if !s.config.banning.enabled || s.inwhitelist(ip) {

  return

  atomic.storeint64(&x.bannedat, util.maketimestamp())

  //x.banned赋值为1

  if atomic.compareandswapint32(&x.banned, 0, 1) {

  //"ipset": "blacklist",

  if len(s.config.banning.ipset) > 0 {

  s.banchannel <- ip

  } else {

  log.println("banned peer", ip)

  处置applyloginpolicy

  func (s *policyserver) applyloginpolicy(addy, ip string) bool {

  if s.inblacklist(addy) {

  x := s.get(ip)

  s.forceban(x, ip)

  return false

  return true

  func (s *policyserver) inblacklist(addy string) bool {

  s.rlock()

  defer s.runlock()

  return util.stringinslice(addy, s.blacklist)

  处置applyloginpolicy

  func (s *policyserver) applysharepolicy(ip string, validshare bool) bool {

  x := s.get(ip)

  x.lock()

  if validshare {

  x.validshares++

  if s.config.limits.enabled {

  //increase allowed number of connections on each valid share

  //每个灵验share不妨减少的贯穿数

  //"limitjump": 10

  x.incrlimit(s.config.limits.limitjump)

  } else {

  x.invalidshares++

  totalshares := x.validshares + x.invalidshares

  //check after after miner submitted this number of shares

  //30个shares后查看

  //"checkthreshold": 30,

  if totalshares < s.config.banning.checkthreshold {

  x.unlock()

  return true

  validshares := float32(x.validshares)

  invalidshares := float32(x.invalidshares)

  x.resetshares()

  x.unlock()

  //失效share比率

  ratio := invalidshares / validshares

  // percent of invalid shares from all shares to ban miner

  //"invalidpercent": 30,

  if ratio >= s.config.banning.invalidpercent/100.0 {

  s.forceban(x, ip)

  return false

  return true

  //加

  func (x *stats) incrlimit(n int32) {

  atomic.addint32(&x.connlimit, n)

  //reset

  func (x *stats) resetshares() {

  x.validshares = 0

  x.invalidshares = 0

  处置applylimitpolicy

  func (s *policyserver) applylimitpolicy(ip string) bool {

  if !s.config.limits.enabled {

  return true

  now := util.maketimestamp()

  //"grace": "5m",

  if now-s.startedat > s.grace {

  //减1

  return s.get(ip).decrlimit() > 0

  return true

  func (x *stats) decrlimit() int32 {

  return atomic.addint32(&x.connlimit, -1)

  处置banclient

  func (s *policyserver) banclient(ip string) {

  x := s.get(ip)

  s.forceban(x, ip)

本文转载自互联网,如有侵权,联系删除

相关推荐

区块链和玩耍篇

区块链和玩耍篇

  提起玩耍,各别岁月的人都有着各别的回顾,从早期红白键的任天国,传说、谎话西游的炽热,在到现此刻王者光彩、吃鸡...

专栏 2021.11.27 0 0

评论列表
  • 我Bitpie钱包收到的HT要转到火币erc20和trc20哪一个?哪位大神给指教下!

    2021-11-04 13:02:55 回复该评论
  • 都被强权控制,只有我们币圈,没有一个特定的强权控制

    2021-11-04 13:02:55 回复该评论
  • 大家疯涌进来的时候价格6.7,现在大家都走的话就便宜卖了,6.5给你出去

    2021-11-04 13:02:55 回复该评论
  • BananaEX社区交易已上线

    2021-11-04 17:15:17 回复该评论
  • 会有机会的,祝各位老板都发财!!

    2021-11-04 17:15:17 回复该评论
  • 我562,,空他,610,,也给我干爆了

    2021-11-04 17:15:17 回复该评论
  • 这轮行情才是其他币的噩梦啊,大吸血

    2021-11-04 17:15:17 回复该评论