From e3394173350e663786d56d900e39435cedd9acd3 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Wed, 19 Jul 2023 00:31:27 +0200 Subject: [PATCH] Unknown request method eth_submitHashrate from ( ip) --- proxy/handlers.go | 15 ++++++++------- proxy/stratum.go | 7 ++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/proxy/handlers.go b/proxy/handlers.go index 7efc91f..40be410 100644 --- a/proxy/handlers.go +++ b/proxy/handlers.go @@ -1,6 +1,7 @@ package proxy import ( + "fmt" "log" "regexp" "strings" @@ -173,10 +174,10 @@ func (s *ProxyServer) handleGetBlockByNumberRPC() *rpc.GetBlockReplyPart { return reply } -// handleUnknownRPC handles an unknown RPC request method. -// It logs an error and returns an error reply. -func (s *ProxyServer) handleUnknownRPC(cs *Session, m string) *ErrorReply { - log.Printf("Unknown request method %s from %s", m, cs.ip) - s.policy.ApplyMalformedPolicy(cs.ip) - return &ErrorReply{Code: -3, Message: "Method not found"} -} +// handleUnknownRPC handles incoming requests with unknown methods +func (s *ProxyServer) handleUnknownRPC(cs *Session, method string) *ErrorReply { + // Implement your logic for handling unknown methods here + // For example, you can return a custom error indicating that the method is not supported + errMsg := fmt.Sprintf("Method %s not supported", method) + return &ErrorReply{Code: -32601, Message: errMsg} +} \ No newline at end of file diff --git a/proxy/stratum.go b/proxy/stratum.go index d412867..a6f1e2e 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "encoding/json" "errors" + "fmt" "io" "log" "math/rand" @@ -392,8 +393,12 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { return cs.sendTCPResult(req.Id, &reply) case "eth_submitHashrate": - return cs.sendTCPResult(req.Id, true) + // Return an error indicating that the method is not supported + errMsg := fmt.Sprintf("Method %s not supported", req.Method) + errReply := &ErrorReply{Code: -32601, Message: errMsg} + return cs.sendTCPError(req.Id, errReply) default: + // Handle unknown methods errReply := s.handleUnknownRPC(cs, req.Method) return cs.sendTCPError(req.Id, errReply) }