public HashBlock Allocate(uint desired, Client c) { HashBlock block = null; HashBlock free = FindFreeBlock(desired); if (free != null) { if (free.Count > desired) { // Split this block block = new HashBlock(); block.Owner = c; block.Start = free.Start; block.Count = desired; mBusyBlocks.Add(block); free.Start += desired; free.Count -= desired; } else { // Remove the free block from the free list mFreeBlocks.Remove(free); // Assign the free block to the client free.Owner = c; // Add the block to the busy list block = free; mBusyBlocks.Add(block); } } return block; }
public void RecordClientWork(Client c) { ClientWork w = new ClientWork(); w.mTime = DateTime.UtcNow; w.mMemberName = c.mAgent; w.mProductName = c.mLocation; w.mHashes = c.mHashesDone; if (w.mMemberName == null || w.mMemberName.Length <= 0) w.mMemberName = "unknown"; if (w.mProductName == null || w.mProductName.Length <= 0) w.mProductName = "unknown"; mClientWorkQueueLock.WaitOne(); mClientWorkQueue.Add(w); mClientWorkQueueLock.ReleaseMutex(); }
public void WorkComplete(Client solver, bool solutionFound, uint solution) { mEventLog.RecordClientWork(solver); WorkBlock block = solver.mCurrentBlock; block.mHashMan.FinishBlock(solver.mHashBlock); solver.mHashBlock = null; if (solutionFound && mBlock == block) { mBlocksSubmitted++; bool success = mUpstream.SubmitWork(block, solution); //if (!success) // success = mUpstream.SubmitWork(block, (uint)IPAddress.HostToNetworkOrder((int)solution)); // Start a new block if (success) { // Send email notification about this found solution /* TimeSpan span = DateTime.Now - block.mHashMan.mStartTime; string hashrate = string.Format("{0:N}", block.mHashMan.mHashesDone / span.TotalSeconds); string body = "Found solution for " + block.mCurrency + " block: \n" + block.ToString() + "\n\n"; body += "Solution string: " + data + "\n"; body += "Block Accepted: " + success.ToString() + "\n"; body += "Hashes Done: " + block.mHashMan.mHashesDone + "\n"; body += "Time Spent: " + span.ToString() + "\n"; body += "Hashrate: " + hashrate + "\n"; body += "Clients: " + mClients.Count + "\n"; body += "\n\n"; //mMailer.SendEmail(body); */ //mMailer.SendEmail("Block Accepted"); string data = block.GetSolutionString(solution); mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Work accepted! solution: {0}, dataString: {1}", solution, data)); BeginBlock(); mBlocksAccepted++; } else { string data = block.GetSolutionString(solution); mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Work not accepted. solution: {0}, dataString: {1}", solution, data)); } } }
void AssignWork(Client c) { if (mBlock != null) { //mEventLog.RecordEvent(EventLog.EventType.HashWork, string.Format("Allocating {0} hashes for client: {1}", c.mDesiredHashes, c.ToLogString())); HashManager.HashBlock hashes = mBlock.mHashMan.Allocate(c.mDesiredHashes, c); if (hashes != null) { //mEventLog.RecordEvent(EventLog.EventType.HashWork, string.Format("Sending hash range ({0} - {1}) to client: {2}", hashes.Start, hashes.Start + hashes.Count, c.ToLogString())); c.SendWork(hashes, mBlock); } } }
public void AcceptClient(TcpClient client) { IPEndPoint ep = client.Client.RemoteEndPoint as IPEndPoint; byte[] bytes = ep.Address.GetAddressBytes(); uint addr = (uint)(bytes[0] << 24) | (uint)(bytes[1] << 16) | (uint)(bytes[2] << 8) | bytes[3]; if (!mBlacklist.ContainsKey(addr)) { Client c = new Client(client, this); mEventLog.RecordEvent(EventLog.EventType.Network, string.Format("New connection from: {0}", ep.Address.ToString())); mClientListMutex.WaitOne(); mClients.Add(c); mClientListMutex.ReleaseMutex(); } }