aboutsummaryrefslogtreecommitdiffstats
path: root/src/wireguard/endpoint.rs
blob: f6a560b5b936bae8d2633e588f09f488cfc6dcbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use spin::{Mutex, MutexGuard};
use std::sync::Arc;

use super::super::platform::Endpoint;

#[derive(Clone)]
struct EndpointStore<E: Endpoint> {
    endpoint: Arc<Mutex<Option<E>>>,
}

impl<E: Endpoint> EndpointStore<E> {
    pub fn new() -> EndpointStore<E> {
        EndpointStore {
            endpoint: Arc::new(Mutex::new(None)),
        }
    }

    pub fn set(&self, endpoint: E) {
        *self.endpoint.lock() = Some(endpoint);
    }

    pub fn get(&self) -> MutexGuard<Option<E>> {
        self.endpoint.lock()
    }

    pub fn clear_src(&self) {
        (*self.endpoint.lock()).as_mut().map(|e| e.clear_src());
    }
}