Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Event.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ type EventUpSessionBroken struct {
Slot int
}

type EventUpSessionFull struct {
Slot int
}

type EventSubmitShareBTC struct {
ID interface{}
Message *ExMessageSubmitShareBTC
Expand Down
2 changes: 1 addition & 1 deletion UpSessionBTC.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (up *UpSessionBTC) close() {
up.manager.SendEvent(EventUpSessionBroken{up.slot})
}

if up.config.AlwaysKeepDownconn {
if up.stat != StatExit && up.config.AlwaysKeepDownconn {
if up.lastJob != nil {
up.manager.SendEvent(EventUpdateFakeJobBTC{up.lastJob})
}
Expand Down
7 changes: 6 additions & 1 deletion UpSessionETH.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (up *UpSessionETH) close() {
up.manager.SendEvent(EventUpSessionBroken{up.slot})
}

if up.config.AlwaysKeepDownconn {
if up.stat != StatExit && up.config.AlwaysKeepDownconn {
if up.lastJob != nil {
up.manager.SendEvent(EventUpdateFakeJobETH{up.lastJob})
}
Expand Down Expand Up @@ -702,6 +702,11 @@ func (up *UpSessionETH) handleExMessageSetExtraNonce(ex *ExMessage) {
return
}

// 矿池服务器满了,无法连接新矿机
if msg.ExtraNonce == EthereumInvalidExtraNonce {
up.manager.SendEvent(EventUpSessionFull{up.slot})
}

down := up.downSessions[msg.SessionID]
if down != nil {
down.SendEvent(EventSetExtraNonce{msg.ExtraNonce})
Expand Down
24 changes: 21 additions & 3 deletions UpSessionManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type UpSessionInfo struct {
minerNum int
ready bool
full bool
upSession UpSession
}

Expand Down Expand Up @@ -90,7 +91,7 @@ func (manager *UpSessionManager) addDownSession(e EventAddDownSession) {
// 寻找连接数最少的服务器
for i := range manager.upSessions {
info := &manager.upSessions[i]
if info.ready && (selected == nil || info.minerNum < selected.minerNum) {
if info.ready && !info.full && (selected == nil || info.minerNum < selected.minerNum) {
selected = info
}
}
Expand Down Expand Up @@ -155,13 +156,19 @@ func (manager *UpSessionManager) upSessionBroken(e EventUpSessionBroken) {
go manager.connect(e.Slot)
}

func (manager *UpSessionManager) upSessionFull(e EventUpSessionFull) {
info := &manager.upSessions[e.Slot]
info.full = true
}

func (manager *UpSessionManager) updateMinerNum(e EventUpdateMinerNum) {
defer manager.tryPrintMinerNum()

manager.upSessions[e.Slot].minerNum -= e.DisconnectedMinerCounter
up := &manager.upSessions[e.Slot]
up.minerNum -= e.DisconnectedMinerCounter

if glog.V(3) {
glog.Info(manager.id, "miner num update, slot: ", e.Slot, ", miners: ", manager.upSessions[e.Slot].minerNum)
glog.Info(manager.id, "miner num update, slot: ", e.Slot, ", miners: ", up.minerNum)
}

if manager.config.MultiUserMode {
Expand All @@ -174,6 +181,15 @@ func (manager *UpSessionManager) updateMinerNum(e EventUpdateMinerNum) {
manager.parent.SendEvent(EventStopUpSessionManager{manager.subAccount})
}
}

if up.full && up.minerNum == 0 {
// 重连矿池服务器已满的空闲连接
go func() {
glog.Info(manager.id, "reconnect full pool session #", e.Slot)
up.upSession.SendEvent(EventExit{})
manager.SendEvent(EventUpSessionBroken{e.Slot})
}()
}
}

func (manager *UpSessionManager) updateFakeMinerNum(e EventUpdateFakeMinerNum) {
Expand Down Expand Up @@ -233,6 +249,8 @@ func (manager *UpSessionManager) handleEvent() {
manager.addDownSession(e)
case EventUpSessionBroken:
manager.upSessionBroken(e)
case EventUpSessionFull:
manager.upSessionFull(e)
case EventUpdateMinerNum:
manager.updateMinerNum(e)
case EventUpdateFakeMinerNum:
Expand Down