[−][src]Struct tox_packet::dht::packed_node::PackedNode
PackedNode
format is a way to store the node info in a small yet easy to
parse format.
It is used in many places in Tox, e.g. in DHT Send nodes
.
To store more than one node, simply append another on to the previous one:
[packed node 1][packed node 2][...]
Serialized Packed node:
Length | Content |
---|---|
1 | Ip type (v4 or v6) |
4 or 16 | IPv4 or IPv6 address |
2 | port |
32 | node ID |
Size of serialized PackedNode
is 39 bytes with IPv4 node info, or 51 with
IPv6 node info.
DHT module should use only UDP variants of Ip type, given that DHT runs solely on the UDP.
Fields
saddr: SocketAddr
Socket addr of node.
pk: PublicKey
Public Key of the node.
Implementations
impl PackedNode
[src]
pub fn new(saddr: SocketAddr, pk: &PublicKey) -> Self
[src]
Create new PackedNode
. The IPv6 address will be converted to IPv4 if
it's IPv4-compatible or IPv4-mapped.
pub fn to_tcp_bytes<'a>(
&self,
buf: (&'a mut [u8], usize)
) -> Result<(&'a mut [u8], usize), GenError>
[src]
&self,
buf: (&'a mut [u8], usize)
) -> Result<(&'a mut [u8], usize), GenError>
to_bytes for TCP
pub fn from_tcp_bytes(
i: &[u8]
) -> IResult<&[u8], PackedNode, (&[u8], ErrorKind)>
[src]
i: &[u8]
) -> IResult<&[u8], PackedNode, (&[u8], ErrorKind)>
from_bytes for TCP.
pub fn ip_type(&self) -> u8
[src]
Get an IP type from the PackedNode
.
pub fn ip(&self) -> IpAddr
[src]
Get an IP address from the PackedNode
.
pub fn socket_addr(&self) -> SocketAddr
[src]
Get a Socket address from the PackedNode
.
Trait Implementations
impl Clone for PackedNode
[src]
pub fn clone(&self) -> PackedNode
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for PackedNode
[src]
impl Debug for PackedNode
[src]
impl Eq for PackedNode
[src]
impl FromBytes for PackedNode
[src]
Deserialize bytes into PackedNode
. Returns Error
if deseralizing
failed.
Can fail if:
- length is too short for given Ip Type
- PK can't be parsed
Blindly trusts that provided Ip Type
matches - i.e. if there are provided
51 bytes (which is length of PackedNode
that contains IPv6), and Ip Type
says that it's actually IPv4, bytes will be parsed as if that was an IPv4
address.
impl PartialEq<PackedNode> for PackedNode
[src]
pub fn eq(&self, other: &PackedNode) -> bool
[src]
pub fn ne(&self, other: &PackedNode) -> bool
[src]
impl StructuralEq for PackedNode
[src]
impl StructuralPartialEq for PackedNode
[src]
impl ToBytes for PackedNode
[src]
Auto Trait Implementations
impl RefUnwindSafe for PackedNode
[src]
impl Send for PackedNode
[src]
impl Sync for PackedNode
[src]
impl Unpin for PackedNode
[src]
impl UnwindSafe for PackedNode
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,