Skip to content

Commit

Permalink
fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
swordlet committed Aug 1, 2023
1 parent fe9e163 commit 0d1f8a3
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 57 deletions.
7 changes: 6 additions & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ module github.com/swordlet/xmrig2xdag
go 1.17

require (
github.com/didip/tollbooth v4.0.2+incompatible
github.com/kelseyhightower/envconfig v1.4.0
github.com/pkg/errors v0.9.1
github.com/powerman/rpc-codec v1.2.2
github.com/sourcegraph/jsonrpc2 v0.1.0
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
golang.org/x/time v0.3.0
)

require (
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
golang.org/x/time v0.3.0 // indirect
)
4 changes: 4 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
github.com/didip/tollbooth v4.0.2+incompatible h1:fVSa33JzSz0hoh2NxpwZtksAzAgd7zjmGO20HCZtF4M=
github.com/didip/tollbooth v4.0.2+incompatible/go.mod h1:A9b0665CE6l1KmzpDws2++elm/CsuWBMa5Jv4WY0PEY=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/powerman/rpc-codec v1.2.2 h1:BK0JScZivljhwW/vLLhZLtUgqSxc/CD3sHEs8LiwwKw=
Expand Down
2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

var (
version = "2.0.1"
version = "2.0.2"

// cmd line options
configFile *string
Expand Down
2 changes: 2 additions & 0 deletions server/proxy/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"strconv"
"time"

"github.com/sourcegraph/jsonrpc2"
"github.com/swordlet/xmrig2xdag/logger"
Expand Down Expand Up @@ -115,6 +116,7 @@ func (m *Mining) Getjob(p PassThruParams, resp *Job) error {
// But the coinhive miner doesn't care, it just doesn't keep up with submissions.
func (m *Mining) Submit(p PassThruParams, resp *StatusReply) error {
worker := m.getWorker(p.Context())
worker.Conn().SetReadDeadline(time.Now().Add(45 * time.Second))
status, err := worker.Proxy().Submit(p)
if err != nil {
return err
Expand Down
66 changes: 33 additions & 33 deletions server/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type Worker interface {
// Disconnect closes the connection to the proxy from the worker.
// Ideally it sets up the worker to try and reconnect to a new proxy through the director.
Disconnect()

Conn() net.Conn
Close()

NewJob(*Job)
Expand Down Expand Up @@ -142,17 +142,17 @@ func NewProxy(id uint64) *Proxy {
miniResult: math.MaxUint64,
notify: make(chan []byte, 2),
}
go p.deleteIdle()
// go p.deleteIdle()

p.SS = stratum.NewServer()
p.SS.RegisterName("mining", &Mining{})
return p
}

func (p *Proxy) deleteIdle() {
<-time.After(35 * time.Second)
p.Delete()
}
// func (p *Proxy) deleteIdle() {
// <-time.After(35 * time.Second)
// p.Delete()
// }

func (p *Proxy) Run(minerName string) {
retryTimes := 3
Expand Down Expand Up @@ -289,8 +289,8 @@ func (p *Proxy) handleNotification(notif []byte) {
}

func (p *Proxy) connect(minerName string) error {
p.connMu.Lock()
defer p.connMu.Unlock()
// p.connMu.Lock()
// defer p.connMu.Unlock()

var conn net.Conn
var socks5Dialer proxy.Dialer
Expand Down Expand Up @@ -443,31 +443,31 @@ func (p *Proxy) Close() {
p.isClosed = true
}

func (p *Proxy) Delete() {
p.connMu.Lock()
defer p.connMu.Unlock()

if p.isClosed {
return
}

if p.Conn != nil && p.Conn.ConnID > 0 {
return
}

if p.worker != nil {
p.worker.Close()
}
close(p.done)
p.director.removeProxy(p.ID)
p.worker = nil
p.SS = nil
p.director = nil

logger.Get().Printf("Proxy[%d] idle deleted", p.ID)
p.Conn = nil
p.isClosed = true
}
// func (p *Proxy) Delete() {
// p.connMu.Lock()
// defer p.connMu.Unlock()

// if p.isClosed {
// return
// }

// if p.Conn != nil && p.Conn.ConnID > 0 {
// return
// }

// if p.worker != nil {
// p.worker.Close()
// }
// close(p.done)
// p.director.removeProxy(p.ID)
// p.worker = nil
// p.SS = nil
// p.director = nil

// logger.Get().Printf("Proxy[%d] idle deleted", p.ID)
// p.Conn = nil
// p.isClosed = true
// }

func (p *Proxy) handleSubmit(s *share) (err error) {
defer func() {
Expand Down
20 changes: 12 additions & 8 deletions server/stratum/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"encoding/json"
"errors"
"io"
"net/http"
"net/rpc"
"sync"

"github.com/didip/tollbooth"
"github.com/swordlet/xmrig2xdag/config"
)

type serverCodec struct {
Expand Down Expand Up @@ -105,14 +109,14 @@ func (s *Server) ServeCodec(codec rpc.ServerCodec) {
s.Server.ServeCodec(codec)
}

// func (s *Server) HandleHTTP(rpcPath, debugPath string) {
// limit := config.Get().RateLimit
// if limit == 0 {
// limit = 1
// }
// http.Handle(rpcPath, tollbooth.LimitFuncHandler(tollbooth.NewLimiter(float64(limit), nil), s.ServeHTTP))
// // http.Handle(debugPath, debugHTTP{server})
// }
func (s *Server) HandleHTTP(rpcPath, debugPath string) {
limit := config.Get().RateLimit
if limit == 0 {
limit = 1
}
http.Handle(rpcPath, tollbooth.LimitFuncHandler(tollbooth.NewLimiter(float64(limit), nil), s.ServeHTTP))
// http.Handle(debugPath, debugHTTP{server})
}

func (s *Server) ServeConn(ctx context.Context, conn io.ReadWriteCloser) {
s.ServeCodec(NewDefaultServerCodecContext(ctx, conn))
Expand Down
25 changes: 12 additions & 13 deletions server/tcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/swordlet/xmrig2xdag/config"
"github.com/swordlet/xmrig2xdag/logger"
"golang.org/x/time/rate"
)

func StartServer() {
Expand Down Expand Up @@ -37,24 +36,24 @@ func StartServer() {
" Listen failed with error: ", listenErr)
return
}
rl := config.Get().RateLimit
if rl == 0 {
rl = 1
}
ra := rate.Every(25 * time.Millisecond)
limit := rate.NewLimiter(ra, rl)
// rl := config.Get().RateLimit
// if rl == 0 {
// rl = 1
// }
// ra := rate.Every(25 * time.Millisecond)
// limit := rate.NewLimiter(ra, rl)
for {
conn, err := listener.Accept()
if err != nil {
logger.Get().Println("Unable to accept connection: ", err)
}
// conn.SetDeadline(time.Now().Add(45 * time.Second))
conn.SetReadDeadline(time.Now().Add(90 * time.Second))

if !limit.Allow() {
logger.Get().Println("Out of rate limit:", rl, "per 100 ms.")
conn.Close()
continue
}
// if !limit.Allow() {
// logger.Get().Println("Out of rate limit:", rl, "per 25 ms.")
// conn.Close()
// continue
// }
go SpawnWorker(conn)
}
}
1 change: 0 additions & 1 deletion server/tcp/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (w *Worker) NewJob(j *proxy.Job) {
w.Disconnect()
}
// other actions? shut down worker?
// w.Conn().SetDeadline(time.Now().Add(45 * time.Second))
}

func (w *Worker) expectedHashes() uint32 {
Expand Down

0 comments on commit 0d1f8a3

Please sign in to comment.