Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyFFM committed Jun 15, 2019
1 parent d1f7419 commit 2396457
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
listenAddr: "127.0.0.1:7777" # address proxy listens on
scanTime: 20 # your maximum scantime in seconds (collision avoidance)
displayMiners: true # displays info on connected miners at the beginning of each round

#primary chain
primarySubmitURL: "http://50-50-pool.burst.cryptoguru.org:8124" # primary chain: url to forward nonces to (pool, wallet)
primaryTargetDeadline: 31536000 # primary chain: target deadline
primaryPassphrase: "" # primary chain: passphrase overwrite (optional), empty -> passphrase from client will be forwarded if any
primaryIpForwarding: false # primary chain: set X-Forwarded-For Headder
primaryIgnoreWorseDeadlines: false # primary chain: ignore a deadline if a better deadline has already been found.
primaryAccountKey: "" # primary chain: account key

#secondary chain
secondarySubmitURL: "wss://ecominer.hdpool.com" # secondary chain: url to forward nonces to (pool, wallet)
secondaryTargetDeadline: 1000000000 # secondary chain: target deadline
secondaryPassphrase: "" # secondary chain: passphrase overwrite (optional), empty -> passphrase from client will be forwarded if any
Expand Down
22 changes: 17 additions & 5 deletions wsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func newWebsocketAPI(server string, accountKey string, minerName string, capacit
}

func (c *websocketAPI) UpdateSize(totalSize int64){
c.sendMu.Lock()
c.ci.Capacity = totalSize
c.sendMu.Unlock()
}

func (c *websocketAPI) Close() {
Expand All @@ -100,7 +102,9 @@ func (c *websocketAPI) Connect() {
// message handler
go func() {
for {
c.receiveMu.Lock()
messageType, message, err := c.rc.ReadMessage()
c.receiveMu.Unlock()
if err != nil {
continue
}
Expand All @@ -110,7 +114,6 @@ func (c *websocketAPI) Connect() {
onTextMessage(string(message))

}

}
}()
}
Expand All @@ -120,19 +123,22 @@ func (c *websocketAPI) subscribe() error {
signal.Notify(interrupt, os.Interrupt)

// request initial mining info
c.sendMu.Lock()
if err := c.rc.WriteMessage(1, []byte("{\"cmd\":\"mining_info\",\"para\":{}}")); err != nil {
log.Printf("Error: WriteMessage %s", c.rc.GetURL())
return err
}
c.sendMu.Unlock()
// subscribe for future mining infos
channelName := "poolmgr.mining_info"
subscribeObject := getSubscribeEventObject(channelName, 0)
subscribeData := serializeDataIntoString(subscribeObject)

c.sendMu.Lock()
if err := c.rc.WriteMessage(1, []byte(subscribeData)); err != nil {
log.Printf("Error: WriteMessage %s", c.rc.GetURL())
return err
}
c.sendMu.Unlock()
// subscribe to heartbeat
// cancel existing
// create new
Expand All @@ -152,16 +158,19 @@ func (c *websocketAPI) subscribe() error {
log.Println("websocket api: heartbeat lost, trying to reconnect...")
ct := time.Now()
lastHeartBeat.Store(ct)
c.Close()
//c.Connect()
c.Close()
}
c.sendMu.Lock()
ci := clientInfo{c.accountKey,c.ci.MinerName,c.ci.MinerName+".hdproxy.exe."+hdproxyVersion, c.ci.Capacity}
hb := websocketMessage{"poolmgr.heartbeat",ci}
req, err := jsonx.MarshalToString(&hb);
if err != nil {
return
}
// debug
// log.Println(req)
c.rc.WriteMessage(1, []byte(req))
c.sendMu.Unlock()
case <- interrupt:
ticker.Stop()
os.Exit(0)
Expand Down Expand Up @@ -239,13 +248,16 @@ func serializeDataIntoString(data interface{}) string {
}

func (c *websocketAPI) submitNonce(accountID uint64, height uint64, nonce uint64, deadline uint64){
c.sendMu.Lock()
nd := nonceData{accountID, height, strconv.FormatUint(nonce,10), deadline, time.Now().Unix()}
ns := nonceSubmission{c.ci.AccountKey,c.ci.MinerName,"",c.ci.Capacity,[]nonceData{nd}}
hb := websocketMessage{"poolmgr.submit_nonce",ns}
req, err := jsonx.MarshalToString(&hb);
// debug log.Println(req)
// debug
// log.Println(req)
if err != nil {
return
}
c.rc.WriteMessage(1, []byte(req))
c.sendMu.Unlock()
}

0 comments on commit 2396457

Please sign in to comment.