Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub mod toxcore {
pub mod toxid;
pub mod tcp;
pub mod dht_new;
pub mod onion;
}

/// Tox Encrypt Save (a.k.a. **TES**) module. Can be used to ecrypt / decrypt
Expand Down
53 changes: 45 additions & 8 deletions src/toxcore/dht_new/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,40 @@ use toxcore::binary_io_new::*;
use toxcore::crypto_core::*;
use toxcore::dht_new::packet_kind::*;
use toxcore::dht_new::packed_node::PackedNode;
use toxcore::onion::packet::*;

/// Length in bytes of [`PingRequest`](./struct.PingRequest.html) and
/// [`PingResponse`](./struct.PingResponse.html) when serialized into bytes.
pub const PING_SIZE: usize = 9;

/** DHT packet base enum that encapsulates
[`DhtPacket`](./struct.DhtPacket.html) or [`DhtRequest`](./struct.DhtRequest.html).

https://zetok.github.io/tox-spec/#dht-packet
https://zetok.github.io/tox-spec/#dht-request-packets
/** DHT packet base enum that encapsulates all types of DHT packets.
*/
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum DhtBase {
/// DhtBase are wrapper for DhtPacket and DhtRequest
/// [`DhtPacket`](./struct.DhtPacket.html) structure.
DhtPacket(DhtPacket),
/// DhtBase are wrapper for DhtPacket and DhtRequest
/// [`DhtRequest`](./struct.DhtRequest.html) structure.
DhtRequest(DhtRequest),
/// [`OnionRequest0`](../onion/struct.OnionRequest0.html) structure.
OnionRequest0(OnionRequest0),
/// [`OnionRequest1`](../onion/struct.OnionRequest1.html) structure.
OnionRequest1(OnionRequest1),
/// [`OnionRequest2`](../onion/struct.OnionRequest2.html) structure.
OnionRequest2(OnionRequest2),
/// [`AnnounceRequest`](../onion/struct.AnnounceRequest.html) structure.
AnnounceRequest(AnnounceRequest),
/// [`AnnounceResponse`](../onion/struct.AnnounceResponse.html) structure.
AnnounceResponse(AnnounceResponse),
/// [`OnionDataRequest`](../onion/struct.OnionDataRequest.html) structure.
OnionDataRequest(OnionDataRequest),
/// [`OnionDataResponse`](../onion/struct.OnionDataResponse.html) structure.
OnionDataResponse(OnionDataResponse),
/// [`OnionResponse3`](../onion/struct.OnionResponse3.html) structure.
OnionResponse3(OnionResponse3),
/// [`OnionResponse2`](../onion/struct.OnionResponse2.html) structure.
OnionResponse2(OnionResponse2),
/// [`OnionResponse1`](../onion/struct.OnionResponse1.html) structure.
OnionResponse1(OnionResponse1),
}

/** DHT packet struct that encapsulates in the payload
Expand Down Expand Up @@ -133,14 +150,34 @@ impl ToBytes for DhtBase {
match *self {
DhtBase::DhtPacket(ref p) => p.to_bytes(buf),
DhtBase::DhtRequest(ref p) => p.to_bytes(buf),
DhtBase::OnionRequest0(ref p) => p.to_bytes(buf),
DhtBase::OnionRequest1(ref p) => p.to_bytes(buf),
DhtBase::OnionRequest2(ref p) => p.to_bytes(buf),
DhtBase::AnnounceRequest(ref p) => p.to_bytes(buf),
DhtBase::AnnounceResponse(ref p) => p.to_bytes(buf),
DhtBase::OnionDataRequest(ref p) => p.to_bytes(buf),
DhtBase::OnionDataResponse(ref p) => p.to_bytes(buf),
DhtBase::OnionResponse3(ref p) => p.to_bytes(buf),
DhtBase::OnionResponse2(ref p) => p.to_bytes(buf),
DhtBase::OnionResponse1(ref p) => p.to_bytes(buf),
}
}
}

impl FromBytes for DhtBase {
named!(from_bytes<DhtBase>, alt!(
map!(DhtPacket::from_bytes, DhtBase::DhtPacket) |
map!(DhtRequest::from_bytes, DhtBase::DhtRequest)
map!(DhtRequest::from_bytes, DhtBase::DhtRequest) |
map!(OnionRequest0::from_bytes, DhtBase::OnionRequest0) |
map!(OnionRequest1::from_bytes, DhtBase::OnionRequest1) |
map!(OnionRequest2::from_bytes, DhtBase::OnionRequest2) |
map!(AnnounceRequest::from_bytes, DhtBase::AnnounceRequest) |
map!(AnnounceResponse::from_bytes, DhtBase::AnnounceResponse) |
map!(OnionDataRequest::from_bytes, DhtBase::OnionDataRequest) |
map!(OnionDataResponse::from_bytes, DhtBase::OnionDataResponse) |
map!(OnionResponse3::from_bytes, DhtBase::OnionResponse3) |
map!(OnionResponse2::from_bytes, DhtBase::OnionResponse2) |
map!(OnionResponse1::from_bytes, DhtBase::OnionResponse1)
));
}

Expand Down
25 changes: 25 additions & 0 deletions src/toxcore/onion/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (C) 2013 Tox project All Rights Reserved.
Copyright © 2018 Evgeny Kurnevsky <kurnevsky@gmail.com>

This file is part of Tox.

Tox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Tox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/

/*! Onion packets handling

*/

pub mod packet;
Loading