Skip to content

Commit c2ffde7

Browse files
committed
feat(onion_client): add function to remove a friend
1 parent fed4da5 commit c2ffde7

File tree

1 file changed

+14
-4
lines changed
  • src/toxcore/onion/client

1 file changed

+14
-4
lines changed

src/toxcore/onion/client/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,20 @@ impl OnionClient {
549549
state.paths_pool.path_nodes.put(node);
550550
}
551551

552-
/// Add new node to random nodes pool to use them to build random paths.
552+
/// Add a friend to start looking for its DHT `PublicKey`.
553553
pub fn add_friend(&self, real_pk: PublicKey) {
554554
let mut state = self.state.lock();
555555

556556
state.friends.insert(real_pk, OnionFriend::new(real_pk));
557557
}
558558

559+
/// Remove a friend and stop looking for him.
560+
pub fn remove_friend(&self, real_pk: PublicKey) {
561+
let mut state = self.state.lock();
562+
563+
state.friends.remove(&real_pk);
564+
}
565+
559566
/// Set friend's DHT `PublicKey` when it gets known somewhere else.
560567
pub fn set_friend_dht_pk(&self, real_pk: PublicKey, dht_pk: PublicKey) {
561568
let mut state = self.state.lock();
@@ -1080,7 +1087,7 @@ mod tests {
10801087
}
10811088

10821089
#[test]
1083-
fn add_friend() {
1090+
fn add_remove_friend() {
10841091
let (dht_pk, dht_sk) = gen_keypair();
10851092
let (real_pk, real_sk) = gen_keypair();
10861093
let (udp_tx, _udp_rx) = mpsc::channel(1);
@@ -1092,8 +1099,11 @@ mod tests {
10921099
let (friend_pk, _friend_sk) = gen_keypair();
10931100
onion_client.add_friend(friend_pk);
10941101

1095-
let state = onion_client.state.lock();
1096-
assert_eq!(state.friends[&friend_pk].real_pk, friend_pk);
1102+
assert_eq!(onion_client.state.lock().friends[&friend_pk].real_pk, friend_pk);
1103+
1104+
onion_client.remove_friend(friend_pk);
1105+
1106+
assert!(!onion_client.state.lock().friends.contains_key(&friend_pk));
10971107
}
10981108

10991109
#[test]

0 commit comments

Comments
 (0)