[][src]Struct tox_packet::dht::packed_node::PackedNode

pub struct PackedNode {
    pub saddr: SocketAddr,
    pub pk: PublicKey,
}

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:

LengthContent
1Ip type (v4 or v6)
4 or 16IPv4 or IPv6 address
2port
32node 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]

to_bytes for TCP

pub fn from_tcp_bytes(
    i: &[u8]
) -> IResult<&[u8], PackedNode, (&[u8], ErrorKind)>
[src]

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]

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]

impl StructuralEq for PackedNode[src]

impl StructuralPartialEq for PackedNode[src]

impl ToBytes for PackedNode[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.