Struct stratum_server::MinerList
source · Fields§
§miners: Arc<RwLock<HashMap<u32, Miner>>>
Implementations§
source§impl MinerList
impl MinerList
sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
More examples
src/session.rs (line 185)
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
pub fn new(
id_manager: IDManager,
sender: UnboundedSender<SendInformation>,
config_manager: ConfigManager,
cancel_token: CancellationToken,
// #[cfg(feature = "upstream")] upstream_sender: UnboundedSender<String>,
// #[cfg(feature = "upstream")] upstream_receiver: UnboundedReceiver<
// serde_json::map::Map<String, serde_json::Value>,
// >,
state: State,
) -> Result<Self> {
let session_id = id_manager.allocate_session_id()?;
let id = Uuid::new_v4();
debug!("Accepting new miner. ID: {}", &id);
let config = config_manager.current_config();
let options = MinerOptions {
retarget_time: config.difficulty.retarget_time,
target_time: config.difficulty.target_time,
//@todo these values make no sense so let's trim them a bit.
min_diff: config.difficulty.minimum_difficulty,
max_diff: config.difficulty.maximum_difficulty,
max_delta: 1.0, //@todo make this adjustable, not sure if this is solid or not.
//@todo probably don't store, get from above and then calcualte the others.
variance_percent: config.difficulty.variance_percent,
// share_time_min: 4.2,
// share_time_max: 7.8,
};
Ok(Session {
id,
session_id,
id_manager,
user_info: Arc::new(Mutex::new(UserInfo {
account_id: 0,
mining_account: 0,
worker_name: None,
})),
info: Arc::new(RwLock::new(SessionInfo::new())),
sender: Arc::new(Mutex::new(sender)),
// #[cfg(feature = "upstream")]
// upstream_sender: Arc::new(Mutex::new(upstream_sender)),
// #[cfg(feature = "upstream")]
// upstream_receiver: Arc::new(Mutex::new(upstream_receiver)),
difficulty: Arc::new(Mutex::new(config.difficulty.initial_difficulty)),
previous_difficulty: Arc::new(Mutex::new(config.difficulty.initial_difficulty)),
next_difficulty: Arc::new(Mutex::new(None)),
options: Arc::new(options),
needs_ban: Arc::new(Mutex::new(false)),
state: Arc::new(Mutex::new(state)),
cancel_token,
miner_list: MinerList::new(),
connection_miner: Arc::new(Mutex::new(None)),
})
}
sourcepub async fn add_miner(&self, session_id: u32, miner: Miner)
pub async fn add_miner(&self, session_id: u32, miner: Miner)
Examples found in repository?
src/session.rs (line 348)
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
pub async fn register_worker(
&self,
session_id: u32,
client_agent: &str,
worker_name: &str,
worker_id: Uuid,
) {
let worker = Miner::new(
worker_id,
Some(client_agent.to_owned()),
Some(worker_name.to_owned()),
Buffer::from(session_id.to_le_bytes().to_vec()),
self.options.clone(),
format_difficulty(*self.difficulty.lock().await),
);
self.miner_list.add_miner(session_id, worker).await;
}