diff --git a/core_impl.go b/core_impl.go index de75322..217b2b7 100644 --- a/core_impl.go +++ b/core_impl.go @@ -200,7 +200,9 @@ func NewCustomDiff(globalDiff uint64) *CustomDiff { return &CustomDiff{globalDiff: globalDiff} } -// OnLogin parses +N suffixes and applies global difficulty fallbacks. +// OnLogin normalises the login user once during handshake. +// +// cd.OnLogin(proxy.Event{Miner: &proxy.Miner{user: "WALLET+50000"}}) func (cd *CustomDiff) OnLogin(e Event) { if cd == nil || e.Miner == nil { return @@ -225,6 +227,10 @@ func NewRateLimiter(config RateLimit) *RateLimiter { } // Allow returns true if the IP address is permitted to open a new connection. +// +// if rl.Allow("203.0.113.42:3333") { +// // accept the socket +// } func (rl *RateLimiter) Allow(ip string) bool { if rl == nil || rl.config.MaxConnectionsPerMinute <= 0 { return true diff --git a/state_impl.go b/state_impl.go index 3a4e721..36acf64 100644 --- a/state_impl.go +++ b/state_impl.go @@ -916,13 +916,13 @@ func (m *Miner) handleLogin(req stratumRequest) { m.loginAlgos = append([]string(nil), params.Algo...) m.extAlgo = len(m.loginAlgos) > 0 m.rpcID = generateUUID() - m.state = MinerStateWaitReady if m.onLogin != nil { m.onLogin(m) } if m.state == MinerStateClosing { return } + m.state = MinerStateWaitReady if m.extNH { if m.MapperID() < 0 { m.state = MinerStateWaitLogin @@ -1556,16 +1556,14 @@ func cloneWorkerRecord(record WorkerRecord) WorkerRecord { return cloned } -// Apply parses login suffixes and applies the configured global difficulty. +// Apply normalises one miner login at the same point the handshake does. +// +// cd.Apply(&proxy.Miner{user: "WALLET+50000"}) func (cd *CustomDiff) Apply(miner *Miner) { if cd == nil || miner == nil { return } - if miner.customDiffResolved { - return - } - miner.user, miner.customDiff = parseLoginUser(miner.user, cd.globalDiff) - miner.customDiffResolved = true + cd.OnLogin(Event{Miner: miner}) } // NewServer constructs a server instance.