pub struct MinerList {
    pub miners: Arc<RwLock<HashMap<u32, Miner>>>,
}

Fields§

§miners: Arc<RwLock<HashMap<u32, Miner>>>

Implementations§

Examples found in repository?
src/miner_list.rs (line 42)
41
42
43
    fn default() -> Self {
        Self::new()
    }
More examples
Hide additional 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)),
        })
    }
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;
    }
Examples found in repository?
src/session.rs (line 352)
351
352
353
    pub async fn unregister_worker(&self, session_id: u32) -> Option<Miner> {
        self.miner_list.remove_miner(session_id).await
    }
Examples found in repository?
src/session.rs (line 361)
360
361
362
    pub async fn get_worker_by_session_id(&self, session_id: u32) -> Option<Miner> {
        self.miner_list.get_miner_by_id(session_id).await
    }
Examples found in repository?
src/session.rs (line 366)
364
365
366
367
368
    pub async fn update_worker_by_session_id(&self, session_id: u32, miner: Miner) {
        self.miner_list
            .update_miner_by_session_id(session_id, miner)
            .await;
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Converts to this type from a reference to the input type.
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more