pub struct PackedNode {
pub saddr: SocketAddr,
pub pk: PublicKey,
}
Expand description
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§
Source§impl PackedNode
impl PackedNode
Sourcepub fn new(saddr: SocketAddr, pk: &PublicKey) -> Self
pub fn new(saddr: SocketAddr, pk: &PublicKey) -> Self
Create new PackedNode
. The IPv6 address will be converted to IPv4 if
it’s IPv4-compatible or IPv4-mapped.
Sourcepub fn to_tcp_bytes<'a>(
&self,
buf: (&'a mut [u8], usize),
) -> Result<(&'a mut [u8], usize), GenError>
pub fn to_tcp_bytes<'a>( &self, buf: (&'a mut [u8], usize), ) -> Result<(&'a mut [u8], usize), GenError>
to_bytes for TCP
Sourcepub fn from_tcp_bytes(
i: &[u8],
) -> IResult<&[u8], PackedNode, (&[u8], ErrorKind)>
pub fn from_tcp_bytes( i: &[u8], ) -> IResult<&[u8], PackedNode, (&[u8], ErrorKind)>
from_bytes for TCP.
Sourcepub fn socket_addr(&self) -> SocketAddr
pub fn socket_addr(&self) -> SocketAddr
Get a Socket address from the PackedNode
.
Trait Implementations§
Source§impl Clone for PackedNode
impl Clone for PackedNode
Source§fn clone(&self) -> PackedNode
fn clone(&self) -> PackedNode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PackedNode
impl Debug for PackedNode
Source§impl FromBytes for PackedNode
Deserialize bytes into PackedNode
. Returns Error
if deseralizing
failed.
impl FromBytes for PackedNode
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.
Source§fn from_bytes(i: &[u8]) -> IResult<&[u8], PackedNode, (&[u8], ErrorKind)>
fn from_bytes(i: &[u8]) -> IResult<&[u8], PackedNode, (&[u8], ErrorKind)>
nom
from raw bytes