mirror of
https://github.com/cryptonote-social/csminer.git
synced 2024-08-15 16:30:37 +03:00
ability to batch & send multiple chats per share
This commit is contained in:
parent
153dcc1d7e
commit
d5e4d7aecf
@ -24,6 +24,11 @@ var (
|
||||
randID int64
|
||||
)
|
||||
|
||||
const (
|
||||
HASHES_PER_CHAT = 5000
|
||||
MAX_CHATS_PER_SHARE = 5
|
||||
)
|
||||
|
||||
func init() {
|
||||
err := binary.Read(rand.Reader, binary.LittleEndian, &randID)
|
||||
if err != nil {
|
||||
@ -41,16 +46,26 @@ func SendChat(chat string) int64 {
|
||||
return int64(len(chatQueue)-1) ^ randID
|
||||
}
|
||||
|
||||
// GetChatToSend returns the next queued chat message that needs to be delivered. The function
|
||||
// will return the same result until ChatSent is called. It will return ("", -1) if there are no
|
||||
// chats to send at this time.
|
||||
func GetChatToSend() (chat string, id int64) {
|
||||
// GetChatsToSend returns the next queud chat messages to deliver with a valid mining share. It
|
||||
// requires at least HASHES_PER_CHAT hashes to be computed per chat returned, and returns up to
|
||||
// MAX_CHATS_PER_SHARE. Returns nil if there are no chats queued to send.
|
||||
func GetChatsToSend(diff int64) []client.ChatToSend {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
if chatToSendIndex >= len(chatQueue) {
|
||||
return "", -1
|
||||
if chatToSendIndex == len(chatQueue) {
|
||||
return nil
|
||||
}
|
||||
return chatQueue[chatToSendIndex], int64(chatToSendIndex) ^ randID
|
||||
r := []client.ChatToSend{}
|
||||
for diff > HASHES_PER_CHAT && chatToSendIndex < len(chatQueue) && len(r) < MAX_CHATS_PER_SHARE {
|
||||
r = append(r, client.ChatToSend{
|
||||
ID: int64(chatToSendIndex) ^ randID,
|
||||
Message: chatQueue[chatToSendIndex],
|
||||
})
|
||||
chatToSendIndex++
|
||||
diff -= HASHES_PER_CHAT
|
||||
}
|
||||
// TODO: verify the total bytes we will be sending is within the server's request size limit
|
||||
return r
|
||||
}
|
||||
|
||||
func HasChatsToSend() bool {
|
||||
|
@ -666,9 +666,9 @@ func goMine(job client.MultiClientJob, thread int) {
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
chatMsg, chatID := chat.GetChatToSend()
|
||||
chats := chat.GetChatsToSend(int64(diffTarget))
|
||||
//crylog.Info("sending chatmsg:", chatMsg)
|
||||
resp, err := cl.SubmitWork(fnonce, jobid, chatMsg, chatID)
|
||||
resp, err := cl.SubmitWork(fnonce, jobid, chats)
|
||||
if err != nil {
|
||||
crylog.Warn("Submit work client failure:", jobid, err)
|
||||
cl.Close()
|
||||
@ -679,7 +679,9 @@ func goMine(job client.MultiClientJob, thread int) {
|
||||
crylog.Warn("Submit work server error:", jobid, resp.Error)
|
||||
return
|
||||
}
|
||||
chat.ChatSent(chatID)
|
||||
for i := range chats {
|
||||
chat.ChatSent(chats[i].ID)
|
||||
}
|
||||
stats.ShareAccepted(diffTarget)
|
||||
if resp.Result == nil {
|
||||
crylog.Warn("nil result")
|
||||
|
@ -308,8 +308,13 @@ func (cl *Client) GetChats(chatToken int64) (*Response, error) {
|
||||
return cl.submitRequest(chatRequest, GET_CHATS_JSON_ID)
|
||||
}
|
||||
|
||||
type ChatToSend struct {
|
||||
ID int64
|
||||
Message string
|
||||
}
|
||||
|
||||
// if error is returned then client will be closed and put in not-alive state
|
||||
func (cl *Client) SubmitWork(nonce string, jobid string, chat string, chatID int64) (*Response, error) {
|
||||
func (cl *Client) SubmitWork(nonce string, jobid string, chats []ChatToSend) (*Response, error) {
|
||||
submitRequest := &struct {
|
||||
ID uint64 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
@ -323,9 +328,8 @@ func (cl *Client) SubmitWork(nonce string, jobid string, chat string, chatID int
|
||||
Nonce string `json:"nonce"`
|
||||
Result string `json:"result"`
|
||||
|
||||
Chat string `json:"chat"`
|
||||
ChatID int64 `json:"chat_id"`
|
||||
}{"696969", jobid, nonce, "", chat, chatID},
|
||||
Chats []ChatToSend `json:"chats"`
|
||||
}{"696969", jobid, nonce, "", chats},
|
||||
}
|
||||
return cl.submitRequest(submitRequest, SUBMIT_WORK_JSON_ID)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user