Skip to content

Commit

Permalink
chore: adjust access client api
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Aug 20, 2024
1 parent fb00e87 commit 8902996
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
9 changes: 2 additions & 7 deletions src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use serde::Deserialize;
const ACCESS_TTL: Duration = Duration::from_secs(10 * 60);

pub struct AccessClient {
local_id: libp2p::PeerId,
endpoint: reqwest::Url,
client: reqwest::Client,
cache: HashMap<PeerId, (bool, Instant)>,
Expand All @@ -20,9 +19,8 @@ struct AccessClientResponse {
}

impl AccessClient {
pub fn new(local_id: libp2p::PeerId, endpoint: reqwest::Url) -> AccessClient {
pub fn new(endpoint: reqwest::Url) -> AccessClient {
AccessClient {
local_id,
endpoint,
client: reqwest::Client::new(),
cache: HashMap::default(),
Expand All @@ -31,10 +29,7 @@ impl AccessClient {

async fn request_endpoint(&mut self, peer: &PeerId) -> Result<bool, reqwest::Error> {
let url = self.endpoint.join("access-control").unwrap();
let params = [
("device", self.local_id.to_string()),
("user", peer.to_string()),
];
let params = [("peer_id", peer.to_string())];

let response = self
.client
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ impl PProxy {
let (command_tx, command_rx) = mpsc::channel(DEFAULT_CHANNEL_SIZE);
let swarm = crate::p2p::new_swarm(keypair, listen_addr)
.map_err(|e| Error::Libp2pSwarmCreateError(e.to_string()))?;
let access_client = access_server_endpoint
.map(|endpoint| AccessClient::new(*swarm.local_peer_id(), endpoint));
let access_client = access_server_endpoint.map(AccessClient::new);

Ok((
Self {
Expand Down

0 comments on commit 8902996

Please sign in to comment.