|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package proxy |
|
|
|
package proxy |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
@ -21,6 +22,8 @@ func (s *ProxyServer) handleLoginRPC(cs *Session, params []string, id string) (b |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
login := strings.ToLower(params[0]) |
|
|
|
login := strings.ToLower(params[0]) |
|
|
|
|
|
|
|
login = strings.Split(login, ".")[0] |
|
|
|
|
|
|
|
|
|
|
|
if !util.IsValidHexAddress(login) { |
|
|
|
if !util.IsValidHexAddress(login) { |
|
|
|
return false, &ErrorReply{Code: -1, Message: "Invalid login"} |
|
|
|
return false, &ErrorReply{Code: -1, Message: "Invalid login"} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -68,22 +71,22 @@ func (s *ProxyServer) handleSubmitRPC(cs *Session, login, id string, params []st |
|
|
|
log.Printf("Malformed PoW result from %s@%s %v", login, cs.ip, params) |
|
|
|
log.Printf("Malformed PoW result from %s@%s %v", login, cs.ip, params) |
|
|
|
return false, &ErrorReply{Code: -1, Message: "Malformed PoW result"} |
|
|
|
return false, &ErrorReply{Code: -1, Message: "Malformed PoW result"} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
go func(s *ProxyServer, cs *Session, login, id string, params []string) { |
|
|
|
t := s.currentBlockTemplate() |
|
|
|
t := s.currentBlockTemplate() |
|
|
|
exist, validShare := s.processShare(login, id, cs.ip, t, params) |
|
|
|
exist, validShare := s.processShare(login, id, cs.ip, t, params) |
|
|
|
ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare) |
|
|
|
ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare) |
|
|
|
|
|
|
|
|
|
|
|
if exist { |
|
|
|
if exist { |
|
|
|
log.Printf("Duplicate share from %s@%s %v", login, cs.ip, params) |
|
|
|
log.Printf("Duplicate share from %s@%s %v", login, cs.ip, params) |
|
|
|
return false, &ErrorReply{Code: 22, Message: "Duplicate share"} |
|
|
|
cs.lastErr = errors.New("Duplicate share") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !validShare { |
|
|
|
if !validShare { |
|
|
|
log.Printf("Invalid share from %s@%s", login, cs.ip) |
|
|
|
log.Printf("Invalid share from %s@%s", login, cs.ip) |
|
|
|
// Bad shares limit reached, return error and close
|
|
|
|
// Bad shares limit reached, return error and close
|
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
return false, &ErrorReply{Code: 23, Message: "Invalid share"} |
|
|
|
cs.lastErr = errors.New("Invalid share") |
|
|
|
} |
|
|
|
} |
|
|
|
return false, nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if s.config.Proxy.Debug { |
|
|
|
if s.config.Proxy.Debug { |
|
|
|
@ -91,10 +94,13 @@ func (s *ProxyServer) handleSubmitRPC(cs *Session, login, id string, params []st |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
return true, &ErrorReply{Code: -1, Message: "High rate of invalid shares"} |
|
|
|
cs.lastErr = errors.New("High rate of invalid shares") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}(s, cs, login, id, params) |
|
|
|
|
|
|
|
|
|
|
|
return true, nil |
|
|
|
return true, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *ProxyServer) handleGetBlockByNumberRPC() *rpc.GetBlockReplyPart { |
|
|
|
func (s *ProxyServer) handleGetBlockByNumberRPC() *rpc.GetBlockReplyPart { |
|
|
|
t := s.currentBlockTemplate() |
|
|
|
t := s.currentBlockTemplate() |
|
|
|
var reply *rpc.GetBlockReplyPart |
|
|
|
var reply *rpc.GetBlockReplyPart |
|
|
|
|