Skip to content

Commit 38d1075

Browse files
committed
feat(friends): add friends module
1 parent c2ffde7 commit 38d1075

File tree

8 files changed

+1218
-22
lines changed

8 files changed

+1218
-22
lines changed

src/toxcore/dht/server/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,12 @@ mod tests {
14921492
const ONION_RETURN_2_PAYLOAD_SIZE: usize = ONION_RETURN_2_SIZE - secretbox::NONCEBYTES;
14931493
const ONION_RETURN_3_PAYLOAD_SIZE: usize = ONION_RETURN_3_SIZE - secretbox::NONCEBYTES;
14941494

1495+
impl Server {
1496+
pub fn has_friend(&self, pk: &PublicKey) -> bool {
1497+
self.friends.read().contains_key(pk)
1498+
}
1499+
}
1500+
14951501
fn create_node() -> (Server, PrecomputedKey, PublicKey, SecretKey,
14961502
mpsc::Receiver<(Packet, SocketAddr)>, SocketAddr) {
14971503
crypto_init().unwrap();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//! Errors for friend connections module.
2+
3+
use failure::Fail;
4+
5+
error_kind! {
6+
#[doc = "Error that can happen while removing a friend"]
7+
#[derive(Debug)]
8+
RemoveFriendError,
9+
#[doc = "The specific kind of error that can occur."]
10+
#[derive(Debug, Eq, PartialEq, Fail)]
11+
RemoveFriendErrorKind {
12+
#[doc = "Failed to kill net_crypto connection."]
13+
#[fail(display = "Failed to kill net_crypto connection")]
14+
KillConnection,
15+
#[doc = "There is no such friend."]
16+
#[fail(display = "There is no such friend")]
17+
NoFriend,
18+
}
19+
}
20+
21+
error_kind! {
22+
#[doc = "Error that can happen while removing a frind"]
23+
#[derive(Debug)]
24+
RunError,
25+
#[doc = "The specific kind of error that can occur."]
26+
#[derive(Debug, Eq, PartialEq, Fail)]
27+
RunErrorKind {
28+
#[doc = "Wakeup timer error."]
29+
#[fail(display = "Wakeup timer error")]
30+
Wakeup,
31+
#[doc = "Failed to kill net_crypto connection."]
32+
#[fail(display = "Failed to kill net_crypto connection")]
33+
KillConnection,
34+
#[doc = "Failed to send packet."]
35+
#[fail(display = "Failed to send packet")]
36+
SendTo,
37+
#[doc = "Failed to add TCP connection."]
38+
#[fail(display = "Failed to TCP connection")]
39+
AddTcpConnection,
40+
#[doc = "Failed to send connection status."]
41+
#[fail(display = "Failed to send connection status")]
42+
SendToConnectionStatus
43+
}
44+
}
45+
46+
error_kind! {
47+
#[doc = "Error that can happen while handling `ShareRelays` packet."]
48+
#[derive(Debug)]
49+
HandleShareRelaysError,
50+
#[doc = "The specific kind of error that can occur."]
51+
#[derive(Debug, Eq, PartialEq, Fail)]
52+
HandleShareRelaysErrorKind {
53+
#[doc = "Failed to add TCP connection."]
54+
#[fail(display = "Failed to TCP connection")]
55+
AddTcpConnection
56+
}
57+
}

0 commit comments

Comments
 (0)